private Map<AbstractProject, List<DependencyGroup>> finalize(Map<AbstractProject, List<DependencyGroup>> m) { for (Entry<AbstractProject, List<DependencyGroup>> e : m.entrySet()) { Collections.sort( e.getValue(), NAME_COMPARATOR ); e.setValue( Collections.unmodifiableList(e.getValue()) ); } return Collections.unmodifiableMap(m); }
public void testEntrySetSetValueSameValue() { // TODO: Investigate the extent to which, in practice, maps that support // put() also support Entry.setValue(). if (!supportsPut) { return; } final Map<K, V> map; try { map = makePopulatedMap(); } catch (UnsupportedOperationException e) { return; } Set<Entry<K, V>> entrySet = map.entrySet(); Entry<K, V> entry = entrySet.iterator().next(); final V oldValue = entry.getValue(); final V returnedValue = entry.setValue(oldValue); assertEquals(oldValue, returnedValue); assertTrue(entrySet.contains(mapEntry(entry.getKey(), oldValue))); assertEquals(oldValue, map.get(entry.getKey())); assertInvariants(map); }
/** * 分割Map,其中旧map直接被改变 * @param src * @param rate * @return */ public static Map<String, String[]> splitMap(Map<String, String[]> src, double rate) { assert 0 <= rate && rate <= 1; Map<String, String[]> output = new TreeMap<String, String[]>(); for (Map.Entry<String, String[]> entry : src.entrySet()) { String[][] array = spiltArray(entry.getValue(), rate); output.put(entry.getKey(), array[0]); entry.setValue(array[1]); } return output; } }
throw new IllegalArgumentException("OUT/INOUT parameter not available: " + key); Object value = this.outputParameters.get(key); if (value instanceof IllegalArgumentException) { throw (IllegalArgumentException) value; this.outputParameters = new LinkedHashMap<>(); this.outputParameters.put(args[0], null); for (Map.Entry<Object, Object> entry : this.outputParameters.entrySet()) { try { Object key = entry.getKey(); if (key instanceof Integer) { entry.setValue(storedProc.getOutputParameterValue((Integer) key)); entry.setValue(storedProc.getOutputParameterValue(key.toString())); entry.setValue(ex);
static <T> void fixReplace(Map<Local, T> toReplace) { List<Map.Entry<Local, T>> set = new ArrayList<>(toReplace.entrySet()); Collections.sort(set, new Comparator<Map.Entry<Local, T>>() { @Override public int compare(Map.Entry<Local, T> localTEntry, Map.Entry<Local, T> t1) { return Integer.compare(localTEntry.getKey()._ls_index, t1.getKey()._ls_index); } }); boolean changed = true; while (changed) { changed = false; for (Map.Entry<Local, T> e : set) { T b = e.getValue(); if(b instanceof Local) { T n = toReplace.get(b); if (n != null && b != n) { changed = true; e.setValue(n); } } } } }
if(map == null) return; for(Map.Entry<Address,View> entry: map.entrySet()) { Address key=entry.getKey(); List<Address> members=new ArrayList<>(entry.getValue().getMembers()); boolean modified=false; for(Iterator<Address> it=members.iterator(); it.hasNext();) { Address val=it.next(); if(val.equals(key)) // we can always talk to ourself ! continue; View view=map.get(val); final Collection<Address> tmp_mbrs=view != null? view.getMembers() : null; if(tmp_mbrs != null && !tmp_mbrs.contains(key)) { View old_view=entry.getValue(); entry.setValue(new View(old_view.getViewId(), members));
if (cm.containsKey(key)) { if (!filteredMappings.contains(key) && cm.get(key) == null) { filteredMappings.add(key); resultMapping.put(key, cm.get(key)); && !cm.get(key).equals(resultMapping.get(key))) { filteredMappings.add(key); resultMapping.remove(key); Iterator<Map.Entry<String, TaggedValue>> it = resultMapping.entrySet().iterator(); while (it.hasNext()) { Map.Entry<String, TaggedValue> entry = it.next(); TaggedValue value = mergeReturnValues(Collections.singletonList(entry.getValue())); if (value == null) { it.remove(); entry.setValue(value);
public void testBiMapEntrySetIteratorRemove() { BiMap<Integer, String> map = HashBiMap.create(); map.put(1, "one"); Set<Entry<Integer, String>> entries = map.entrySet(); Iterator<Entry<Integer, String>> iterator = entries.iterator(); Entry<Integer, String> entry = iterator.next(); entry.setValue("two"); // changes the iterator's current entry value assertEquals("two", map.get(1)); assertEquals(Integer.valueOf(1), map.inverse().get("two")); iterator.remove(); // removes the updated entry assertTrue(map.isEmpty()); }
public <C> CommandDispatcher<C> createCommandDispatcher(Object id, C context) { synchronized (this.dispatchers) { Map.Entry<CommandDispatcher<?>, Integer> existingEntry = this.dispatchers.get(id); if (existingEntry == null) { CommandDispatcher<C> dispatcher = this.factory.createCommandDispatcher(id, context); CommandDispatcher<C> result = new ManagedCommandDispatcher<>(dispatcher, () -> { synchronized (this.dispatchers) { Map.Entry<CommandDispatcher<?>, Integer> entry = this.dispatchers.get(id); synchronized (entry) { int refs = entry.getValue() - 1; this.dispatchers.remove(id); } else { entry.setValue(refs); this.dispatchers.put(id, new AbstractMap.SimpleEntry<>(result, 1)); return result; CommandDispatcher<C> result = (CommandDispatcher<C>) existingEntry.getKey(); int refs = existingEntry.getValue() + 1; existingEntry.setValue(refs);
private static void addCellPermissions(final byte[] perms, Map<byte[], List<Cell>> familyMap) { // Iterate over the entries in the familyMap, replacing the cells therein // with new cells including the ACL data for (Map.Entry<byte[], List<Cell>> e: familyMap.entrySet()) { List<Cell> newCells = Lists.newArrayList(); for (Cell cell: e.getValue()) { // Prepend the supplied perms in a new ACL tag to an update list of tags for the cell List<Tag> tags = new ArrayList<>(); tags.add(new ArrayBackedTag(AccessControlLists.ACL_TAG_TYPE, perms)); Iterator<Tag> tagIterator = PrivateCellUtil.tagsIterator(cell); while (tagIterator.hasNext()) { tags.add(tagIterator.next()); } newCells.add(PrivateCellUtil.createCell(cell, tags)); } // This is supposed to be safe, won't CME e.setValue(newCells); } }
@CheckNoWriter @CheckNoStats @Test(dataProvider = "caches", expectedExceptions = NullPointerException.class) @CacheSpec(implementation = Implementation.Caffeine, population = { Population.SINGLETON, Population.PARTIAL, Population.FULL }) public void writeThroughEntry_null(Map<Integer, Integer> map, CacheContext context) { map.entrySet().iterator().next().setValue(null); }
entry1.setValue(newValue1); } catch (UnsupportedOperationException ex) { entry1.setValue(newValue1); entryConfirmed1.setValue(newValue1); entry2.setValue(newValue2); entryConfirmed2.setValue(newValue2); entry2.setValue(newValue1); // should remove key1 } catch (IllegalArgumentException ex) { return; // simplest way of dealing with tricky situation entryConfirmed2.setValue(newValue1); AbstractTestBidiMap.this.confirmed.remove(key1); assertEquals(newValue1, entry2.getValue()); assertEquals(true, AbstractTestBidiMap.this.map.containsKey(entry2.getKey())); assertEquals(true, AbstractTestBidiMap.this.map.containsValue(newValue1)); assertEquals(newValue1, AbstractTestBidiMap.this.map.get(entry2.getKey())); assertEquals(false, AbstractTestBidiMap.this.map.containsKey(key1)); assertEquals(false, AbstractTestBidiMap.this.map.containsValue(newValue2)); it.next(); // if you fail here, maybe you should be throwing an IAE, see above if (isRemoveSupported()) { it.remove();
public void testLinkedEntries() { Multimap<String, Integer> map = create(); map.put("bar", 1); map.put("foo", 2); map.put("bar", 3); Iterator<Entry<String, Integer>> entries = map.entries().iterator(); Entry<String, Integer> entry = entries.next(); assertEquals("bar", entry.getKey()); assertEquals(1, (int) entry.getValue()); entry = entries.next(); assertEquals("foo", entry.getKey()); assertEquals(2, (int) entry.getValue()); entry.setValue(4); entry = entries.next(); assertEquals("bar", entry.getKey()); assertEquals(3, (int) entry.getValue()); assertFalse(entries.hasNext()); entries.remove(); assertEquals("{bar=[1], foo=[4]}", map.toString()); }
private void handleObject(Iterator<Map.Entry<String, Object>> iterator) { Map.Entry<String, Object> objectEntry = iterator.next(); Object o = objectEntry.getValue(); for (Map.Entry<String, Boolean> stringBooleanEntry : booleanMap.entrySet()) { if (!stringBooleanEntry.getValue()) { iterator.remove(); return; entryList.addAll(objectMap.get(multiPageModel.getPageKey()).entrySet()); if (entryList.size() != 0) { Collections.sort(entryList, new Comparator<Map.Entry<String, MultiPageModel>>() { MultiPageModel value = entryList.get(0).getValue(); for (int i = 1; i < entryList.size(); i++) { value = value.combine(entryList.get(i).getValue()); objectEntry.setValue(value);
/** * Tests the constructors. */ public void testSetValue() { Map map = new HashMap(); map.put("A", "a"); map.put("B", "b"); map.put("C", "c"); Map.Entry entry = new TiedMapEntry(map, "A"); assertSame("A", entry.getKey()); assertSame("a", entry.getValue()); assertSame("a", entry.setValue("x")); assertSame("A", entry.getKey()); assertSame("x", entry.getValue()); entry = new TiedMapEntry(map, "B"); assertSame("B", entry.getKey()); assertSame("b", entry.getValue()); assertSame("b", entry.setValue("y")); assertSame("B", entry.getKey()); assertSame("y", entry.getValue()); entry = new TiedMapEntry(map, "C"); assertSame("C", entry.getKey()); assertSame("c", entry.getValue()); assertSame("c", entry.setValue("z")); assertSame("C", entry.getKey()); assertSame("z", entry.getValue()); }
entry1.setValue(newValue1); } catch (UnsupportedOperationException ex) { entry1.setValue(newValue1); entryConfirmed1.setValue(newValue1); assertEquals(newValue1, entry1.getValue()); assertEquals(true, AbstractTestMap.this.map.containsKey(entry1.getKey())); assertEquals(true, AbstractTestMap.this.map.containsValue(newValue1)); assertEquals(newValue1, AbstractTestMap.this.map.get(entry1.getKey())); verify(); entry1.setValue(newValue1); entryConfirmed1.setValue(newValue1); assertEquals(newValue1, entry1.getValue()); assertEquals(true, AbstractTestMap.this.map.containsKey(entry1.getKey())); assertEquals(true, AbstractTestMap.this.map.containsValue(newValue1)); assertEquals(newValue1, AbstractTestMap.this.map.get(entry1.getKey())); verify(); entry2.setValue(newValue2); entryConfirmed2.setValue(newValue2); assertEquals(newValue2, entry2.getValue()); assertEquals(true, AbstractTestMap.this.map.containsKey(entry2.getKey())); assertEquals(true, AbstractTestMap.this.map.containsValue(newValue2)); assertEquals(newValue2, AbstractTestMap.this.map.get(entry2.getKey())); verify();
public void testEntrySetToTypedArrayMutationThrows() { map.putInstance(String.class, "test"); @SuppressWarnings("unchecked") // Should get a CCE later if cast is wrong Entry<Object, Object> entry = map.entrySet().toArray(new Entry[0])[0]; assertEquals(TypeToken.of(String.class), entry.getKey()); assertEquals("test", entry.getValue()); try { entry.setValue(1); fail(); } catch (UnsupportedOperationException expected) { } }