public void addAssignedSplit(Node node) { assignmentCount.merge(node, 1, (x, y) -> x + y); } }
@Override public V merge( K key, V value, BiFunction<? super V, ? super V, ? extends V> remappingFunction) { synchronized (mutex) { return delegate().merge(key, value, remappingFunction); } }
@Override public V merge( K key, V value, BiFunction<? super V, ? super V, ? extends V> remappingFunction) { synchronized (mutex) { return delegate().merge(key, value, remappingFunction); } }
@Override public void updateCount(Tuple2<Long, IntType> value, Map<Long, Integer> windowCounts) { windowCounts.merge(value.f0, value.f1.value, (a, b) -> a + b); }
public static Map<PlanNodeId, PlanNodeStats> aggregatePlanNodeStats(List<StageInfo> stageInfos) { Map<PlanNodeId, PlanNodeStats> aggregatedStats = new HashMap<>(); List<PlanNodeStats> planNodeStats = stageInfos.stream() .flatMap(stageInfo -> stageInfo.getTasks().stream()) .map(TaskInfo::getStats) .flatMap(taskStats -> getPlanNodeStats(taskStats).stream()) .collect(toList()); for (PlanNodeStats stats : planNodeStats) { aggregatedStats.merge(stats.getPlanNodeId(), stats, (left, right) -> left.mergeWith(right)); } return aggregatedStats; }
public void testMergeNullValue() { try { getMap() .merge( k0(), null, (oldV, newV) -> { throw new AssertionFailedError("Should not call merge function if value was null"); }); fail("Expected NullPointerException or UnsupportedOperationException"); } catch (NullPointerException | UnsupportedOperationException expected) { } }
@Override public void validate(PlanNode planNode, Session session, Metadata metadata, SqlParser sqlParser, TypeProvider types, WarningCollector warningCollector) { Map<PlanNodeId, PlanNode> planNodeIds = new HashMap<>(); searchFrom(planNode) .findAll() .forEach(node -> planNodeIds.merge(node.getId(), node, this::reportDuplicateId)); }
public void testMergeNullFunction() { try { getMap().merge(k0(), v3(), null); fail("Expected NullPointerException or UnsupportedOperationException"); } catch (NullPointerException | UnsupportedOperationException expected) { } }
@MapFeature.Require(absent = SUPPORTS_PUT) public void testMergeUnsupported() { try { getMap() .merge( k3(), v3(), (oldV, newV) -> { throw new AssertionFailedError(); }); fail("Expected UnsupportedOperationException"); } catch (UnsupportedOperationException expected) { } }
private void updateRowsOnHosts(MemoryTableHandle table, Collection<Slice> fragments) { checkState( tableDataFragments.containsKey(table.getTableId()), "Uninitialized table [%s.%s]", table.getSchemaName(), table.getTableName()); Map<HostAddress, MemoryDataFragment> dataFragments = tableDataFragments.get(table.getTableId()); for (Slice fragment : fragments) { MemoryDataFragment memoryDataFragment = MemoryDataFragment.fromSlice(fragment); dataFragments.merge(memoryDataFragment.getHostAddress(), memoryDataFragment, MemoryDataFragment::merge); } }
@Override public void updateCount(Tuple4<Long, Long, Long, IntType> value, Map<Long, Integer> windowCounts) { windowCounts.merge(value.f0, 1, (a, b) -> a + b); // verify the contents of that window, the contents should be: // (key + num windows so far) assertEquals("Window counts don't match for key " + value.f0 + ".", value.f0.intValue() + windowCounts.get(value.f0), value.f3.value); } }
@MapFeature.Require({SUPPORTS_PUT, ALLOWS_NULL_KEYS}) public void testMergeAbsentNullKey() { assertEquals( "Map.merge(null, value, function) should return value", v3(), getMap() .merge( null, v3(), (oldV, newV) -> { throw new AssertionFailedError( "Should not call merge function if key was absent"); })); expectAdded(entry(null, v3())); }
@MapFeature.Require(SUPPORTS_PUT) public void testAbsent() { assertEquals( "Map.merge(absent, value, function) should return value", v3(), getMap() .merge( k3(), v3(), (oldV, newV) -> { throw new AssertionFailedError( "Should not call merge function if key was absent"); })); expectAdded(e3()); }
@CheckNoWriter @CheckNoStats @Test(dataProvider = "caches") @CacheSpec(removalListener = { Listener.DEFAULT, Listener.REJECTING }) public void merge_absent(Map<Integer, Integer> map, CacheContext context) { Integer result = map.merge(context.absentKey(), context.absentValue(), (key, value) -> value); assertThat(result, is(context.absentValue())); assertThat(map.get(context.absentKey()), is(context.absentValue())); assertThat(map.size(), is(1 + context.original().size())); }
@CheckNoWriter @CheckNoStats @CacheSpec(removalListener = { Listener.DEFAULT, Listener.REJECTING }) @Test(dataProvider = "caches", expectedExceptions = NullPointerException.class) public void merge_nullValue(Map<Integer, Integer> map, CacheContext context) { map.merge(1, null, (key, value) -> -key); }
@CheckNoWriter @CheckNoStats @CacheSpec(removalListener = { Listener.DEFAULT, Listener.REJECTING }) @Test(dataProvider = "caches", expectedExceptions = NullPointerException.class) public void merge_nullMappingFunction(Map<Integer, Integer> map, CacheContext context) { map.merge(1, 1, null); }
@MapFeature.Require({SUPPORTS_PUT, ALLOWS_NULL_VALUES}) @CollectionSize.Require(absent = ZERO) public void testMappedToNull() { initMapWithNullValue(); assertEquals( "Map.merge(keyMappedToNull, value, function) should return value", v3(), getMap() .merge( getKeyForNullValue(), v3(), (oldV, newV) -> { throw new AssertionFailedError( "Should not call merge function if key was mapped to null"); })); expectReplacement(entry(getKeyForNullValue(), v3())); }
@MapFeature.Require(SUPPORTS_REMOVE) @CollectionSize.Require(absent = ZERO) public void testMergePresentToNull() { assertNull( "Map.merge(present, value, functionReturningNull) should return null", getMap() .merge( k0(), v3(), (oldV, newV) -> { assertEquals(v0(), oldV); assertEquals(v3(), newV); return null; })); expectMissing(e0()); }
@MapFeature.Require(SUPPORTS_PUT) @CollectionSize.Require(absent = ZERO) public void testMergeFunctionThrows() { try { getMap() .merge( k0(), v3(), (oldV, newV) -> { assertEquals(v0(), oldV); assertEquals(v3(), newV); throw new ExpectedException(); }); fail("Expected ExpectedException"); } catch (ExpectedException expected) { } expectUnchanged(); }
@MapFeature.Require(SUPPORTS_PUT) @CollectionSize.Require(absent = ZERO) public void testMergePresent() { assertEquals( "Map.merge(present, value, function) should return function result", v4(), getMap() .merge( k0(), v3(), (oldV, newV) -> { assertEquals(v0(), oldV); assertEquals(v3(), newV); return v4(); })); expectReplacement(entry(k0(), v4())); }