Tabnine Logo
Map.merge
Code IndexAdd Tabnine to your IDE (free)

How to use
merge
method
in
java.util.Map

Best Java code snippets using java.util.Map.merge (Showing top 20 results out of 2,088)

origin: prestodb/presto

  public void addAssignedSplit(Node node)
  {
    assignmentCount.merge(node, 1, (x, y) -> x + y);
  }
}
origin: google/guava

@Override
public V merge(
  K key, V value, BiFunction<? super V, ? super V, ? extends V> remappingFunction) {
 synchronized (mutex) {
  return delegate().merge(key, value, remappingFunction);
 }
}
origin: prestodb/presto

@Override
public V merge(
  K key, V value, BiFunction<? super V, ? super V, ? extends V> remappingFunction) {
 synchronized (mutex) {
  return delegate().merge(key, value, remappingFunction);
 }
}
origin: apache/flink

@Override
public void updateCount(Tuple2<Long, IntType> value, Map<Long, Integer> windowCounts) {
  windowCounts.merge(value.f0, value.f1.value, (a, b) -> a + b);
}
origin: prestodb/presto

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;
}
origin: google/guava

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) {
 }
}
origin: prestodb/presto

@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));
}
origin: google/guava

public void testMergeNullFunction() {
 try {
  getMap().merge(k0(), v3(), null);
  fail("Expected NullPointerException or UnsupportedOperationException");
 } catch (NullPointerException | UnsupportedOperationException expected) {
 }
}
origin: google/guava

@MapFeature.Require(absent = SUPPORTS_PUT)
public void testMergeUnsupported() {
 try {
  getMap()
    .merge(
      k3(),
      v3(),
      (oldV, newV) -> {
       throw new AssertionFailedError();
      });
  fail("Expected UnsupportedOperationException");
 } catch (UnsupportedOperationException expected) {
 }
}
origin: prestodb/presto

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);
  }
}
origin: apache/flink

  @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);
  }
}
origin: google/guava

@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()));
}
origin: google/guava

@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());
}
origin: ben-manes/caffeine

@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()));
}
origin: ben-manes/caffeine

@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);
}
origin: ben-manes/caffeine

@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);
}
origin: google/guava

@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()));
}
origin: google/guava

@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());
}
origin: google/guava

@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();
}
origin: google/guava

@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()));
}
java.utilMapmerge

Popular methods of Map

  • put
    Maps the specified key to the specified value.
  • get
  • entrySet
    Returns a Set view of the mappings contained in this map. The set is backed by the map, so changes t
  • containsKey
    Returns whether this Map contains the specified key.
  • keySet
    Returns a set of the keys contained in this Map. The Set is backed by this Map so changes to one are
  • values
    Returns a Collection view of the values contained in this map. The collection is backed by the map,
  • remove
  • size
    Returns the number of mappings in this Map.
  • isEmpty
    Returns true if this map contains no key-value mappings.
  • clear
    Removes all elements from this Map, leaving it empty.
  • putAll
    Copies all of the mappings from the specified map to this map (optional operation). The effect of th
  • forEach
  • putAll,
  • forEach,
  • equals,
  • computeIfAbsent,
  • hashCode,
  • getOrDefault,
  • containsValue,
  • putIfAbsent,
  • compute

Popular in Java

  • Making http post requests using okhttp
  • getContentResolver (Context)
  • getResourceAsStream (ClassLoader)
  • findViewById (Activity)
  • Thread (java.lang)
    A thread is a thread of execution in a program. The Java Virtual Machine allows an application to ha
  • ServerSocket (java.net)
    This class represents a server-side socket that waits for incoming client connections. A ServerSocke
  • Locale (java.util)
    Locale represents a language/country/variant combination. Locales are used to alter the presentatio
  • Set (java.util)
    A Set is a data structure which does not allow duplicate elements.
  • Stack (java.util)
    Stack is a Last-In/First-Out(LIFO) data structure which represents a stack of objects. It enables u
  • LogFactory (org.apache.commons.logging)
    Factory for creating Log instances, with discovery and configuration features similar to that employ
  • Top plugins for WebStorm
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now