Codota Logo
Multiset.setCount
Code IndexAdd Codota to your IDE (free)

How to use
setCount
method
in
com.google.common.collect.Multiset

Best Java code snippets using com.google.common.collect.Multiset.setCount (Showing top 20 results out of 369)

  • Common ways to obtain Multiset
private void myMethod () {
Multiset m =
  • Codota IconMultimap fromMultimap;fromMultimap.keys()
  • Codota Iconnew Keys()
  • Codota Iconnew Multimaps.Keys<K, V>(this)
  • Smart code suggestions by Codota
}
origin: google/guava

@Override
public boolean setCount(E element, int oldCount, int newCount) {
 synchronized (mutex) {
  return delegate().setCount(element, oldCount, newCount);
 }
}
origin: google/guava

@Override
public int setCount(E element, int count) {
 synchronized (mutex) {
  return delegate().setCount(element, count);
 }
}
origin: google/guava

 private int setCount(E element, int count) {
  return getMultiset().setCount(element, count);
 }
}
origin: google/guava

/**
 * Adds or removes the necessary occurrences of an element such that the element attains the
 * desired count.
 *
 * @param element the element to add or remove occurrences of
 * @param count the desired count of the element in this multiset
 * @return this {@code Builder} object
 * @throws NullPointerException if {@code element} is null
 * @throws IllegalArgumentException if {@code count} is negative
 */
@CanIgnoreReturnValue
public Builder<E> setCount(E element, int count) {
 contents.setCount(checkNotNull(element), count);
 return this;
}
origin: google/guava

@CanIgnoreReturnValue
@Override
public boolean setCount(E element, int oldCount, int newCount) {
 return delegate().setCount(element, oldCount, newCount);
}
origin: google/guava

@CanIgnoreReturnValue
@Override
public int setCount(E element, int count) {
 return delegate().setCount(element, count);
}
origin: wildfly/wildfly

@Override
public int setCount(E element, int count) {
 synchronized (mutex) {
  return delegate().setCount(element, count);
 }
}
origin: google/guava

/** Delegate implementation which cares about the element type. */
private static <E> boolean retainOccurrencesImpl(
  Multiset<E> multisetToModify, Multiset<?> occurrencesToRetain) {
 checkNotNull(multisetToModify);
 checkNotNull(occurrencesToRetain);
 // Avoiding ConcurrentModificationExceptions is tricky.
 Iterator<Entry<E>> entryIterator = multisetToModify.entrySet().iterator();
 boolean changed = false;
 while (entryIterator.hasNext()) {
  Entry<E> entry = entryIterator.next();
  int retainCount = occurrencesToRetain.count(entry.getElement());
  if (retainCount == 0) {
   entryIterator.remove();
   changed = true;
  } else if (retainCount < entry.getCount()) {
   multisetToModify.setCount(entry.getElement(), retainCount);
   changed = true;
  }
 }
 return changed;
}
origin: google/guava

private void assertSetCountNegativeOldCount() {
 try {
  getMultiset().setCount(e3(), -1, 1);
  fail("calling setCount() with a negative oldCount should throw IllegalArgumentException");
 } catch (IllegalArgumentException expected) {
 }
}
origin: google/guava

/** An implementation of {@link Multiset#setCount(Object, int, int)}. */
static <E> boolean setCountImpl(Multiset<E> self, E element, int oldCount, int newCount) {
 checkNonnegative(oldCount, "oldCount");
 checkNonnegative(newCount, "newCount");
 if (self.count(element) == oldCount) {
  self.setCount(element, newCount);
  return true;
 } else {
  return false;
 }
}
origin: google/j2objc

@CanIgnoreReturnValue
@Override
public boolean setCount(E element, int oldCount, int newCount) {
 return delegate().setCount(element, oldCount, newCount);
}
origin: google/j2objc

@CanIgnoreReturnValue
@Override
public int setCount(E element, int count) {
 return delegate().setCount(element, count);
}
origin: google/guava

private boolean setCount(E element, int count) {
 return getMultiset().setCount(element, getMultiset().count(element), count);
}
origin: google/guava

@SuppressWarnings("cast")
@Override
public boolean remove(Object object) {
 if (object instanceof Multiset.Entry) {
  Entry<?> entry = (Entry<?>) object;
  Object element = entry.getElement();
  int entryCount = entry.getCount();
  if (entryCount != 0) {
   // Safe as long as we never add a new entry, which we won't.
   @SuppressWarnings("unchecked")
   Multiset<Object> multiset = (Multiset) multiset();
   return multiset.setCount(element, entryCount, 0);
  }
 }
 return false;
}
origin: wildfly/wildfly

