/** * 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); }
/** * Creates a pair of {@code Integer} 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<Integer, Double> of(int first, Double second) { if (second != null) { return IntDoublePair.of(first, second.doubleValue()); } return ObjectsPair.of((Integer) first, second); }
/** * Creates a pair of {@code Integer} 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<Integer, Double> of(int first, double second) { return IntDoublePair.of(first, second); }
/** * Creates a pair of {@code Integer} 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<Integer, Double> of(Integer first, double second) { if (first != null) { return IntDoublePair.of(first.intValue(), second); } return ObjectsPair.of(first, (Double) second); }