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

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

Introduction

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

Prototype

int size();

Source Link

Document

Returns the total number of items in the bag across all types.

Usage

From source file:de.dhke.projects.cutil.collections.aspect.AspectMultiMapValueCollectionTest.java

/**
 * Test of iterator method, of class AspectMultiMapValueCollection.
 *//*ww w.  j av a 2  s  .  co m*/
@Test
public void testIterator() {
    _aspectMap.put("_", "a");
    Bag<String> values = new HashBag<>();
    Iterator<String> iter = _values.iterator();
    while (iter.hasNext())
        values.add(iter.next());
    assertEquals(2, values.getCount("a"));
    assertEquals(1, values.getCount("A"));
    assertEquals(1, values.getCount("b"));
    assertEquals(1, values.getCount("B"));
    assertEquals(1, values.getCount("c"));
    assertEquals(1, values.getCount("C"));
    assertEquals(0, values.getCount("d"));
    assertEquals(0, values.getCount("D"));
    assertEquals(_values.size(), values.size());
}

From source file:com.diversityarrays.kdxplore.trials.SampleGroupViewer.java

private String getBriefSummary(SampleGroup sampleGroup) throws IOException {
    Bag<Integer> plotIdsWithSpecimens = new HashBag<>();
    Set<Integer> plotIdsWithScores = new HashSet<>();
    int[] results = new int[3];
    java.util.function.Predicate<KdxSample> visitor = new java.util.function.Predicate<KdxSample>() {
        @Override/*from   w w w. j av a  2 s .  c  o  m*/
        public boolean test(KdxSample s) {
            plotIdsWithScores.add(s.getPlotId());
            int snum = s.getSpecimenNumber();
            if (snum <= 0) {
                ++results[0]; // Plot level sample count
            } else {
                ++results[1]; // Individual level sample count
                plotIdsWithSpecimens.add(s.getPlotId());
                results[2] = Math.max(results[2], snum); // maximum specimen number
            }
            return true;
        }
    };

    boolean scored = true;
    kdxdb.visitKdxSamplesForSampleGroup(sampleGroup, KdxploreDatabase.SampleLevel.BOTH, scored, visitor);

    int nPlotSamples = results[0];
    int nSpecimenSamples = results[1];
    int totalScoredSamples = nPlotSamples + nSpecimenSamples;

    int maxSpecimenNumber = results[2];

    int nPlotsWithSpecimens = plotIdsWithSpecimens.size();
    int nPlotsWithScores = plotIdsWithScores.size();

    int maxCount = 0;
    for (Integer plotId : plotIdsWithSpecimens.uniqueSet()) {
        int count = plotIdsWithSpecimens.getCount(plotId);
        maxCount = Math.max(maxCount, count);
    }

    StringBuilder sb = new StringBuilder("<HTML>");

    sb.append("<br><B>Scored Samples:</b> ").append(totalScoredSamples);
    sb.append("<br><B>Plot Level Samples:</b> ").append(nPlotSamples);
    sb.append("<br><B>Individual Samples:</b> ").append(nSpecimenSamples);
    sb.append("<br>");
    sb.append("<br><B>Max Individual number:</b> ").append(maxSpecimenNumber);
    sb.append("<br><B># Plots with Individuals:</b> ").append(nPlotsWithSpecimens);
    sb.append("<br>");
    sb.append("<br><B># Plots with scored samples:</b> ").append(nPlotsWithScores);
    sb.append("<br><B>Max # individual scores per plot:</b> ").append(maxCount);

    return sb.toString();
}

From source file:org.o3project.odenos.component.federator.FederatorBoundaryTableTest.java

/**
 * Test method for {@link org.o3project.odenos.component.federator.FederatorBoundaryTable#FederatorBoundaryTable()}.
 *//*from   w ww. ja v a2  s  .  c  om*/
@Test
public void testFederatorBoundaryTable() {

    /*
     * test
     */
    FederatorBoundaryTable result = new FederatorBoundaryTable();

    /*
     * check
     */
    assertThat(result, is(notNullValue()));

    Map<String, FederatorBoundary> boundaries = Whitebox.getInternalState(target, "boundaries");
    assertThat(boundaries.size(), is(0));

    Bag<BoundaryPort> boundaryPorts = Whitebox.getInternalState(target, "boundaryPorts");
    assertThat(boundaryPorts.size(), is(0));

}