Example usage for org.apache.commons.collections15 Bag remove

List of usage examples for org.apache.commons.collections15 Bag remove

Introduction

In this page you can find the example usage for org.apache.commons.collections15 Bag remove.

Prototype

boolean remove(E object, int nCopies);

Source Link

Document

Removes nCopies copies of the specified object from the Bag.

Usage

From source file:mulavito.utils.BagUtil.java

/**
 * Set the counter of the given entry in the given set.
 * // w  ww  .  j  a va  2 s .c o  m
 * @param bag
 *            The bag to modify
 * @param entry
 *            The entry whose counter is set
 * @param count
 *            The new non-negative counter value
 */
public static <T> void setCount(Bag<T> bag, T entry, int count) {
    if (bag == null)
        throw new IllegalArgumentException();
    else if (count < 0)
        throw new IllegalArgumentException();

    int oldCount = bag.getCount(entry);

    if (count > oldCount)
        bag.add(entry, count - oldCount);
    else if (count < oldCount)
        bag.remove(entry, oldCount - count);
}