Tabnine Logo
Multiset.setCount
Code IndexAdd Tabnine 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)

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 int setCount(E element, int count) {
 return delegate().setCount(element, count);
}
origin: google/guava

@CanIgnoreReturnValue
@Override
public boolean setCount(E element, int oldCount, int newCount) {
 return delegate().setCount(element, oldCount, newCount);
}
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 int setCount(E element, int count) {
 return delegate().setCount(element, count);
}
origin: wildfly/wildfly

@CanIgnoreReturnValue
@Override
public boolean setCount(E element, int oldCount, int newCount) {
 return delegate().setCount(element, oldCount, newCount);
}
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

  • Creating JSON documents from java classes using gson
  • setRequestProperty (URLConnection)
  • compareTo (BigDecimal)
  • orElseThrow (Optional)
    Return the contained value, if present, otherwise throw an exception to be created by the provided s
  • Color (java.awt)
    The Color class is used to encapsulate colors in the default sRGB color space or colors in arbitrary
  • Map (java.util)
    A Map is a data structure consisting of a set of keys and values in which each key is mapped to a si
  • Queue (java.util)
    A collection designed for holding elements prior to processing. Besides basic java.util.Collection o
  • Vector (java.util)
    Vector is an implementation of List, backed by an array and synchronized. All optional operations in
  • JButton (javax.swing)
  • Location (org.springframework.beans.factory.parsing)
    Class that models an arbitrary location in a Resource.Typically used to track the location of proble
  • Github Copilot alternatives
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