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; } }
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; } }
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; } }
/** * 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; } }
/** * 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; } }
@Override public int setCount(E element, int count) { checkNonnegative(count, "count"); AtomicInteger existingCounter; int oldCount; if (count == 0) { existingCounter = backingMap.remove(element); oldCount = getAndSet(existingCounter, count); } else { existingCounter = backingMap.get(element); oldCount = getAndSet(existingCounter, count); if (existingCounter == null) { backingMap.put(element, new AtomicInteger(count)); } } size += (count - oldCount); return oldCount; }
public int setCount(E element, int count) { checkNonnegative(count, "count"); if (count == count(element)) { return count; } else if (count == 0) { remove(element); return 1; } else { throw new UnsupportedOperationException(); } }
/** * Adds or removes occurrences of {@code element} such that the {@link #count} * of the element becomes {@code count}. * * @return the count of {@code element} in the multiset before this call * @throws IllegalArgumentException if {@code count} is negative */ @Override public int setCount(E element, int count) { checkNonnegative(count, "count"); return (count == 0) ? removeAllOccurrences(element) : unbox(countMap.put(element, count)); }
public int setCount(E element, int count) { checkNonnegative(count, "count"); if (count == count(element)) { return count; } else if (count == 0) { remove(element); return 1; } else { throw new UnsupportedOperationException(); } }
static <E> int setCountImpl(Multiset<E> self, E element, int count) { checkNonnegative(count, "count"); int oldCount = self.count(element); int delta = count - oldCount; if (delta > 0) { self.add(element, delta); } else if (delta < 0) { self.remove(element, -delta); } return oldCount; }
/** * Adds or removes occurrences of {@code element} such that the {@link #count} * of the element becomes {@code count}. * * @return the count of {@code element} in the multiset before this call * @throws IllegalArgumentException if {@code count} is negative */ @Override public int setCount(E element, int count) { checkNonnegative(count, "count"); return (count == 0) ? removeAllOccurrences(element) : unbox(countMap.put(element, count)); }
public int setCount(E element, int count) { checkNonnegative(count, "count"); if (count == count(element)) { return count; } else if (count == 0) { remove(element); return 1; } else { throw new UnsupportedOperationException(); } }
static <E> int setCountImpl(Multiset<E> self, E element, int count) { checkNonnegative(count, "count"); int oldCount = self.count(element); int delta = count - oldCount; if (delta > 0) { self.add(element, delta); } else if (delta < 0) { self.remove(element, -delta); } return oldCount; }
/** * Adds or removes occurrences of {@code element} such that the {@link #count} * of the element becomes {@code count}. * * @return the count of {@code element} in the multiset before this call * @throws IllegalArgumentException if {@code count} is negative */ @Override public int setCount(E element, int count) { checkNonnegative(count, "count"); return (count == 0) ? removeAllOccurrences(element) : unbox(countMap.put(element, count)); }
static <E> int setCountImpl(Multiset<E> self, E element, int count) { checkNonnegative(count, "count"); int oldCount = self.count(element); int delta = count - oldCount; if (delta > 0) { self.add(element, delta); } else if (delta < 0) { self.remove(element, -delta); } return oldCount; }
@Override public int setCount(E element, int count) { checkNonnegative(count, "count"); if (count == count(element)) { return count; } else if (count == 0) { remove(element); return 1; } else { throw new UnsupportedOperationException(); } }
/** * Adds or removes occurrences of {@code element} such that the {@link #count} * of the element becomes {@code count}. * * @return the count of {@code element} in the multiset before this call * @throws IllegalArgumentException if {@code count} is negative */ @Override public int setCount(E element, int count) { checkNonnegative(count, "count"); return (count == 0) ? removeAllOccurrences(element) : unbox(countMap.put(element, count)); }
public int setCount(E element, int count) { checkNonnegative(count, "count"); if (count == count(element)) { return count; } else if (count == 0) { remove(element); return 1; } else { throw new UnsupportedOperationException(); } }
/** * An implementation of {@link Multiset#setCount(Object, int)}. */ static <E> int setCountImpl(Multiset<E> self, E element, int count) { checkNonnegative(count, "count"); int oldCount = self.count(element); int delta = count - oldCount; if (delta > 0) { self.add(element, delta); } else if (delta < 0) { self.remove(element, -delta); } return oldCount; }
@Override public int remove(@Nullable Object element, int occurrences) { Multisets.checkNonnegative(occurrences, "occurrences"); if (occurrences == 0) { return count(element); } else { return contains(element) ? unfiltered.remove(element, occurrences) : 0; } }