Example usage for org.apache.commons.collections CollectionUtils getCardinalityMap

List of usage examples for org.apache.commons.collections CollectionUtils getCardinalityMap

Introduction

In this page you can find the example usage for org.apache.commons.collections CollectionUtils getCardinalityMap.

Prototype

public static Map getCardinalityMap(final Collection coll) 

Source Link

Document

Returns a Map mapping each unique element in the given Collection to an Integer representing the number of occurrences of that element in the Collection .

Usage

From source file:gov.nih.nci.eagle.web.reports.EpiReportBean.java

public String getRelativesWhoSmoked() {
    String rel = "";
    List<String> extypes = new ArrayList<String>();
    for (Relative r : studyParticipant.getEpidemiologicalFinding().getRelativeCollection()) {
        if (r.getSmokingStatus().equals("1")) {
            extypes.add(r.getRelationshipType());
        }//from www  .  j  a  v a  2  s. co  m
    }

    Map<String, Integer> m = CollectionUtils.getCardinalityMap(extypes);
    for (String s : m.keySet()) {
        rel += " " + s;
        if (m.get(s) > 1) {
            rel += "(" + m.get(s) + ") ";
        }
    }
    //       rel = StringUtils.join(extypes.toArray(), " ");

    return (!rel.equals("")) ? rel : "-";
}

From source file:gov.nih.nci.eagle.web.reports.EpiReportBean.java

public String getEtsExposure() {
    String ets = "";
    List<String> extypes = new ArrayList<String>();
    for (EnvironmentalFactor ef : studyParticipant.getEpidemiologicalFinding()
            .getEnvironmentalFactorCollection()) {
        extypes.add(ef.getExposureType());
    }//ww  w.j a v a2 s .c o  m

    //      int hit = StringUtils.countMatches(ets, ef.getExposureType());
    Map<String, Integer> m = CollectionUtils.getCardinalityMap(extypes);
    for (String s : m.keySet()) {

        ets += " " + s;
        if (m.get(s) > 1) {
            ets += "(" + m.get(s) + ") ";
        }
    }
    return (!ets.equals("")) ? ets : "-";
}

From source file:com.nomsic.sid.Sid.java

/**
 * //from w w  w  . jav  a 2 s  .  c o m
 * @param thresholdSq
 * @return
 * @throws IOException
 */
public List<Match> getMatches(final double thresholdSq) throws IOException {

    if (recordSets == null) {
        Preconditions.checkNotNull(recordFile);
        FieldRecordProcessor processor = new FieldRecordProcessor();
        processor.setIgnoreFirstLine(ignoreFirstLine);
        recordSets = Files.readLines(recordFile, Charset.defaultCharset(), processor);
    }

    @SuppressWarnings("unchecked")
    Map<SortedSet<String>, Integer> recordSetCardinalityMap = CollectionUtils.getCardinalityMap(recordSets);

    buildRecordSimsetMap(recordSetCardinalityMap);
    buildRecordFieldCountMap();

    Set<Match> matches = computeMatches();
    matches = Sets.filter(matches, new Predicate<Match>() {
        @Override
        public boolean apply(Match m) {
            return m.getSimilarityIndex() > thresholdSq;
        }
    });
    ArrayList<Match> matchList = Lists.newArrayList();
    matchList.addAll(matches);
    Collections.sort(matchList, new Comparator<Match>() {
        @Override
        public int compare(Match o1, Match o2) {
            return o2.getSimilarityIndex().compareTo(o1.getSimilarityIndex());
        }
    });
    return matchList;
}