/** * Adds a new pair to this list with the given key and value * * @param key the key to add; can be <code>null</code> * @param value the value to add; can be <code>null</code> * @return true (as specified by Collection.add(E)) */ public boolean add(final K key, final V value) { return add(new MutablePair<K, V>(key, value)); }
/** * Constructor for building a list of the given key-value pairs * * @param keys the keys (can be null) * @param values the values (must be null if the keys are null, otherwise * must be non-null and of the same size as the keys) */ public PairList(final List<? extends K> keys, final List<? extends V> values) { Validate.isTrue(!(keys == null ^ values == null), "Parameter types and names must either both be null or both be not null"); if (keys == null) { Validate.isTrue(values == null, "Parameter names must be null if types are null"); } else { Validate.isTrue(values != null, "Parameter names are required if types are provided"); Validate.isTrue(keys.size() == values.size(), "Expected %d values but found %d", keys.size(), values.size()); for (int i = 0; i < keys.size(); i++) { add(keys.get(i), values.get(i)); } } }