@Override public Map<String, String> toSingleValueMap() { LinkedHashMap<String, String> singleValueMap = new LinkedHashMap<>(this.headers.size()); this.headers.forEach((key, value) -> singleValueMap.put(key, value.get(0))); return singleValueMap; }
@Override public V get(K key) { return cache.get(key); }
@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(); }
@Override protected Map<String, String> create(Entry<String, String>[] entries) { return populate(new LinkedHashMap<String, String>(), entries); } })
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); } } }
private void resolveWaitingFutures() { final LinkedHashMap<CustomSettableFuture, Counter> waitingFuturesCopy = new LinkedHashMap<>(); synchronized (waitingFutures) { waitingFuturesCopy.putAll(waitingFutures); waitingFutures.clear(); } for (Map.Entry<CustomSettableFuture, Counter> e : waitingFuturesCopy.entrySet()) { try { e.getKey().set(getRequestsSinceWithoutWait(e.getValue())); } catch (Exception ex) { e.getKey().setException(ex); } } }
@SuppressWarnings("serial") public void testLinkedHashMapWithInitialMap() { Map<String, String> map = new LinkedHashMap<String, String>( ImmutableMap.of( "Hello", "World", "first", "second", "polygene", "lubricants", "alpha", "betical")); LinkedHashMap<String, String> copy = Maps.newLinkedHashMap(map); Iterator<Entry<String, String>> iter = copy.entrySet().iterator(); assertTrue(iter.hasNext()); Entry<String, String> entry = iter.next(); assertEquals("Hello", entry.getKey()); assertEquals("World", entry.getValue()); assertTrue(iter.hasNext()); entry = iter.next(); assertEquals("first", entry.getKey()); assertEquals("second", entry.getValue()); assertTrue(iter.hasNext()); entry = iter.next(); assertEquals("polygene", entry.getKey()); assertEquals("lubricants", entry.getValue()); assertTrue(iter.hasNext()); entry = iter.next(); assertEquals("alpha", entry.getKey()); assertEquals("betical", entry.getValue()); assertFalse(iter.hasNext()); }
public JdbcSqlStat createSqlStat(String sql) { lock.writeLock().lock(); try { JdbcSqlStat sqlStat = sqlStatMap.get(sql); if (sqlStat == null) { sqlStat = new JdbcSqlStat(sql); sqlStat.setDbType(this.dbType); sqlStat.setName(this.name); sqlStatMap.put(sql, sqlStat); } return sqlStat; } finally { lock.writeLock().unlock(); } }
@Override public V put(K key, V value) { lock.lock(); try { return super.put(key, value); } finally { lock.unlock(); } }
@VisibleForTesting static ImmutableMap<File, ClassLoader> getClassPathEntries(ClassLoader classloader) { LinkedHashMap<File, ClassLoader> entries = Maps.newLinkedHashMap(); // Search parent first, since it's the order ClassLoader#loadClass() uses. ClassLoader parent = classloader.getParent(); if (parent != null) { entries.putAll(getClassPathEntries(parent)); } for (URL url : getClassLoaderUrls(classloader)) { if (url.getProtocol().equals("file")) { File file = toFile(url); if (!entries.containsKey(file)) { entries.put(file, classloader); } } } return ImmutableMap.copyOf(entries); }
public void testSegmentPut_evict() { int maxSize = 10; LocalCache<Object, Object> map = makeLocalCache(createCacheBuilder().concurrencyLevel(1).maximumSize(maxSize)); // manually add elements to avoid eviction int originalCount = 1024; LinkedHashMap<Object, Object> originalMap = Maps.newLinkedHashMap(); for (int i = 0; i < originalCount; i++) { Object key = new Object(); Object value = new Object(); map.put(key, value); originalMap.put(key, value); if (i >= maxSize) { Iterator<Object> it = originalMap.keySet().iterator(); it.next(); it.remove(); } assertEquals(originalMap, map); } }
@Override public Object getValueAt(int rowIndex, int columnIndex) { if (list != null && rowIndex < list.size()) {// 没有超出最大行数 LinkedHashMap<String, Object> dataNow = list.get(rowIndex); if (showKeys != null) { int titleLen = showKeys.size(); if (titleLen > 0 && columnIndex < titleLen) { return dataNow.get(showKeys.get(columnIndex)); } } else { Object[] values = dataNow.values().toArray(); if (columnIndex < values.length) { return values[columnIndex]; } } } return null; }
@Override public Set<Entry<String, V>> entrySet() { return this.targetMap.entrySet(); }
@Override public Set<String> keySet() { return this.targetMap.keySet(); }
private void checkState(PartitionStates<String> states, LinkedHashMap<TopicPartition, String> expected) { assertEquals(expected.keySet(), states.partitionSet()); assertEquals(expected.size(), states.size()); List<PartitionStates.PartitionState<String>> statesList = new ArrayList<>(); for (Map.Entry<TopicPartition, String> entry : expected.entrySet()) { statesList.add(new PartitionStates.PartitionState<>(entry.getKey(), entry.getValue())); assertTrue(states.contains(entry.getKey())); } assertEquals(statesList, states.partitionStates()); }
public List<JdbcSqlStatValue> getRuningSqlList() { List<JdbcSqlStat> stats = new ArrayList<JdbcSqlStat>(sqlStatMap.size()); lock.readLock().lock(); try { for (Map.Entry<String, JdbcSqlStat> entry : sqlStatMap.entrySet()) { JdbcSqlStat stat = entry.getValue(); if (stat.getRunningCount() >= 0) { stats.add(entry.getValue()); } } } finally { lock.readLock().unlock(); } List<JdbcSqlStatValue> values = new ArrayList<JdbcSqlStatValue>(stats.size()); for (JdbcSqlStat stat : stats) { JdbcSqlStatValue value = stat.getValue(false); if (value.getRunningCount() > 0) { values.add(value); } } return values; }
@Override @Nullable public V computeIfAbsent(String key, Function<? super String, ? extends V> mappingFunction) { String oldKey = this.caseInsensitiveKeys.putIfAbsent(convertKey(key), key); if (oldKey != null) { return this.targetMap.get(oldKey); } return this.targetMap.computeIfAbsent(key, mappingFunction); }
@Override @Nullable public V putIfAbsent(String key, @Nullable V value) { String oldKey = this.caseInsensitiveKeys.putIfAbsent(convertKey(key), key); if (oldKey != null) { return this.targetMap.get(oldKey); } return this.targetMap.putIfAbsent(key, value); }