@SuppressWarnings({"unchecked", "rawtypes"}) protected void visitMap(Map<?, ?> mapVal) { Map newContent = new LinkedHashMap(); boolean entriesModified = false; for (Map.Entry entry : mapVal.entrySet()) { Object key = entry.getKey(); int keyHash = (key != null ? key.hashCode() : 0); Object newKey = resolveValue(key); int newKeyHash = (newKey != null ? newKey.hashCode() : 0); Object val = entry.getValue(); Object newVal = resolveValue(val); newContent.put(newKey, newVal); entriesModified = entriesModified || (newVal != val || newKey != key || newKeyHash != keyHash); } if (entriesModified) { mapVal.clear(); mapVal.putAll(newContent); } }
/** * same as clojure's (merge-with merge m1 m2). */ private static Map mergeMaps(Map m1, Map m2) { if (m2 == null) { return m1; } for (Object o : m2.entrySet()) { Map.Entry entry = (Map.Entry) o; Object k = entry.getKey(); Map existing = (Map) m1.get(k); if (existing == null) { m1.put(k, entry.getValue()); } else { existing.putAll((Map) m2.get(k)); } } return m1; }
/** * 合并用户对namespace的修改 */ private Map<String, String> mergeOverriddenProperties(String namespace, Map<String, String> configurations) { if (addedOrModifiedPropertiesOfNamespace.containsKey(namespace)) { configurations.putAll(addedOrModifiedPropertiesOfNamespace.get(namespace)); } if (deletedKeysOfNamespace.containsKey(namespace)) { for (String k : deletedKeysOfNamespace.get(namespace)) { configurations.remove(k); } } return configurations; }
public void updatePatterns(Map<String, Map<Integer, Set<E>>> tempPatsForSents) { for(Map.Entry<String, Map<Integer, Set<E>>> en :tempPatsForSents.entrySet()){ Map<Integer, Set<E>> m = getPatternsForAllTokens(en.getKey()); if(m == null) m = new HashMap<>(); tempPatsForSents.get(en.getKey()).putAll(m); } this.addPatterns(tempPatsForSents); close(); }
public <T> void mergeDataset( String property, Map<String, T> new_metadata ) { Object md = dynamic_properties.get( property ); if ( !( md instanceof Map<?, ?> ) ) { md = new HashMap<String, T>(); dynamic_properties.put( property, md ); } @SuppressWarnings("unchecked") Map<String, T> metadata = ( Map<String, T> ) md; metadata.putAll( new_metadata ); }
public ConstantsAndVariables(Properties props, Map<String, Set<CandidatePhrase>> labelDictionary, Map<String, Class<? extends Key<String>>> answerClass, Map<String, Class> generalizeClasses, Map<String, Map<Class, Object>> ignoreClasses) throws IOException { //make the list unmodifiable! for(Entry<String, Set<CandidatePhrase>> en2: labelDictionary.entrySet()){ seedLabelDictionary.put(en2.getKey(), Collections.unmodifiableSet(en2.getValue())); } this.labels = labelDictionary.keySet(); this.answerClass = answerClass; this.generalizeClasses = generalizeClasses; if(this.generalizeClasses == null) this.generalizeClasses = new HashMap<>(); this.generalizeClasses.putAll(answerClass); this.ignoreWordswithClassesDuringSelection = ignoreClasses; setUp(props); }
private Map<String, String> createEnvironment(List<String> paths, Platform platform, Map<String, String> additionalEnvironment) { final Map<String, String> environment = new HashMap<>(System.getenv()); String pathVarName = "PATH"; String pathVarValue = environment.get(pathVarName); if (platform.isWindows()) { for (Map.Entry<String, String> entry : environment.entrySet()) { if ("PATH".equalsIgnoreCase(entry.getKey())) { pathVarName = entry.getKey(); pathVarValue = entry.getValue(); } } } StringBuilder pathBuilder = new StringBuilder(); if (pathVarValue != null) { pathBuilder.append(pathVarValue).append(File.pathSeparator); } for (String path : paths) { pathBuilder.insert(0, File.pathSeparator).insert(0, path); } environment.put(pathVarName, pathBuilder.toString()); if (additionalEnvironment != null) { environment.putAll(additionalEnvironment); } return environment; }
/** * Merge a single hint into a map of hints, possibly creating and copying * all hints into a new map, or otherwise if the map of hints is empty, * creating a new single entry map. * @param hints a map of hints to be merge * @param hintName the hint name to merge * @param hintValue the hint value to merge * @return a single map with all hints */ public static Map<String, Object> merge(Map<String, Object> hints, String hintName, Object hintValue) { if (hints.isEmpty()) { return Collections.singletonMap(hintName, hintValue); } else { Map<String, Object> result = new HashMap<>(hints.size() + 1); result.putAll(hints); result.put(hintName, hintValue); return result; } }
/** * Invoked once immediately after construction * * @param storm_conf Storm configuration */ @Override public void prepare(Map<String, Object> storm_conf) { Map<?, ?> params = (Map<?, ?>) storm_conf.get(Config.STORM_GROUP_MAPPING_SERVICE_PARAMS); Map<String, Set<String>> mapping = (Map<String, Set<String>>) params.get(STORM_FIXED_GROUP_MAPPING); if (mapping != null) { cachedGroups.putAll(mapping); } else { LOG.warn("There is no initial group mapping"); } }
for (Map.Entry<String, String> entry : parameters.entrySet()) { String value = getParameters().get(entry.getKey()); if (value == null) { if (entry.getValue() != null) { hasAndEqual = false; break; if (!value.equals(entry.getValue())) { hasAndEqual = false; break; map.putAll(parameters); return new URL(protocol, username, password, host, port, path, map);
static <T extends StandardTable<Object, Object, Object>> T populate( SerializationStreamReader reader, T table) throws SerializationException { Map<?, ?> hashMap = (Map<?, ?>) reader.readObject(); for (Entry<?, ?> row : hashMap.entrySet()) { table.row(row.getKey()).putAll((Map<?, ?>) row.getValue()); } return table; }
public Topologies(Map<String, TopologyDetails> topologies) { if (topologies == null) topologies = new HashMap<>(); this.topologies = new HashMap<>(topologies.size()); this.topologies.putAll(topologies); this.nameToId = new HashMap<>(topologies.size()); for (String topologyId : topologies.keySet()) { TopologyDetails topology = topologies.get(topologyId); this.nameToId.put(topology.getName(), topologyId); } }
/** * Only keep props that are not in parent */ private Map<String, String> collectModuleSpecificProps(DefaultInputModule module) { Map<String, String> moduleSpecificProps = new HashMap<>(); AbstractProjectOrModule parent = hierarchy.parent(module); if (parent == null) { moduleSpecificProps.putAll(module.properties()); } else { Map<String, String> parentProps = parent.properties(); for (Map.Entry<String, String> entry : module.properties().entrySet()) { if (!parentProps.containsKey(entry.getKey()) || !parentProps.get(entry.getKey()).equals(entry.getValue())) { moduleSpecificProps.put(entry.getKey(), entry.getValue()); } } } return moduleSpecificProps; }
private Map<String, Object> contextWithSqlId(Map<String, Object> queryContext) { Map<String, Object> newContext = new HashMap<>(); if (queryContext != null) { newContext.putAll(queryContext); } if (!newContext.containsKey(PlannerContext.CTX_SQL_QUERY_ID)) { newContext.put(PlannerContext.CTX_SQL_QUERY_ID, UUID.randomUUID().toString()); } return newContext; }