public Challenge(String scheme, Map<String, String> authParams) { if (scheme == null) throw new NullPointerException("scheme == null"); if (authParams == null) throw new NullPointerException("authParams == null"); this.scheme = scheme; Map<String, String> newAuthParams = new LinkedHashMap<>(); for (Entry<String, String> authParam : authParams.entrySet()) { String key = (authParam.getKey() == null) ? null : authParam.getKey().toLowerCase(US); newAuthParams.put(key, authParam.getValue()); } this.authParams = unmodifiableMap(newAuthParams); }
private void innerUpdateEndOffsets(final Map<TopicPartition, Long> newOffsets, final boolean replace) { for (final Map.Entry<TopicPartition, Long> entry : newOffsets.entrySet()) { List<Long> offsets = endOffsets.get(entry.getKey()); if (replace || offsets == null) { offsets = new ArrayList<>(); } offsets.add(entry.getValue()); endOffsets.put(entry.getKey(), offsets); } }
private Map<String, List<LazyHeaderFactory>> copyHeaders() { Map<String, List<LazyHeaderFactory>> result = new HashMap<>(headers.size()); for (Map.Entry<String, List<LazyHeaderFactory>> entry : headers.entrySet()) { @SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops") List<LazyHeaderFactory> valueCopy = new ArrayList<>(entry.getValue()); result.put(entry.getKey(), valueCopy); } return result; }
/** * Stores the contents of a map in an output stream, as part of serialization. It does not support * concurrent maps whose content may change while the method is running. * * <p>The serialized output consists of the number of entries, first key, first value, second key, * second value, and so on. */ static <K, V> void writeMap(Map<K, V> map, ObjectOutputStream stream) throws IOException { stream.writeInt(map.size()); for (Map.Entry<K, V> entry : map.entrySet()) { stream.writeObject(entry.getKey()); stream.writeObject(entry.getValue()); } }
public static boolean mapEquals(Map<?, ?> map1, Map<?, ?> map2) { if (map1 == null && map2 == null) { return true; } if (map1 == null || map2 == null) { return false; } if (map1.size() != map2.size()) { return false; } for (Map.Entry<?, ?> entry : map1.entrySet()) { Object key = entry.getKey(); Object value1 = entry.getValue(); Object value2 = map2.get(key); if (!objectEquals(value1, value2)) { return false; } } return true; }
@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(); }
public void testOrderedAsMapEntries() { TreeMultimap<String, Integer> multimap = createPopulate(); Iterator<Entry<String, Collection<Integer>>> iterator = multimap.asMap().entrySet().iterator(); Entry<String, Collection<Integer>> entry = iterator.next(); assertEquals(null, entry.getKey()); assertThat(entry.getValue()).containsExactly(7, 3, 1); entry = iterator.next(); assertEquals("tree", entry.getKey()); assertThat(entry.getValue()).containsExactly(null, 0); entry = iterator.next(); assertEquals("google", entry.getKey()); assertThat(entry.getValue()).containsExactly(6, 2); }
@Override protected void expectContents(Collection<Entry<K, V>> expected) { // TODO: move this to invariant checks once the appropriate hook exists? super.expectContents(expected); for (Entry<K, V> entry : expected) { assertEquals( "Wrong value for key " + entry.getKey(), entry.getValue(), getMap().get(entry.getKey())); } }
@Override public String toString() { Iterator<Map.Entry<String, Object>> entries = entrySet().iterator(); StringBuilder sb = new StringBuilder("{"); while (entries.hasNext()) { Map.Entry<String, Object> entry = entries.next(); sb.append(entry.getKey()); sb.append('='); sb.append(valueToString(entry.getValue())); sb.append(entries.hasNext() ? ", " : ""); } sb.append("}"); return sb.toString(); }
static <T> StringBuilder allSequenceFrequency(Map<Integer, List<T>> its) { StringBuilder b = new StringBuilder(); for (Map.Entry<Integer, List<T>> e : its.entrySet()) { if (b.length() > 0) { b.append(", "); } b.append(e.getKey()).append("={"); b.append(sequenceFrequency(e.getValue())); b.append("}"); } return b; } static <T> StringBuilder sequenceFrequency(Iterable<T> it) {
@CollectionSize.Require(absent = ZERO) @MapFeature.Require(SUPPORTS_REMOVE) public void testEntriesRemainValidAfterRemove() { Iterator<Entry<K, V>> iterator = multimap().entries().iterator(); Entry<K, V> entry = iterator.next(); K key = entry.getKey(); V value = entry.getValue(); multimap().removeAll(key); assertEquals(key, entry.getKey()); assertEquals(value, entry.getValue()); } }
private void checkAllDataSources() { Map<String, DataSource> dataSourceMap = selector.getDataSourceMap(); for (Map.Entry<String, DataSource> e : dataSourceMap.entrySet()) { if (!(e.getValue() instanceof DruidDataSource)) { continue; } boolean flag = check(e.getKey(), (DruidDataSource) e.getValue()); if (flag) { errorCounts.put(e.getKey(), 0); } else { if (!errorCounts.containsKey(e.getKey())) { errorCounts.put(e.getKey(), 0); } int count = errorCounts.get(e.getKey()); errorCounts.put(e.getKey(), count + 1); } } }