int getMessageCountAndThenIncrement(String msg) { // don't insert null elements if (msg == null) { return 0; } Integer i; // LinkedHashMap is not LinkedHashMap. See also LBCLASSIC-255 synchronized (this) { i = super.get(msg); if (i == null) { i = 0; } else { i = i + 1; } super.put(msg, i); } return i; }
private Map<String, Map<String, Exclusion>> unmodifiableRefStringMap( Map<String, Map<String, ParamsBuilder>> mapmap) { LinkedHashMap<String, Map<String, Exclusion>> fieldNameByClassName = new LinkedHashMap<>(); for (Map.Entry<String, Map<String, ParamsBuilder>> entry : mapmap.entrySet()) { fieldNameByClassName.put(entry.getKey(), unmodifiableRefMap(entry.getValue())); } return unmodifiableMap(fieldNameByClassName); }
@Override public Iterable<Entry<K, Collection<V>>> order(List<Entry<K, Collection<V>>> insertionOrder) { Map<K, Collection<V>> map = new HashMap<>(); List<Entry<K, V>> builder = new ArrayList<>(); for (Entry<K, Collection<V>> entry : insertionOrder) { for (V v : entry.getValue()) { builder.add(mapEntry(entry.getKey(), v)); } map.put(entry.getKey(), entry.getValue()); } Iterable<Entry<K, V>> ordered = multimapGenerator.order(builder); LinkedHashMap<K, Collection<V>> orderedMap = new LinkedHashMap<>(); for (Entry<K, V> entry : ordered) { orderedMap.put(entry.getKey(), map.get(entry.getKey())); } return orderedMap.entrySet(); }
targetAliasToPartnInfo.remove(targetAlias); List<Path> pathsToRemove = new ArrayList<>(); for (Entry<Path, ArrayList<String>> entry: targetPathToAliases.entrySet()) { ArrayList<String> aliases = entry.getValue(); aliases.remove(targetAlias); if (aliases.isEmpty()) { pathsToRemove.add(entry.getKey()); targetAliasToWork.put(sourceAlias, sourceAliasToWork.get(sourceAlias)); targetAliasToPartnInfo.putAll(sourceAliasToPartnInfo); targetPathToPartitionInfo.putAll(sourcePathToPartitionInfo); List<Path> pathsToAdd = new ArrayList<>(); for (Entry<Path, ArrayList<String>> entry: sourcePathToAliases.entrySet()) { ArrayList<String> aliases = entry.getValue(); if (aliases.contains(sourceAlias)) { pathsToAdd.add(entry.getKey()); targetPathToAliases.put(pathToAdd, new ArrayList<String>()); targetPathToAliases.get(pathToAdd).add(sourceAlias);
/** * Puts the dependency for an operator, columninfo tuple. * @param op The operator whose dependency is being inserted. * @param col The column info whose dependency is being inserted. * @param dep The dependency. */ public void putDependency(Operator<? extends OperatorDesc> op, ColumnInfo col, Dependency dep) { LinkedHashMap<ColumnInfo, Dependency> colMap = depMap.get(op); if (colMap == null) { colMap = new LinkedHashMap<ColumnInfo, Dependency>(); depMap.put(op, colMap); } colMap.put(col, dep); }
List<TopicPartition> altered = new ArrayList<>(); for (Iterator<Entry<TopicPartition, PartitionData>> iter = sessionPartitions.entrySet().iterator(); iter.hasNext(); ) { Entry<TopicPartition, PartitionData> entry = iter.next(); TopicPartition topicPartition = entry.getKey(); PartitionData prevData = entry.getValue(); PartitionData nextData = next.get(topicPartition); if (nextData != null) { if (prevData.equals(nextData)) { next.put(topicPartition, nextData); entry.setValue(nextData); altered.add(topicPartition); removed.add(topicPartition); for (Entry<TopicPartition, PartitionData> entry : next.entrySet()) { TopicPartition topicPartition = entry.getKey(); PartitionData nextData = entry.getValue(); if (sessionPartitions.containsKey(topicPartition)) { sessionPartitions.put(topicPartition, nextData); added.add(topicPartition);
/** * Creates a proxy instance for the supplied annotation type and values. * * @param classLoader The class loader that should be used for loading the annotation's values. * @param annotationType The annotation's type. * @param values The values that the annotation contains. * @param <S> The type of the handled annotation. * @return A proxy for the annotation type and values. * @throws ClassNotFoundException If the class of an instance that is contained by this annotation could not be found. */ @SuppressWarnings("unchecked") public static <S extends Annotation> S of(ClassLoader classLoader, Class<S> annotationType, Map<String, ? extends AnnotationValue<?, ?>> values) throws ClassNotFoundException { LinkedHashMap<Method, AnnotationValue.Loaded<?>> loadedValues = new LinkedHashMap<Method, AnnotationValue.Loaded<?>>(); for (Method method : annotationType.getDeclaredMethods()) { AnnotationValue<?, ?> annotationValue = values.get(method.getName()); loadedValues.put(method, (annotationValue == null ? defaultValueOf(method) : annotationValue).load(classLoader)); } return (S) Proxy.newProxyInstance(classLoader, new Class<?>[]{annotationType}, new AnnotationInvocationHandler<S>(annotationType, loadedValues)); }
@Override public void replaceRoots(Map<Operator<?>, Operator<?>> replacementMap) { LinkedHashMap<String, Operator<?>> newAliasToWork = new LinkedHashMap<String, Operator<?>>(); for (Map.Entry<String, Operator<?>> entry: aliasToWork.entrySet()) { newAliasToWork.put(entry.getKey(), replacementMap.get(entry.getValue())); } setAliasToWork(newAliasToWork); }
private static void addToHistory(LinkedHashMap<String, Properties> propHistory, Map<String, Object> flatMap) { String id = String.valueOf(flatMap.get("pipelineid")); String key = (String) flatMap.get("key"); String value = (String) flatMap.get("value"); if (!propHistory.containsKey(id)) { propHistory.put(id, new Properties()); } propHistory.get(id).add(new Property(key, value)); }
/** * Prints a summary of important details about the chore. Used for debugging purposes */ private void printChoreDetails(final String header, ScheduledChore chore) { LinkedHashMap<String, String> output = new LinkedHashMap<>(); output.put(header, ""); output.put("Chore name: ", chore.getName()); output.put("Chore period: ", Integer.toString(chore.getPeriod())); output.put("Chore timeBetweenRuns: ", Long.toString(chore.getTimeBetweenRuns())); for (Entry<String, String> entry : output.entrySet()) { if (LOG.isTraceEnabled()) LOG.trace(entry.getKey() + entry.getValue()); } }
public String route(int jobId, List<String> addressList) { // cache clear if (System.currentTimeMillis() > CACHE_VALID_TIME) { jobLRUMap.clear(); CACHE_VALID_TIME = System.currentTimeMillis() + 1000*60*60*24; } // init lru LinkedHashMap<String, String> lruItem = jobLRUMap.get(jobId); if (lruItem == null) { /** * LinkedHashMap * a、accessOrder:ture=访问顺序排序(get/put时排序);false=插入顺序排期; * b、removeEldestEntry:新增元素时将会调用,返回true时会删除最老元素;可封装LinkedHashMap并重写该方法,比如定义最大容量,超出是返回true即可实现固定长度的LRU算法; */ lruItem = new LinkedHashMap<String, String>(16, 0.75f, true); jobLRUMap.putIfAbsent(jobId, lruItem); } // put for (String address: addressList) { if (!lruItem.containsKey(address)) { lruItem.put(address, address); } } // load String eldestKey = lruItem.entrySet().iterator().next().getKey(); String eldestValue = lruItem.get(eldestKey); return eldestValue; }
/** * Creates a map from a sequence of entries * * @param entries The entries to map * @param <K> The key type * @param <V> The value type * @return A map */ @SafeVarargs public static <K, V> Map<K, V> mkMap(final Map.Entry<K, V>... entries) { final LinkedHashMap<K, V> result = new LinkedHashMap<>(); for (final Map.Entry<K, V> entry : entries) { result.put(entry.getKey(), entry.getValue()); } return result; }
private void update(Map<TopicPartition, S> partitionToState) { LinkedHashMap<String, List<TopicPartition>> topicToPartitions = new LinkedHashMap<>(); for (TopicPartition tp : partitionToState.keySet()) { List<TopicPartition> partitions = topicToPartitions.computeIfAbsent(tp.topic(), k -> new ArrayList<>()); partitions.add(tp); } for (Map.Entry<String, List<TopicPartition>> entry : topicToPartitions.entrySet()) { for (TopicPartition tp : entry.getValue()) { S state = partitionToState.get(tp); map.put(tp, state); } } }
targetAliasToPartnInfo.remove(targetAlias); List<Path> pathsToRemove = new ArrayList<>(); for (Entry<Path, ArrayList<String>> entry: targetPathToAliases.entrySet()) { ArrayList<String> aliases = entry.getValue(); aliases.remove(targetAlias); if (aliases.isEmpty()) { pathsToRemove.add(entry.getKey()); targetAliasToWork.put(sourceAlias, sourceAliasToWork.get(sourceAlias)); targetAliasToPartnInfo.putAll(sourceAliasToPartnInfo); targetPathToPartitionInfo.putAll(sourcePathToPartitionInfo); List<Path> pathsToAdd = new ArrayList<>(); for (Entry<Path, ArrayList<String>> entry: sourcePathToAliases.entrySet()) { ArrayList<String> aliases = entry.getValue(); if (aliases.contains(sourceAlias)) { pathsToAdd.add(entry.getKey()); targetPathToAliases.put(pathToAdd, new ArrayList<String>()); targetPathToAliases.get(pathToAdd).add(sourceAlias);
/** * * @param key Key. * @param node Mapped node. * @param mappings Full node mapping. */ private void addNodeMapping( KeyCacheObject key, ClusterNode node, Map<ClusterNode, LinkedHashMap<KeyCacheObject, Boolean>> mappings ) { LinkedHashMap<KeyCacheObject, Boolean> old = mappings.get(node); if (old == null) mappings.put(node, old = new LinkedHashMap<>(3, 1f)); old.put(key, false); }
public void put(String key, File file, String fileName, MediaType contentType) { if (key != null) { List<FileWrapper> fileWrappers = fileParamsMap.get(key); if (fileWrappers == null) { fileWrappers = new ArrayList<>(); fileParamsMap.put(key, fileWrappers); } fileWrappers.add(new FileWrapper(file, fileName, contentType)); } }