/** * Create a new CompositeMap which composites all of the Map instances in the * argument. It copies the argument array, it does not use it directly. * * @param composite Maps to be composited * @param mutator MapMutator to be used for mutation operations */ @SuppressWarnings("unchecked") public CompositeMap(final Map<K, V>[] composite, final MapMutator<K, V> mutator) { this.mutator = mutator; this.composite = new Map[0]; for (int i = composite.length - 1; i >= 0; --i) { this.addComposited(composite[i]); } }
/** * Checks if this Map equals another as per the Map specification. * * @param obj the object to compare to * @return true if the maps are equal */ @Override public boolean equals(final Object obj) { if (obj instanceof Map) { final Map<?, ?> map = (Map<?, ?>) obj; return this.entrySet().equals(map.entrySet()); } return false; }
private synchronized CompositeMap<IOption, Object> compositeFrom(Stream<Map<IOption, Object>> stream) { List<Map<IOption, Object>> list = stream.collect(Collectors.toList()); CompositeMap<IOption, Object> map = new CompositeMap<>(); map.setMutator(new NoOpMapMutator()); for (ListIterator<Map<IOption, Object>> iter = list.listIterator(list.size()); iter.hasPrevious();) { map.addComposited(iter.previous()); } return map; }
private void applyDefaults() { LOGGER.debug("applying defaults"); sectionMap.forEach((key, value) -> { value.values().forEach( option -> getNodeNames().forEach(node -> getOrDefault(getNodeEffectiveMap(node), option, node))); for (Map.Entry<String, Map<IOption, Object>> nodeMap : nodeSpecificDefinedMap.entrySet()) { value.values() .forEach(option -> getOrDefault( new CompositeMap<>(nodeMap.getValue(), definedMap, new NoOpMapMutator()), option, nodeMap.getKey())); } }); }
/** * Gets a hash code for the Map as per the Map specification. * {@inheritDoc} */ @Override public int hashCode() { int code = 0; for (final Map.Entry<K, V> entry : entrySet()) { code += entry.hashCode(); } return code; }