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

How to use
replaceAll
method
in
java.util.Map

Best Java code snippets using java.util.Map.replaceAll (Showing top 20 results out of 666)

origin: google/guava

@Override
public void replaceAll(BiFunction<? super K, ? super V, ? extends V> function) {
 synchronized (mutex) {
  delegate().replaceAll(function);
 }
}
origin: google/guava

@Override
public void replaceAll(BiFunction<? super K, ? super V, ? extends V> function) {
 this.delegate.replaceAll(function);
 inverse.delegate.clear();
 Entry<K, V> broken = null;
 Iterator<Entry<K, V>> itr = this.delegate.entrySet().iterator();
 while (itr.hasNext()) {
  Entry<K, V> entry = itr.next();
  K k = entry.getKey();
  V v = entry.getValue();
  K conflict = inverse.delegate.putIfAbsent(v, k);
  if (conflict != null) {
   broken = entry;
   // We're definitely going to throw, but we'll try to keep the BiMap in an internally
   // consistent state by removing the bad entry.
   itr.remove();
  }
 }
 if (broken != null) {
  throw new IllegalArgumentException("value already present: " + broken.getValue());
 }
}
origin: prestodb/presto

@Override
public void replaceAll(BiFunction<? super K, ? super V, ? extends V> function) {
 synchronized (mutex) {
  delegate().replaceAll(function);
 }
}
origin: apache/flink

private void cleanUp() {
  // invalidate row
  final Row deleteRow = materializedTable.get(validRowPosition);
  if (rowPositionCache.get(deleteRow) == validRowPosition) {
    // this row has no duplicates in the materialized table,
    // it can be removed from the cache
    rowPositionCache.remove(deleteRow);
  }
  materializedTable.set(validRowPosition, null);
  validRowPosition++;
  // perform clean up in batches
  if (validRowPosition >= overcommitThreshold) {
    materializedTable.subList(0, validRowPosition).clear();
    // adjust all cached indexes
    rowPositionCache.replaceAll((k, v) -> v - validRowPosition);
    validRowPosition = 0;
  }
}
origin: prestodb/presto

@Override
public void replaceAll(BiFunction<? super K, ? super V, ? extends V> function) {
 this.delegate.replaceAll(function);
 inverse.delegate.clear();
 Entry<K, V> broken = null;
 Iterator<Entry<K, V>> itr = this.delegate.entrySet().iterator();
 while (itr.hasNext()) {
  Entry<K, V> entry = itr.next();
  K k = entry.getKey();
  V v = entry.getValue();
  K conflict = inverse.delegate.putIfAbsent(v, k);
  if (conflict != null) {
   broken = entry;
   // We're definitely going to throw, but we'll try to keep the BiMap in an internally
   // consistent state by removing the bad entry.
   itr.remove();
  }
 }
 if (broken != null) {
  throw new IllegalArgumentException("value already present: " + broken.getValue());
 }
}
origin: wildfly/wildfly

@Override
public void replaceAll(BiFunction<? super K, ? super V, ? extends V> function) {
 synchronized (mutex) {
  delegate().replaceAll(function);
 }
}
origin: wildfly/wildfly

@Override
public void replaceAll(BiFunction<? super K, ? super V, ? extends V> function) {
 this.delegate.replaceAll(function);
 inverse.delegate.clear();
 Entry<K, V> broken = null;
 Iterator<Entry<K, V>> itr = this.delegate.entrySet().iterator();
 while (itr.hasNext()) {
  Entry<K, V> entry = itr.next();
  K k = entry.getKey();
  V v = entry.getValue();
  K conflict = inverse.delegate.putIfAbsent(v, k);
  if (conflict != null) {
   broken = entry;
   // We're definitely going to throw, but we'll try to keep the BiMap in an internally
   // consistent state by removing the bad entry.
   itr.remove();
  }
 }
 if (broken != null) {
  throw new IllegalArgumentException("value already present: " + broken.getValue());
 }
}
origin: google/guava

 @MapFeature.Require(absent = SUPPORTS_PUT)
 public void testReplaceAll_unsupportedNoOpFunction() {
  try {
   getMap().replaceAll((K k, V v) -> v);
  } catch (UnsupportedOperationException tolerated) {
  }
  expectUnchanged();
 }
}
origin: google/guava

@MapFeature.Require(SUPPORTS_PUT)
public void testReplaceAllRotate() {
 getMap()
   .replaceAll(
     (K k, V v) -> {
      int index = keys().asList().indexOf(k);
      return values().asList().get(index + 1);
     });
 List<Entry<K, V>> expectedEntries = new ArrayList<>();
 for (Entry<K, V> entry : getSampleEntries()) {
  int index = keys().asList().indexOf(entry.getKey());
  expectedEntries.add(Helpers.mapEntry(entry.getKey(), values().asList().get(index + 1)));
 }
 expectContents(expectedEntries);
}
origin: google/guava

@MapFeature.Require(SUPPORTS_PUT)
@CollectionFeature.Require(KNOWN_ORDER)
public void testReplaceAllPreservesOrder() {
 getMap()
   .replaceAll(
     (K k, V v) -> {
      int index = keys().asList().indexOf(k);
      return values().asList().get(index + 1);
     });
 List<Entry<K, V>> orderedEntries = getOrderedElements();
 int index = 0;
 for (K key : getMap().keySet()) {
  assertEquals(orderedEntries.get(index).getKey(), key);
  index++;
 }
}
origin: google/guava

