/** * Obtains an instance from an {@code int} and a {@code double}. * * @param first the first element * @param second the second element * @return a pair formed from the two parameters */ public static IntDoublePair of(int first, double second) { return new IntDoublePair(first, second); }
@Override public IntDoublePair build() { return new IntDoublePair( first, second); }
/** * Parses an {@code IntDoublePair} from the standard string format. * <p> * The standard format is '[$first, $second]'. Spaces around the values are trimmed. * * @param pairStr the text to parse * @return the parsed pair * @throws IllegalArgumentException if the pair cannot be parsed */ @FromString public static IntDoublePair parse(String pairStr) { ArgChecker.notNull(pairStr, "pairStr"); if (pairStr.length() < 5) { throw new IllegalArgumentException("Invalid pair format, too short: " + pairStr); } if (pairStr.charAt(0) != '[') { throw new IllegalArgumentException("Invalid pair format, must start with [: " + pairStr); } if (pairStr.charAt(pairStr.length() - 1) != ']') { throw new IllegalArgumentException("Invalid pair format, must end with ]: " + pairStr); } String content = pairStr.substring(1, pairStr.length() - 1); List<String> split = Splitter.on(',').trimResults().splitToList(content); if (split.size() != 2) { throw new IllegalArgumentException("Invalid pair format, must have two values: " + pairStr); } int first = Integer.parseInt(split.get(0)); double second = Double.parseDouble(split.get(1)); return new IntDoublePair(first, second); }
/** * Obtains an instance from a {@code Pair}. * * @param pair the pair to convert * @return a pair formed by extracting values from the pair */ public static IntDoublePair ofPair(Pair<Integer, Double> pair) { ArgChecker.notNull(pair, "pair"); return new IntDoublePair(pair.getFirst(), pair.getSecond()); }