Java 类org.apache.commons.collections15.bag.HashBag 实例源码

项目:kdxplore    文件:BmsExcelImportCallable.java   
public void report(PrintStream ps) {

    ps.println("Collected " + plots.size() + " plots");

    Bag<String> plotTypeCounts = new HashBag<>();
    for (Plot plot : plots) {
        plotTypeCounts.add(plot.getPlotType());
    }

    ps.println("Found PlotTypes:");
    for (String plotType : plotTypeCounts.uniqueSet()) {
        ps.println("\t" + plotType + ": " + plotTypeCounts.getCount(plotType));
    }

    ps.println("Created " + traitByName.size() + " Traits");
    for (Trait trait : traitByName.values()) {
        ps.println("\t" + trait + " [id=" + trait.getTraitId() + "]");

    }

    ps.println("Created " + plotAttributeByName.size() + " Plot Attributes");
    for (PlotAttribute pa : plotAttributeByName.values()) {
        ps.println("\t" + pa);
    }

    ps.println("Created " + nPlotAttributeValues + " Plot Attribute Values");
    ps.println("Created " + nSamples + " Samples");

    if (! lineNumbersByMessage.isEmpty()) {
        ps.println("Warnings:");
        for (String msg : lineNumbersByMessage.keySet()) {
            Set<Integer> range = lineNumbersByMessage.get(msg);
            ps.println(range.size()+" times: " + msg);
        }
    }
}
项目:kdxplore    文件: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
        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();
}
项目:VarJ    文件:TestCollectionUtils.java   
public void testCardinality() {
    assertEquals(1, CollectionUtils.cardinality("a", collectionA));
    assertEquals(2, CollectionUtils.cardinality("b", collectionA));
    assertEquals(3, CollectionUtils.cardinality("c", collectionA));
    assertEquals(4, CollectionUtils.cardinality("d", collectionA));
    assertEquals(0, CollectionUtils.cardinality("e", collectionA));

    assertEquals(0, CollectionUtils.cardinality("a", collectionB));
    assertEquals(4, CollectionUtils.cardinality("b", collectionB));
    assertEquals(3, CollectionUtils.cardinality("c", collectionB));
    assertEquals(2, CollectionUtils.cardinality("d", collectionB));
    assertEquals(1, CollectionUtils.cardinality("e", collectionB));

    List<Number> numberList = new ArrayList<Number>();
    numberList.add(new Long(1));
    numberList.add(new Integer(1));
    assertEquals(1, CollectionUtils.cardinality(new Long(1), numberList));
    assertEquals(1, CollectionUtils.cardinality(new Integer(1), numberList));

    Set set = new HashSet();
    set.add("A");
    set.add("C");
    set.add("E");
    set.add("E");
    assertEquals(1, CollectionUtils.cardinality("A", set));
    assertEquals(0, CollectionUtils.cardinality("B", set));
    assertEquals(1, CollectionUtils.cardinality("C", set));
    assertEquals(0, CollectionUtils.cardinality("D", set));
    assertEquals(1, CollectionUtils.cardinality("E", set));

    Bag bag = new HashBag();
    bag.add("A", 3);
    bag.add("C");
    bag.add("E");
    bag.add("E");
    assertEquals(3, CollectionUtils.cardinality("A", bag));
    assertEquals(0, CollectionUtils.cardinality("B", bag));
    assertEquals(1, CollectionUtils.cardinality("C", bag));
    assertEquals(0, CollectionUtils.cardinality("D", bag));
    assertEquals(2, CollectionUtils.cardinality("E", bag));
}