Example usage for org.apache.commons.math3.stat Frequency entrySetIterator

List of usage examples for org.apache.commons.math3.stat Frequency entrySetIterator

Introduction

In this page you can find the example usage for org.apache.commons.math3.stat Frequency entrySetIterator.

Prototype

public Iterator<Map.Entry<Comparable<?>, Long>> entrySetIterator() 

Source Link

Document

Return an Iterator over the set of keys and values that have been added.

Usage

From source file:de.upb.wdqa.wdvd.processors.statistics.FrequencyUtils.java

public static List<Map.Entry<Comparable<?>, Long>> sortByFrequency(Frequency frequency) {
    Iterator<Map.Entry<Comparable<?>, Long>> iterator = frequency.entrySetIterator();

    List<Map.Entry<Comparable<?>, Long>> list = new ArrayList<Map.Entry<Comparable<?>, Long>>();

    while (iterator.hasNext()) {
        Map.Entry<Comparable<?>, Long> entry = iterator.next();

        list.add(entry);//from  ww w.j  a va  2s  .c  o m
    }

    Comparator<Map.Entry<Comparable<?>, Long>> comparator = new Comparator<Map.Entry<Comparable<?>, Long>>() {

        @Override
        public int compare(Map.Entry<Comparable<?>, Long> arg0, Map.Entry<Comparable<?>, Long> arg1) {
            if (arg0 == null || arg1 == null) {
                throw new NullPointerException();
            }

            return -Long.compare(arg0.getValue(), arg1.getValue());
        }
    };

    Collections.sort(list, comparator);

    return list;
}

From source file:com.graphhopper.jsprit.core.util.UnassignedJobReasonTracker.java

private String getMostLikely(Frequency reasons) {
    Iterator<Map.Entry<Comparable<?>, Long>> entryIterator = reasons.entrySetIterator();
    int maxCount = 0;
    String mostLikely = null;//  w  w  w.jav  a 2s . co m
    while (entryIterator.hasNext()) {
        Map.Entry<Comparable<?>, Long> entry = entryIterator.next();
        if (entry.getValue() > maxCount) {
            Comparable<?> key = entry.getKey();
            mostLikely = key.toString();
        }
    }
    return mostLikely;
}

From source file:com.graphhopper.jsprit.core.util.UnassignedJobReasonTrackerTest.java

@Test
public void testFreq() {
    Frequency frequency = new Frequency();
    frequency.addValue("VehicleDependentTimeWindowHardActivityConstraint");
    frequency.addValue("b");
    frequency.addValue("VehicleDependentTimeWindowHardActivityConstraint");

    Iterator<Map.Entry<Comparable<?>, Long>> entryIterator = frequency.entrySetIterator();
    while (entryIterator.hasNext()) {
        Map.Entry<Comparable<?>, Long> e = entryIterator.next();
        System.out.println(e.getKey().toString() + " " + e.getValue());
    }/*from  www. ja  v a  2  s .c  om*/
}