@CanIgnoreReturnValue
@Override
public boolean setCount(E element, int oldCount, int newCount) {
 return delegate().setCount(element, oldCount, newCount);
}
origin: wildfly/wildfly

@CanIgnoreReturnValue
@Override
public int setCount(E element, int count) {
 return delegate().setCount(element, count);
}
origin: google/guava

@CollectionFeature.Require(SUPPORTS_ADD)
public void testSetCountConditional_oldCountTooLarge() {
 assertFalse(
   "setCount() with a too-large oldCount should return false",
   getMultiset().setCount(e0(), 2, 3));
 expectUnchanged();
}
origin: google/j2objc

@SuppressWarnings("cast")
@Override
public boolean remove(Object object) {
 if (object instanceof Multiset.Entry) {
  Entry<?> entry = (Entry<?>) object;
  Object element = entry.getElement();
  int entryCount = entry.getCount();
  if (entryCount != 0) {
   // Safe as long as we never add a new entry, which we won't.
   @SuppressWarnings("unchecked")
   Multiset<Object> multiset = (Multiset) multiset();
   return multiset.setCount(element, entryCount, 0);
  }
 }
 return false;
}
origin: google/guava

@CollectionSize.Require(SEVERAL)
@CollectionFeature.Require(SUPPORTS_ADD)
public void testSetCountConditional_oldCountTooSmallNonzero() {
 initThreeCopies();
 assertFalse(
   "setCount() with a too-small oldCount should return false",
   getMultiset().setCount(e0(), 1, 5));
 expectContents(nCopies(3, e0()));
}
origin: google/guava

@CollectionSize.Require(absent = ZERO)
@CollectionFeature.Require(SUPPORTS_ADD)
public void testSetCountConditional_oldCountTooSmallZero() {
 assertFalse(
   "setCount() with a too-small oldCount should return false",
   getMultiset().setCount(e0(), 0, 2));
 expectUnchanged();
}
com.google.common.collectMultisetsetCount

Javadoc

Adds or removes the necessary occurrences of an element such that the element attains the desired count.

Popular methods of Multiset

  • add
    Adds a number of occurrences of an element to this multiset. Note that if occurrences == 1, this met
  • count
    Returns the number of occurrences of an element in this multiset (thecount of the element). Note tha
  • elementSet
    Returns the set of distinct elements contained in this multiset. The element set is backed by the sa
  • entrySet
    Returns a view of the contents of this multiset, grouped into Multiset.Entry instances, each providi
  • remove
    Removes a number of occurrences of the specified element from this multiset. If the multiset contain
  • size
    Returns the total number of all occurrences of all elements in this multiset. Note: this method does
  • isEmpty
  • clear
  • contains
    Determines whether this multiset contains the specified element.This method refines Collection#conta
  • addAll
  • iterator
    Elements that occur multiple times in the multiset will appear multiple times in this iterator, thou
  • equals
    Compares the specified object with this multiset for equality. Returns true if the given object is a
  • iterator,
  • equals,
  • containsAll,
  • hashCode,
  • removeAll,
  • toString,
  • stream,
  • forEachEntry,
  • retainAll

Popular in Java

  • Parsing JSON documents to java classes using gson
  • requestLocationUpdates (LocationManager)
  • setRequestProperty (URLConnection)
    Sets the general request property. If a property with the key already exists, overwrite its value wi
  • scheduleAtFixedRate (ScheduledExecutorService)
    Creates and executes a periodic action that becomes enabled first after the given initial delay, and
  • Menu (java.awt)
  • BufferedInputStream (java.io)
    Wraps an existing InputStream and buffers the input. Expensive interaction with the underlying input
  • OutputStream (java.io)
    A writable sink for bytes.Most clients will use output streams that write data to the file system (
  • Thread (java.lang)
    A thread is a thread of execution in a program. The Java Virtual Machine allows an application to ha
  • NumberFormat (java.text)
    The abstract base class for all number formats. This class provides the interface for formatting and
  • BasicDataSource (org.apache.commons.dbcp)
    Basic implementation of javax.sql.DataSource that is configured via JavaBeans properties. This is no
Codota Logo
  • Products

    Search for Java codeSearch for JavaScript codeEnterprise
  • IDE Plugins

    IntelliJ IDEAWebStormAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogCodota Academy Plugin user guide Terms of usePrivacy policyJava Code IndexJavascript Code Index
Get Codota for your IDE now