@Override public boolean setInitParameter(String name, String value) { Assert.notNull(name, "Parameter name must not be null"); if (this.initParameters.containsKey(name)) { return false; } this.initParameters.put(name, value); return true; }
@Override @Nullable public Object getValue(@Nullable String name) { if (!this.uriVariables.containsKey(name)) { throw new IllegalArgumentException("Map has no value for '" + name + "'"); } return this.uriVariables.get(name); } }
/** * Add an option argument for the given option name and add the given value to the * list of values associated with this option (of which there may be zero or more). * The given value may be {@code null}, indicating that the option was specified * without an associated value (e.g. "--foo" vs. "--foo=bar"). */ public void addOptionArg(String optionName, @Nullable String optionValue) { if (!this.optionArgs.containsKey(optionName)) { this.optionArgs.put(optionName, new ArrayList<>()); } if (optionValue != null) { this.optionArgs.get(optionName).add(optionValue); } }
void putSanitizeName(RType rType, String sanitizeName, String rawName) { HashMap<String, String> sanitizeNameMap; if (!sanitizeTypeMap.containsKey(rType)) { sanitizeNameMap = new HashMap<>(); sanitizeTypeMap.put(rType, sanitizeNameMap); } else { sanitizeNameMap = sanitizeTypeMap.get(rType); } if (!sanitizeNameMap.containsKey(sanitizeName)) { sanitizeNameMap.put(sanitizeName, rawName); } }
/** * Determine if the parameters in this {@code MimeType} and the supplied * {@code MimeType} are equal, performing case-insensitive comparisons * for {@link Charset Charsets}. * @since 4.2 */ private boolean parametersAreEqual(MimeType other) { if (this.parameters.size() != other.parameters.size()) { return false; } for (Map.Entry<String, String> entry : this.parameters.entrySet()) { String key = entry.getKey(); if (!other.parameters.containsKey(key)) { return false; } if (PARAM_CHARSET.equals(key)) { if (!ObjectUtils.nullSafeEquals(getCharset(), other.getCharset())) { return false; } } else if (!ObjectUtils.nullSafeEquals(entry.getValue(), other.parameters.get(key))) { return false; } } return true; }
private List<Node> convertToNodes(Map<Integer, Node> brokers, Object[] brokerIds) { List<Node> nodes = new ArrayList<>(brokerIds.length); for (Object brokerId : brokerIds) if (brokers.containsKey(brokerId)) nodes.add(brokers.get(brokerId)); else nodes.add(new Node((int) brokerId, "", -1)); return nodes; }
private static Map<String, Object> combineProperties(Set<String> specifiedPropertyKeys, Map<String, Object> defaultProperties, Map<String, Object> inheritedProperties) { Map<String, Object> finalProperties = new HashMap<>(inheritedProperties); for (Map.Entry<String, Object> entry : defaultProperties.entrySet()) { if (specifiedPropertyKeys.contains(entry.getKey()) || !finalProperties.containsKey(entry.getKey())) { finalProperties.put(entry.getKey(), entry.getValue()); } } return finalProperties; } }
public ConfigDef define(ConfigKey key) { if (configKeys.containsKey(key.name)) { throw new ConfigException("Configuration " + key.name + " is defined twice."); } if (key.group != null && !groups.contains(key.group)) { groups.add(key.group); } configKeys.put(key.name, key); return this; }
private static int mergeMaps(Map<String, Integer> map, Map<String, Integer> other) { int deltaSize = 0; for (Map.Entry<String, Integer> entry : other.entrySet()) { if (!map.containsKey(entry.getKey())) { deltaSize += entry.getKey().getBytes().length + SIZE_OF_INT; } map.put(entry.getKey(), map.getOrDefault(entry.getKey(), 0) + other.getOrDefault(entry.getKey(), 0)); } return deltaSize; }
/** * Given two maps (A, B), returns all the key-value pairs in A whose keys are not contained in B */ public static <K, V> Map<K, V> subtractMap(Map<? extends K, ? extends V> minuend, Map<? extends K, ? extends V> subtrahend) { return minuend.entrySet().stream() .filter(entry -> !subtrahend.containsKey(entry.getKey())) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); }
GcCounters() { // connect to itself final JStatData jStatData = JStatData.connect(pid); final Map<String, JStatData.Counter<?>> jStatCounters = jStatData.getAllCounters(); generations.add(new GcGeneration(jStatCounters, 0, "young")); generations.add(new GcGeneration(jStatCounters, 1, "old")); // Removed in Java 8 but still actual for previous Java versions if (jStatCounters.containsKey("sun.gc.generation.2.name")) { generations.add(new GcGeneration(jStatCounters, 2, "perm")); } }
public StringInterningAmazonInfoBuilder withMetadata(HashMap<String, String> metadata) { this.metadata = metadata; if (metadata.isEmpty()) { return this; } for (Map.Entry<String, String> entry : metadata.entrySet()) { String key = entry.getKey().intern(); if (VALUE_INTERN_KEYS.containsKey(key)) { entry.setValue(StringCache.intern(entry.getValue())); } } return this; }
private static void addToMatchedTokensByPhrase(String ph, String sentid, int index, int length){ if(!Data.matchedTokensForEachPhrase.containsKey(ph)) Data.matchedTokensForEachPhrase.put(ph, new HashMap<>()); Map<String, List<Integer>> matcheds = Data.matchedTokensForEachPhrase.get(ph); if(!matcheds.containsKey(sentid)) matcheds.put(sentid, new ArrayList<>()); for (int i = 0; i < length; i++) matcheds.get(sentid).add(index + i); }
private Object getIntroductionDelegateFor(Object targetObject) { synchronized (this.delegateMap) { if (this.delegateMap.containsKey(targetObject)) { return this.delegateMap.get(targetObject); } else { Object delegate = createNewDelegate(); this.delegateMap.put(targetObject, delegate); return delegate; } } }
@Override public V apply(@Nullable K key) { V result = map.get(key); return (result != null || map.containsKey(key)) ? result : defaultValue; }
private static boolean areSelectionOverridesEqual( Map<TrackGroupArray, SelectionOverride> first, Map<TrackGroupArray, SelectionOverride> second) { int firstSize = first.size(); if (second.size() != firstSize) { return false; } for (Map.Entry<TrackGroupArray, SelectionOverride> firstEntry : first.entrySet()) { TrackGroupArray key = firstEntry.getKey(); if (!second.containsKey(key) || !Util.areEqual(firstEntry.getValue(), second.get(key))) { return false; } } return true; } }
@Override public void process(int id, Document document) { if (dataset.containsKey(id)) { documents.add(extractor.extract(id, document, dataset.get(id))); } }
public void setAttachmentIfAbsent(String key, String value) { if (attachments == null) { attachments = new HashMap<String, String>(); } if (!attachments.containsKey(key)) { attachments.put(key, value); } }
private static <K, V> void doDifference( Map<? extends K, ? extends V> left, Map<? extends K, ? extends V> right, Equivalence<? super V> valueEquivalence, Map<K, V> onlyOnLeft, Map<K, V> onlyOnRight, Map<K, V> onBoth, Map<K, MapDifference.ValueDifference<V>> differences) { for (Entry<? extends K, ? extends V> entry : left.entrySet()) { K leftKey = entry.getKey(); V leftValue = entry.getValue(); if (right.containsKey(leftKey)) { V rightValue = onlyOnRight.remove(leftKey); if (valueEquivalence.equivalent(leftValue, rightValue)) { onBoth.put(leftKey, leftValue); } else { differences.put(leftKey, ValueDifferenceImpl.create(leftValue, rightValue)); } } else { onlyOnLeft.put(leftKey, leftValue); } } }
/** * Determine whether this registry contains a custom editor * for the specified array/collection element. * @param elementType the target type of the element * (can be {@code null} if not known) * @param propertyPath the property path (typically of the array/collection; * can be {@code null} if not known) * @return whether a matching custom editor has been found */ public boolean hasCustomEditorForElement(@Nullable Class<?> elementType, @Nullable String propertyPath) { if (propertyPath != null && this.customEditorsForPath != null) { for (Map.Entry<String, CustomEditorHolder> entry : this.customEditorsForPath.entrySet()) { if (PropertyAccessorUtils.matchesProperty(entry.getKey(), propertyPath) && entry.getValue().getPropertyEditor(elementType) != null) { return true; } } } // No property-specific editor -> check type-specific editor. return (elementType != null && this.customEditors != null && this.customEditors.containsKey(elementType)); }