Example #1
0
 /**
  * Creates a pair of {@code Object}s optimizing the storage type.
  *
  * @param <A> the first element type
  * @param <B> the second element type
  * @param first the first element, may be null
  * @param second the second element, may be null
  * @return a pair formed from the two parameters, not null
  */
 @SuppressWarnings("unchecked")
 public static <A, B> Pair<A, B> ofOptimized(A first, B second) {
   if (second instanceof Double) {
     if (first instanceof Double) {
       return (Pair<A, B>)
           DoublesPair.of(((Double) first).doubleValue(), ((Double) second).doubleValue());
     } else if (first instanceof Integer) {
       return (Pair<A, B>)
           IntDoublePair.of(((Integer) first).intValue(), ((Double) second).doubleValue());
     } else if (first instanceof Long) {
       return (Pair<A, B>)
           LongDoublePair.of(((Long) first).longValue(), ((Double) second).doubleValue());
     }
   } else if (first instanceof Integer) {
     return (Pair<A, B>) IntObjectPair.<B>of(((Integer) first).intValue(), second);
   } else if (first instanceof Long) {
     return (Pair<A, B>) LongObjectPair.<B>of(((Long) first).longValue(), second);
   }
   return ObjectsPair.of(first, second);
 }
Example #2
0
 /**
  * Creates a pair of {@code Long} to {@code Double}.
  *
  * @param first the first element, may be null
  * @param second the second element, may be null
  * @return a pair formed from the two parameters, not null
  */
 public static Pair<Long, Double> of(long first, Double second) {
   if (second != null) {
     return LongDoublePair.of(first, second.doubleValue());
   }
   return ObjectsPair.of((Long) first, second);
 }
Example #3
0
 /**
  * Creates a pair of {@code Long} to {@code Double}.
  *
  * @param first the first element, may be null
  * @param second the second element, may be null
  * @return a pair formed from the two parameters, not null
  */
 public static Pair<Long, Double> of(long first, double second) {
   return LongDoublePair.of(first, second);
 }
Example #4
0
 /**
  * Creates a pair of {@code Long} to {@code Double}.
  *
  * @param first the first element, may be null
  * @param second the second element, may be null
  * @return a pair formed from the two parameters, not null
  */
 public static Pair<Long, Double> of(Long first, double second) {
   if (first != null) {
     return LongDoublePair.of(first.longValue(), second);
   }
   return ObjectsPair.of(first, (Double) second);
 }