@MapFeature.Require(absent = SUPPORTS_PUT)
@CollectionSize.Require(ZERO)
public void testReplaceAll_unsupportedByEmptyCollection() {
 try {
  getMap()
    .replaceAll(
      (K k, V v) -> {
       int index = keys().asList().indexOf(k);
       return values().asList().get(index + 1);
      });
 } catch (UnsupportedOperationException tolerated) {
 }
 expectUnchanged();
}
origin: google/guava

@MapFeature.Require(absent = SUPPORTS_PUT)
@CollectionSize.Require(absent = ZERO)
public void testReplaceAll_unsupported() {
 try {
  getMap()
    .replaceAll(
      (K k, V v) -> {
       int index = keys().asList().indexOf(k);
       return values().asList().get(index + 1);
      });
  fail(
    "replaceAll() should throw UnsupportedOperation if a map does "
      + "not support it and is not empty.");
 } catch (UnsupportedOperationException expected) {
 }
 expectUnchanged();
}
origin: ben-manes/caffeine

@CheckNoStats
@Test(dataProvider = "caches")
@CacheSpec(population = { Population.SINGLETON, Population.PARTIAL, Population.FULL },
  removalListener = { Listener.DEFAULT, Listener.CONSUMING })
public void putAll_replace(Map<Integer, Integer> map, CacheContext context) {
 Map<Integer, Integer> entries = new LinkedHashMap<>(context.original());
 entries.replaceAll((key, value) -> key);
 map.putAll(entries);
 assertThat(map, is(equalTo(entries)));
 assertThat(map, hasRemovalNotifications(context, entries.size(), RemovalCause.REPLACED));
 verifyWriter(context, (verifier, writer) -> {
  verifier.wroteAll(entries);
 });
}
origin: ben-manes/caffeine

@CheckNoStats
@Test(dataProvider = "caches", expectedExceptions = WriteException.class)
@CacheSpec(implementation = Implementation.Caffeine, keys = ReferenceType.STRONG,
  population = { Population.SINGLETON, Population.PARTIAL, Population.FULL },
  compute = Compute.SYNC, writer = Writer.EXCEPTIONAL, removalListener = Listener.REJECTING)
public void replaceAll_writerFails(Map<Integer, Integer> map, CacheContext context) {
 try {
  map.replaceAll((key, value) -> context.absentValue());
 } finally {
  assertThat(map, equalTo(context.original()));
 }
}
origin: ben-manes/caffeine

@CheckNoWriter @CheckNoStats
@CacheSpec(population = { Population.SINGLETON, Population.PARTIAL, Population.FULL },
  removalListener = { Listener.DEFAULT, Listener.REJECTING })
@Test(dataProvider = "caches", expectedExceptions = NullPointerException.class)
public void replaceAll_nullValue(Map<Integer, Integer> map, CacheContext context) {
 map.replaceAll((key, value) -> null);
}
origin: ben-manes/caffeine

@CheckNoWriter @CheckNoStats
@CacheSpec(removalListener = { Listener.DEFAULT, Listener.REJECTING })
@Test(dataProvider = "caches", expectedExceptions = NullPointerException.class)
public void replaceAll_null(Map<Integer, Integer> map, CacheContext context) {
 map.replaceAll(null);
}
origin: ben-manes/caffeine

@Test(dataProvider = "caches")
@CacheSpec(population = { Population.SINGLETON, Population.PARTIAL, Population.FULL },
  removalListener = { Listener.DEFAULT, Listener.CONSUMING })
public void putAll_replace(Cache<Integer, Integer> cache, CacheContext context) {
 Map<Integer, Integer> entries = new HashMap<>(context.original());
 entries.replaceAll((key, value) -> value + 1);
 cache.putAll(entries);
 assertThat(cache.asMap(), is(equalTo(entries)));
 assertThat(cache, hasRemovalNotifications(context, entries.size(), RemovalCause.REPLACED));
 verifyWriter(context, (verifier, writer) -> {
  verifier.wroteAll(entries);
 });
}
origin: ben-manes/caffeine

@CacheSpec
@CheckNoWriter @CheckNoStats
@Test(dataProvider = "caches")
public void replaceAll_sameValue(Map<Integer, Integer> map, CacheContext context) {
 map.replaceAll((key, value) -> value);
 assertThat(map, is(equalTo(context.original())));
 if (context.isGuava() || context.isAsync()) {
  assertThat(map, hasRemovalNotifications(context, map.size(), RemovalCause.REPLACED));
 } else {
  assertThat(context.consumedNotifications(), hasSize(0));
 }
}
origin: ben-manes/caffeine

@CacheSpec
@CheckNoStats
@Test(dataProvider = "caches")
public void replaceAll_differentValue(Map<Integer, Integer> map, CacheContext context) {
 map.replaceAll((key, value) -> key);
 map.forEach((key, value) -> {
  assertThat(value, is(equalTo(key)));
  verifyWriter(context, (verifier, writer) -> verifier.wrote(key, key));
 });
 assertThat(map, hasRemovalNotifications(context, map.size(), RemovalCause.REPLACED));
 verifyWriter(context, (verifier, writer) -> verifier.writes(context.original().size()));
}
origin: speedment/speedment

Function<A, A> downstreamFinisher = (Function<A, A>) downstream.finisher();
Function<Map<K, A>, M> finisher = intermediate -> {
  intermediate.replaceAll((k, v) -> downstreamFinisher.apply(v));
  @SuppressWarnings("unchecked")
  M castResult = (M) intermediate;
java.utilMapreplaceAll

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,
  • merge

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