/** * {@inheritDoc} * * @throws IllegalArgumentException if the call would result in more than * {@link Integer#MAX_VALUE} occurrences of {@code element} in this * multiset. */ @Override public int add(@Nullable E element, int occurrences) { if (occurrences == 0) { return count(element); } checkArgument(occurrences > 0, "occurrences cannot be negative: %s", occurrences); Count frequency = backingMap.get(element); int oldCount; if (frequency == null) { oldCount = 0; backingMap.put(element, new Count(occurrences)); } else { oldCount = frequency.get(); long newCount = (long) oldCount + (long) occurrences; checkArgument(newCount <= Integer.MAX_VALUE, "too many occurrences: %s", newCount); frequency.getAndAdd(occurrences); } size += occurrences; return oldCount; }
/** * {@inheritDoc} * * @throws IllegalArgumentException if the call would result in more than * {@link Integer#MAX_VALUE} occurrences of {@code element} in this * multiset. */ @Override public int add(@Nullable E element, int occurrences) { if (occurrences == 0) { return count(element); } checkArgument( occurrences > 0, "occurrences cannot be negative: %s", occurrences); Count frequency = backingMap.get(element); int oldCount; if (frequency == null) { oldCount = 0; backingMap.put(element, new Count(occurrences)); } else { oldCount = frequency.get(); long newCount = (long) oldCount + (long) occurrences; checkArgument(newCount <= Integer.MAX_VALUE, "too many occurrences: %s", newCount); frequency.getAndAdd(occurrences); } size += occurrences; return oldCount; }
/** * {@inheritDoc} * * @throws IllegalArgumentException if the call would result in more than * {@link Integer#MAX_VALUE} occurrences of {@code element} in this * multiset. */ @Override public int add(@Nullable E element, int occurrences) { if (occurrences == 0) { return count(element); } checkArgument( occurrences > 0, "occurrences cannot be negative: %s", occurrences); Count frequency = backingMap.get(element); int oldCount; if (frequency == null) { oldCount = 0; backingMap.put(element, new Count(occurrences)); } else { oldCount = frequency.get(); long newCount = (long) oldCount + (long) occurrences; checkArgument(newCount <= Integer.MAX_VALUE, "too many occurrences: %s", newCount); frequency.getAndAdd(occurrences); } size += occurrences; return oldCount; }
/** * {@inheritDoc} * * @throws IllegalArgumentException if the call would result in more than * {@link Integer#MAX_VALUE} occurrences of {@code element} in this * multiset. */ @Override public int add(@Nullable E element, int occurrences) { if (occurrences == 0) { return count(element); } checkArgument( occurrences > 0, "occurrences cannot be negative: %s", occurrences); Count frequency = backingMap.get(element); int oldCount; if (frequency == null) { oldCount = 0; backingMap.put(element, new Count(occurrences)); } else { oldCount = frequency.get(); long newCount = (long) oldCount + (long) occurrences; checkArgument(newCount <= Integer.MAX_VALUE, "too many occurrences: %s", newCount); frequency.getAndAdd(occurrences); } size += occurrences; return oldCount; }
/** * {@inheritDoc} * * @throws IllegalArgumentException if the call would result in more than * {@link Integer#MAX_VALUE} occurrences of {@code element} in this * multiset. */ @Override public int add(@Nullable E element, int occurrences) { if (occurrences == 0) { return count(element); } checkArgument( occurrences > 0, "occurrences cannot be negative: %s", occurrences); Count frequency = backingMap.get(element); int oldCount; if (frequency == null) { oldCount = 0; backingMap.put(element, new Count(occurrences)); } else { oldCount = frequency.get(); long newCount = (long) oldCount + (long) occurrences; checkArgument(newCount <= Integer.MAX_VALUE, "too many occurrences: %s", newCount); frequency.getAndAdd(occurrences); } size += occurrences; return oldCount; }
/** * {@inheritDoc} * * @throws IllegalArgumentException if the call would result in more than * {@link Integer#MAX_VALUE} occurrences of {@code element} in this * multiset. */ @Override public int add(@Nullable E element, int occurrences) { if (occurrences == 0) { return count(element); } checkArgument( occurrences > 0, "occurrences cannot be negative: %s", occurrences); Count frequency = backingMap.get(element); int oldCount; if (frequency == null) { oldCount = 0; backingMap.put(element, new Count(occurrences)); } else { oldCount = frequency.get(); long newCount = (long) oldCount + (long) occurrences; checkArgument(newCount <= Integer.MAX_VALUE, "too many occurrences: %s", newCount); frequency.getAndAdd(occurrences); } size += occurrences; return oldCount; }
/** * {@inheritDoc} * * @throws IllegalArgumentException if the call would result in more than * {@link Integer#MAX_VALUE} occurrences of {@code element} in this * multiset. */ @Override public int add(@Nullable E element, int occurrences) { if (occurrences == 0) { return count(element); } checkArgument( occurrences > 0, "occurrences cannot be negative: %s", occurrences); Count frequency = backingMap.get(element); int oldCount; if (frequency == null) { oldCount = 0; backingMap.put(element, new Count(occurrences)); } else { oldCount = frequency.get(); long newCount = (long) oldCount + (long) occurrences; checkArgument(newCount <= Integer.MAX_VALUE, "too many occurrences: %s", newCount); frequency.getAndAdd(occurrences); } size += occurrences; return oldCount; }
/** * {@inheritDoc} * * @throws IllegalArgumentException if the call would result in more than * {@link Integer#MAX_VALUE} occurrences of {@code element} in this * multiset. */ @Override public int add(@Nullable E element, int occurrences) { if (occurrences == 0) { return count(element); } checkArgument( occurrences > 0, "occurrences cannot be negative: %s", occurrences); Count frequency = backingMap.get(element); int oldCount; if (frequency == null) { oldCount = 0; backingMap.put(element, new Count(occurrences)); } else { oldCount = frequency.get(); long newCount = (long) oldCount + (long) occurrences; checkArgument(newCount <= Integer.MAX_VALUE, "too many occurrences: %s", newCount); frequency.getAndAdd(occurrences); } size += occurrences; return oldCount; }
/** * {@inheritDoc} * * @throws IllegalArgumentException if the call would result in more than * {@link Integer#MAX_VALUE} occurrences of {@code element} in this * multiset. */ @Override public int add(@Nullable E element, int occurrences) { if (occurrences == 0) { return count(element); } checkArgument( occurrences > 0, "occurrences cannot be negative: %s", occurrences); Count frequency = backingMap.get(element); int oldCount; if (frequency == null) { oldCount = 0; backingMap.put(element, new Count(occurrences)); } else { oldCount = frequency.get(); long newCount = (long) oldCount + (long) occurrences; checkArgument(newCount <= Integer.MAX_VALUE, "too many occurrences: %s", newCount); frequency.getAndAdd(occurrences); } size += occurrences; return oldCount; }