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

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

Introduction

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

Prototype

boolean contains(Object o);

Source Link

Document

Returns true if this collection contains the specified element.

Usage

From source file:de.dhke.projects.cutil.collections.BagUtil.java

public static <T> Bag<T> unionBags(final Bag<T> b0, final Bag<T> b1, final Bag<T> targetBag) {
    targetBag.clear();/*from  ww  w. j  av a  2s  . co m*/
    for (T item : b0) {
        final int count0 = b0.getCount(item);
        final int count1 = b1.getCount(item);
        targetBag.add(item, Math.max(count0, count1));
    }
    for (T item : b1) {
        if (!b0.contains(item)) {
            final int count1 = b1.getCount(item);
            targetBag.add(item, count1);
        }
    }
    return targetBag;
}

From source file:de.dhke.projects.cutil.collections.BagUtilTest.java

/**
 * Test of unionBags method, of class BagUtil.
 */// w  ww  . j  a  va 2 s .  c o m
@Test
public void testUnionBags() {
    System.out.println("unionBags");
    final Bag<String> b0 = new TreeBag<>(Arrays.asList("A", "B", "C"));
    final Bag<String> b1 = new TreeBag<>(Arrays.asList("A", "C"));

    final Bag<String> union = new TreeBag<>();
    BagUtil.unionBags(b0, b1, union);
    assertTrue(union.contains("A"));
    assertTrue(union.contains("B"));
    assertTrue(union.contains("C"));
    assertEquals(1, union.getCount("A"));
    assertEquals(1, union.getCount("B"));
    assertEquals(1, union.getCount("C"));
}

From source file:de.dhke.projects.cutil.collections.BagUtilTest.java

/**
 * Test of intersectBags method, of class BagUtil.
 *//*from w w w . j a  va 2s .co m*/
@Test
public void testIntersectBags() {
    System.out.println("intersectBags");
    final Bag<String> b0 = new TreeBag<>(Arrays.asList("A", "B", "C"));
    final Bag<String> b1 = new TreeBag<>(Arrays.asList("A", "C"));

    final Bag<String> intersection = new TreeBag<>();
    BagUtil.intersectBags(b0, b1, intersection);
    assertTrue(intersection.contains("A"));
    assertFalse(intersection.contains("B"));
    assertTrue(intersection.contains("C"));
    assertEquals(1, intersection.getCount("A"));
    assertEquals(0, intersection.getCount("B"));
    assertEquals(1, intersection.getCount("C"));
}