Exemplo n.º 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);
 }
Exemplo n.º 2
0
 /**
  * Creates a pair of {@code Integer} to {@code Object}.
  *
  * @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
  */
 public static <B> Pair<Integer, B> of(int first, B second) {
   return IntObjectPair.of(first, second);
 }
Exemplo n.º 3
0
 /**
  * Creates a pair of {@code Integer} to {@code Object}.
  *
  * @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
  */
 public static <B> Pair<Integer, B> of(Integer first, B second) {
   if (first != null) {
     return IntObjectPair.of(first.intValue(), second);
   }
   return ObjectsPair.of(first, second);
 }