/** * Creates a map which wraps the given map and * maps keys to ArrayLists. * * @param <K> the key type * @param <V> the value type * @param map the map to wrap * @return a new multi-value map * @since 4.0 */ @SuppressWarnings({ "unchecked", "rawtypes" }) public static <K, V> MultiValueMap<K, V> multiValueMap(final Map<K, ? super Collection<V>> map) { return MultiValueMap.<K, V, ArrayList> multiValueMap((Map<K, ? super Collection>) map, ArrayList.class); }
/** * Creates a mult-value map backed by the given map which returns * collections of type ArrayList. * * @param <K> the key type * @param <V> the value type * @param map the map to decorate * @return a multi-value map backed by the given map which returns ArrayLists of values. * @see MultiValueMap * @since 3.2 * @deprecated since 4.1, use {@link MultiValuedMap} instead */ @Deprecated public static <K, V> MultiValueMap<K, V> multiValueMap(final Map<K, ? super Collection<V>> map) { return MultiValueMap.<K, V>multiValueMap(map); }
/** * Creates a multi-value map backed by the given map which returns * collections of the specified type. * * @param <K> the key type * @param <V> the value type * @param <C> the collection class type * @param map the map to decorate * @param collectionClass the type of collections to return from the map * (must contain public no-arg constructor and extend Collection) * @return a multi-value map backed by the given map which returns collections of the specified type * @see MultiValueMap * @since 3.2 * @deprecated since 4.1, use {@link MultiValuedMap} instead */ @Deprecated public static <K, V, C extends Collection<V>> MultiValueMap<K, V> multiValueMap(final Map<K, C> map, final Class<C> collectionClass) { return MultiValueMap.multiValueMap(map, collectionClass); }
/** * Creates a multi-value map backed by the given map which returns * collections created by the specified collection factory. * * @param <K> the key type * @param <V> the value type * @param <C> the collection class type * @param map the map to decorate * @param collectionFactory a factor which creates collection objects * @return a multi-value map backed by the given map which returns collections * created by the specified collection factory * @see MultiValueMap * @since 3.2 * @deprecated since 4.1, use {@link MultiValuedMap} instead */ @Deprecated public static <K, V, C extends Collection<V>> MultiValueMap<K, V> multiValueMap(final Map<K, C> map, final Factory<C> collectionFactory) { return MultiValueMap.multiValueMap(map, collectionFactory); }
/** * Create an {@link IndexedCollection} for a non-unique index. * * @param <K> the index object type. * @param <C> the collection type. * @param coll the decorated {@link Collection}. * @param keyTransformer the {@link Transformer} for generating index keys. * @return the created {@link IndexedCollection}. */ public static <K, C> IndexedCollection<K, C> nonUniqueIndexedCollection(final Collection<C> coll, final Transformer<C, K> keyTransformer) { return new IndexedCollection<>(coll, keyTransformer, MultiValueMap.<K, C>multiValueMap(new HashMap<K, Collection<C>>()), false); }
/** * Create an {@link IndexedCollection} for a unique index. * <p> * If an element is added, which maps to an existing key, an {@link IllegalArgumentException} * will be thrown. * * @param <K> the index object type. * @param <C> the collection type. * @param coll the decorated {@link Collection}. * @param keyTransformer the {@link Transformer} for generating index keys. * @return the created {@link IndexedCollection}. */ public static <K, C> IndexedCollection<K, C> uniqueIndexedCollection(final Collection<C> coll, final Transformer<C, K> keyTransformer) { return new IndexedCollection<>(coll, keyTransformer, MultiValueMap.<K, C>multiValueMap(new HashMap<K, Collection<C>>()), true); }