@Override @SuppressWarnings("squid:S1185") @Explain("We need to overwrite this to make it synchronized.") public synchronized void put(K key, V value) { super.put(key, value); }
/** * Creates a {@link Collector} which can be used to group a stream into a multi map. * * @param supplier the factory for creating the result map * @param classifier the method used to extract the key from the elements * @param <K> the extracted key type of the map * @param <V> the value type of the incoming stream and outgoing map * @return a <tt>Collector</tt> to be used with {@link Stream#collect(java.util.stream.Collector)} */ public static <K, V> Collector<V, MultiMap<K, V>, MultiMap<K, V>> groupingBy(Supplier<MultiMap<K, V>> supplier, Function<V, K> classifier) { return Collector.of(supplier, (map, value) -> map.put(classifier.apply(value), value), (a, b) -> a.merge(b), Function.identity(), Collector.Characteristics.IDENTITY_FINISH); }
private void registerPart(Object part, Class<?>[] implementedInterfaces, Class<?> predecessor, Object successor) { for (Class<?> iFace : implementedInterfaces) { if (successor == null) { parts.put(iFace, part); if (predecessor != null) { synchronized (parts) { parts.getUnderlyingMap().get(iFace).removeIf(p -> p.getClass().equals(predecessor)); } } } else { synchronized (parts) { Collection<Object> partList = parts.getUnderlyingMap().get(iFace); if (partList == null || !partList.contains(successor)) { parts.put(iFace, part); } } } } }
/** * Creates a {@link Collector} which can be used to group a stream into a multi map. * <p> * This method permits the classifier function to return multiple keys for a single element. The element will * be added for all returned keys. * * @param supplier the factory for creating the result map * @param classifier the method used to extract the keys from the elements * @param <K> the extracted key type of the map * @param <V> the value type of the incoming stream and outgoing map * @return a <tt>Collector</tt> to be used with {@link Stream#collect(java.util.stream.Collector)} */ public static <K, V> Collector<V, MultiMap<K, V>, MultiMap<K, V>> groupingByMultiple(Supplier<MultiMap<K, V>> supplier, Function<V, Collection<K>> classifier) { return Collector.of(supplier, (map, value) -> classifier.apply(value).forEach(key -> map.put(key, value)), (a, b) -> a.merge(b), Function.identity(), Collector.Characteristics.IDENTITY_FINISH); }
/** * Merges the given multi map into this one. * <p> * If both maps contain values for the same key, to lists will be joined together. * <p> * <b>Note</b>: This will modify the callee instead of creating a new result map * * @param other the other map to merge into this one * @return the callee itself for further processing */ public MultiMap<K, V> merge(MultiMap<K, V> other) { if (other != null) { other.base.entrySet().stream().flatMap(Tuple::flatten).forEach(t -> put(t.getFirst(), t.getSecond())); } return this; }
/** * Provides a {@link Collector} which can be used to collect a {@link Stream} of tuples into a {@link MultiMap}. * <p> * The type of <tt>MultiMap</tt> used can be determined by the <tt>supplier</tt>. So for example * {@code MultiMap::createOrdered} will create a map with ordered keys. * * @param supplier factory for generating the result map * @param <K> key type of the tuples being processed * @param <V> value type of the tuples being processed * @return a <tt>Collector</tt> which transforms a stream of tuples into a multi map */ public static <K, V> Collector<Tuple<K, V>, MultiMap<K, V>, MultiMap<K, V>> toMultiMap(Supplier<MultiMap<K, V>> supplier) { return Collector.of(supplier, (map, tuple) -> map.put(tuple.getFirst(), tuple.getSecond()), (a, b) -> a.merge(b), Function.identity(), Collector.Characteristics.IDENTITY_FINISH); }
@SuppressWarnings("unchecked") private static Collection<Class<?>> getMixins(Class<? extends Mixable> forClass) { if (allMixins == null) { MultiMap<Class<? extends Mixable>, Class<?>> mixinMap = MultiMap.create(); for (Class<?> mixinClass : Injector.context().getParts(Mixin.class, Class.class)) { Class<?> target = mixinClass.getAnnotation(Mixin.class).value(); if (Mixable.class.isAssignableFrom(target)) { mixinMap.put((Class<? extends Mixable>) target, mixinClass); } else { Mixing.LOG.WARN("Mixing class '%s' has a non mixable target class (%s). Skipping mixin.", mixinClass.getName(), target.getName()); } } allMixins = mixinMap; } return allMixins.get(forClass); }
if (SQLEntity.class.isAssignableFrom(ed.getType())) { if (databases.containsKey(ed.getRealm())) { targetByRealm.put(ed.getRealm(), createTable(ed));
private Collection<Transformer<?, ?>> getFactories(Class<?> sourceType, Class<?> targetType) { if (factories == null) { MultiMap<Tuple<Class<?>, Class<?>>, Transformer<?, ?>> result = MultiMap.createOrdered(); for (Transformer<?, ?> factory : factoryList) { result.put(Tuple.create(factory.getSourceClass(), factory.getTargetClass()), factory); } factories = result; } return factories.get(Tuple.create(sourceType, targetType)); }