Example usage for java.util SortedMap get

List of usage examples for java.util SortedMap get

Introduction

In this page you can find the example usage for java.util SortedMap get.

Prototype

V get(Object key);

Source Link

Document

Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.

Usage

From source file:com.aurel.track.fieldType.bulkSetters.CompositeSelectBulkSetter.java

/**
 * The JSON configuration object for configuring the js control(s) containing the value
 * @param baseName: the name of the control: important by submit
 * @param value: the value to be set by rendering (first time or after a submit)
 * @param dataSource: defined only for lists (list for global lists, map for context dependent lists)
 * @param labelMap: defined only for context (project/issuType) dependent lists
 * @param disabled: whether the control is disabled
 * @param locale//from   w ww. j  a v a  2 s.c o m
 * @return
 */
public String getJsonValuesForList(String baseName, String baseItemID, Object value, Object dataSource,
        Integer listID) {
    Integer fieldID = getFieldID();
    StringBuilder stringBuilder = new StringBuilder();
    CustomCompositeBaseRT compositeBaseRT = (CustomCompositeBaseRT) FieldTypeManager.getFieldTypeRT(fieldID);
    if (compositeBaseRT != null) {
        Map<Integer, SortedMap<Integer, List<ILabelBean>>> dataSourceMap = (Map<Integer, SortedMap<Integer, List<ILabelBean>>>) dataSource;
        if (dataSourceMap != null) {
            Map<Integer, SortedMap<Integer, Integer[]>> valueMap = (Map<Integer, SortedMap<Integer, Integer[]>>) value;
            stringBuilder.append("[");
            SortedMap<Integer, List<ILabelBean>> compositeListDataSource = dataSourceMap.get(listID);
            if (compositeListDataSource != null) {
                SortedMap<Integer, Integer[]> compositeListValue = null;
                if (valueMap != null) {
                    compositeListValue = valueMap.get(listID);
                }
                for (Iterator<Integer> itrPart = compositeListDataSource.keySet().iterator(); itrPart
                        .hasNext();) {
                    Integer parameterCode = itrPart.next();
                    List<ILabelBean> partDataSource = compositeListDataSource.get(parameterCode);
                    stringBuilder.append("{");
                    JSONUtility.appendStringValue(stringBuilder, JSONUtility.JSON_FIELDS.NAME,
                            getNameWithMergedKey(baseName, fieldID, listID, parameterCode));
                    JSONUtility.appendStringValue(stringBuilder, JSONUtility.JSON_FIELDS.ITEMID,
                            getItemIdWithMergedKey(baseItemID, fieldID, listID, parameterCode));
                    JSONUtility.appendILabelBeanList(stringBuilder, JSONUtility.JSON_FIELDS.DATA_SOURCE,
                            partDataSource);
                    Integer[] listValues = null;
                    Integer listValue = null;
                    if (compositeListValue != null) {
                        listValues = compositeListValue.get(parameterCode);
                        if (listValues != null && listValues.length > 0) {
                            listValue = listValues[0];
                        }
                    }
                    if (listValue == null) {
                        if (partDataSource != null && !partDataSource.isEmpty()) {
                            listValue = partDataSource.get(0).getObjectID();
                        }
                    }
                    if (listValue != null) {
                        JSONUtility.appendIntegerValue(stringBuilder, JSONUtility.JSON_FIELDS.VALUE, listValue,
                                true);
                    }
                    stringBuilder.append("}");
                    if (itrPart.hasNext()) {
                        stringBuilder.append(",");
                    }
                }
            }
            stringBuilder.append("]");
        }
    }
    return stringBuilder.toString();
}

From source file:com.aurel.track.fieldType.runtime.custom.select.CustomDependentSelectRT.java

/**
 * Loads the datasource for the mass operation
 * used mainly by select fields to get /*w w  w.j  a v  a  2s .co m*/
 * the all possible options for a field (system or custom select) 
 * It also sets a value if not yet selected
 * The value can be a List for simple select or a Map of lists for composite selects  
 * @param massOperationContext
 * @param massOperationValue
 * @param parameterCode
 * @param personBean
 * @param locale
 * @return
 */
@Override
public void loadBulkOperationDataSource(MassOperationContext massOperationContext,
        MassOperationValue massOperationValue, Integer parameterCode, TPersonBean personBean, Locale locale) {
    Map<Integer, SortedMap<Integer, Integer[]>> actualValuesMap = null;
    try {
        actualValuesMap = (Map<Integer, SortedMap<Integer, Integer[]>>) massOperationValue.getValue();
    } catch (Exception e) {
        LOGGER.warn("ValueModified: converting the massOperationExpression values to map failed with "
                + e.getMessage());
        LOGGER.debug(ExceptionUtils.getStackTrace(e));
    }
    if (actualValuesMap == null || actualValuesMap.isEmpty()) {
        return;
    }
    Integer fieldID = massOperationValue.getFieldID();
    Map<Integer, Map<Integer, String>> fieldIDToListIDToLabels = massOperationContext
            .getFieldIDToListIDToLabels();
    if (fieldIDToListIDToLabels != null) {
        Map<Integer, String> listIDToLabelMap = fieldIDToListIDToLabels.get(fieldID);
        if (listIDToLabelMap != null) {
            for (Integer listID : listIDToLabelMap.keySet()) {
                SortedMap<Integer, Integer[]> actualValueMap = actualValuesMap.get(listID);
                Map<Integer, SortedMap<Integer, List<IBeanID>>> dataSourceMap = (Map<Integer, SortedMap<Integer, List<IBeanID>>>) massOperationValue
                        .getPossibleValues();
                SortedMap<Integer, List<IBeanID>> compositeDataSource = dataSourceMap.get(listID);
                Object actualParentValue = actualValueMap.get(parentID);
                Integer[] parentIntArr = null;
                Integer parentIntValue = null;
                try {
                    parentIntArr = (Integer[]) actualParentValue;
                    if (parentIntArr != null && parentIntArr.length > 0) {
                        parentIntValue = parentIntArr[0];
                    }
                } catch (Exception e) {
                    LOGGER.warn("Converting the parent value to Integer[] failed with " + e.getMessage());
                    LOGGER.debug(ExceptionUtils.getStackTrace(e));
                }
                List<IBeanID> possiblePartValues = null;
                if (parentIntValue != null) {
                    TOptionBean optionBean = OptionBL.loadByPrimaryKey(parentIntValue);
                    Integer parentListID = optionBean.getList();
                    //get the childNumber'th child list of the parentListID
                    TListBean childListBean = ListBL.getChildList(parentListID, childNumber);
                    if (childListBean != null) {
                        //TODO later filter first by configOptionRoleDAO.loadCreateOptionsByConfigForRoles(configID, person, project);
                        possiblePartValues = LocalizeUtil.localizeDropDownList(
                                optionDAO.loadCreateDataSourceByListAndParents(childListBean.getObjectID(),
                                        parentIntArr),
                                locale);
                    }
                    actualValueMap.put(parameterCode,
                            getBulkSelectValue(massOperationContext, massOperationValue.getFieldID(),
                                    parameterCode, actualValueMap.get(parameterCode), possiblePartValues));
                }
                if (possiblePartValues != null) {
                    compositeDataSource.put(parameterCode, possiblePartValues);
                }
            }
        }
    }
}

From source file:edu.umd.cfar.lamp.viper.util.Range.java

/**
 * Checks to see if some interval of this
 * intersects the specified interval.//from   w  w  w. ja  v a  2 s.  c om
 * @param s the interval to test against
 * @return <code>true</code> if there is some overlap
 */
public boolean intersects(Interval s) {
    if (this.isEmpty() || s.isEmpty()) {
        return false;
    }
    SortedMap m = spans.subMap(s.getStart(), s.getEnd());
    if (!m.isEmpty()) {
        return true;
    } else {
        m = spans.headMap(s.getStart());
        Interval last = (Interval) m.get(m.lastKey());
        return last.intersects(s);
    }
}

From source file:org.calrissian.accumulorecipes.commons.hadoop.GroupedKeyRangePartitioner.java

private synchronized Text[] getCutPoints() throws IOException {
    if (cutPointArray == null) {

        Path[] cf = DistributedCache.getLocalCacheFiles(conf);
        if (cf != null) {
            Map<String, String> curFilesAndGroups = getCurFilesAndGroups();
            SortedMap<String, SortedSet<String>> cutPointMap = new TreeMap<String, SortedSet<String>>();
            for (Path path : cf) {
                String group = null;
                for (Map.Entry<String, String> groupSplits : curFilesAndGroups.entrySet()) {
                    if (path.toString().endsWith(groupSplits.getKey()))
                        group = groupSplits.getValue();
                }//ww w  .  ja v a2  s  . c om

                if (group != null) {
                    Scanner in = new Scanner(new BufferedReader(new FileReader(path.toString())));

                    try {
                        while (in.hasNextLine()) {
                            String split = new String(Base64.decodeBase64(in.nextLine().getBytes()));

                            SortedSet<String> splits = cutPointMap.get(group);
                            if (splits == null) {
                                splits = new TreeSet<String>();
                                cutPointMap.put(group, splits);
                            }
                        }

                        SortedSet<Text> treeSet = new TreeSet<Text>();
                        for (Map.Entry<String, SortedSet<String>> entry : cutPointMap.entrySet()) {
                            treeSet.add(new Text(entry.getKey() + NULL_BYTE + NULL_BYTE));

                            for (String string : entry.getValue())
                                treeSet.add(new Text(entry.getKey() + NULL_BYTE + string));

                            treeSet.add(new Text(entry.getKey() + NULL_BYTE + END_BYTE));
                        }

                        cutPointArray = treeSet.toArray(new Text[] {});
                    } finally {
                        in.close();
                    }

                    break;
                } else {
                    throw new FileNotFoundException(
                            "A file was not found in distribution cache files: " + path.toString());
                }
            }
        }
    }
    return cutPointArray;
}

From source file:com.activecq.tools.errorpagehandler.impl.ErrorPageHandlerImpl.java

/**
 * Merge two Maps together. In the event of any key collisions the Master map wins
 *
 * Any blank value keys are dropped from the final Map
 *
 * Map is sorted by value (String) length
 *
 * @param master/*from   w ww  .j a  va  2s. c o  m*/
 * @param slave
 * @return
 */
private SortedMap<String, String> mergeMaps(SortedMap<String, String> master, SortedMap<String, String> slave) {
    SortedMap<String, String> map = new TreeMap<String, String>(new StringLengthComparator());

    for (final String key : master.keySet()) {
        if (StringUtils.isNotBlank(master.get(key))) {
            map.put(key, master.get(key));
        }
    }

    for (final String key : slave.keySet()) {
        if (master.containsKey(key)) {
            continue;
        }
        if (StringUtils.isNotBlank(slave.get(key))) {
            map.put(key, slave.get(key));
        }
    }

    return map;
}

From source file:edu.umd.cfar.lamp.viper.util.Range.java

/**
 * Gets the range shared by this and the specified 
 * range.//from   ww  w .  ja  va  2 s.  c  o  m
 * @param list the list to intersect with
 * @return the shared range
 */
public Range intersect(IntervalIndexList list) {
    // Note that each span in a range must
    // have a gap before it. this means it is 
    // ease enough to just follow the heuristic:
    // get span to add, advance to latest pointer,
    // get span to add.
    Range newRange = new Range();
    if (this.isEmpty() || list.isEmpty()) {
        return newRange;
    }
    SortedMap A = this.spans;
    Comparable aNextStart = (Comparable) A.firstKey();
    Comparable aNextEnd = (Comparable) A.get(aNextStart);
    Iterator B = list.iterator();
    if (!B.hasNext()) {
        return newRange;
    }
    Interval b = (Interval) B.next();
    if (b.isEmpty()) {
        throw new AssertionError();
    }
    Comparable bNextStart = b.getStart();
    Comparable bNextEnd = b.getEnd();

    while (aNextStart != null && bNextStart != null) {
        double diffStartStart = aNextStart.compareTo(bNextStart);
        double diffEndEnd = aNextEnd.compareTo(bNextEnd);
        if (diffStartStart == 0) {
            // both start at the same time
            if (diffEndEnd == 0) {
                newRange.add(aNextStart, aNextEnd);
                aNextStart = this.firstAfterOrAt(aNextEnd);
                aNextEnd = this.endOf(aNextStart);
                bNextStart = list.firstAfterOrAt(bNextEnd);
                bNextEnd = list.endOf(bNextStart);
            } else if (diffEndEnd < 0) {
                // a stops before b
                newRange.add(aNextStart, aNextEnd);
                aNextStart = this.firstAfterOrAt(aNextEnd);
                aNextEnd = this.endOf(aNextStart);
            } else {
                // b stops before a
                newRange.add(bNextStart, bNextEnd);
                bNextStart = list.firstAfterOrAt(bNextEnd);
                bNextEnd = list.endOf(bNextStart);
            }
        } else if (diffStartStart < 0) {
            // a starts before b
            double diffEndStart = aNextEnd.compareTo(bNextStart);
            if (diffEndStart <= 0) {
                // skip ahead, since there is no
                // chance of overlap here
                aNextStart = this.firstAfterOrAt(aNextEnd);
                aNextEnd = this.endOf(aNextStart);
            } else if (diffEndEnd == 0) {
                newRange.add(bNextStart, bNextEnd);
                aNextStart = this.firstAfterOrAt(aNextEnd);
                aNextEnd = this.endOf(aNextStart);
                bNextStart = list.firstAfterOrAt(bNextEnd);
                bNextEnd = list.endOf(bNextStart);
            } else if (diffEndEnd < 0) {
                // a ends before b does, but after b starts
                newRange.add(bNextStart, aNextEnd);
                aNextStart = this.firstAfterOrAt(aNextEnd);
                aNextEnd = this.endOf(aNextStart);
            } else {
                // a ends after b does
                newRange.add(bNextStart, bNextEnd);
                bNextStart = list.firstAfterOrAt(bNextEnd);
                bNextEnd = list.endOf(bNextStart);
            }
        } else {
            // a starts after b does
            double diffStartEnd = aNextStart.compareTo(bNextEnd);
            if (diffStartEnd >= 0) {
                // skip ahead, since there is no
                // chance of overlap here
                bNextStart = list.firstAfterOrAt(bNextEnd);
                bNextEnd = list.endOf(bNextStart);
            } else if (diffEndEnd == 0) {
                // both end at the same moment
                newRange.add(aNextStart, aNextEnd);
                aNextStart = this.firstAfterOrAt(aNextEnd);
                aNextEnd = this.endOf(aNextStart);
                bNextStart = list.firstAfterOrAt(bNextEnd);
                bNextEnd = list.endOf(bNextStart);
            } else if (diffEndEnd < 0) {
                // a is a subset of b
                newRange.add(aNextStart, aNextEnd);
                aNextStart = this.firstAfterOrAt(aNextEnd);
                aNextEnd = this.endOf(aNextStart);
            } else {
                // a ends after b does
                newRange.add(aNextStart, bNextEnd);
                bNextStart = list.firstAfterOrAt(bNextEnd);
                bNextEnd = list.endOf(bNextStart);
            }
        }
        if ((aNextStart != null && bNextStart != null) && (aNextEnd == null || bNextEnd == null)) {
            throw new AssertionError();
        }
    }
    return newRange;
}

From source file:org.optaplanner.benchmark.impl.result.PlannerBenchmarkResult.java

private List<List<SolverBenchmarkResult>> createSameRankingListList(BenchmarkReport benchmarkReport,
        List<SolverBenchmarkResult> rankableSolverBenchmarkResultList) {
    List<List<SolverBenchmarkResult>> sameRankingListList = new ArrayList<List<SolverBenchmarkResult>>(
            rankableSolverBenchmarkResultList.size());
    if (benchmarkReport.getSolverRankingComparator() != null) {
        Comparator<SolverBenchmarkResult> comparator = Collections
                .reverseOrder(benchmarkReport.getSolverRankingComparator());
        Collections.sort(rankableSolverBenchmarkResultList, comparator);
        List<SolverBenchmarkResult> sameRankingList = null;
        SolverBenchmarkResult previousSolverBenchmarkResult = null;
        for (SolverBenchmarkResult solverBenchmarkResult : rankableSolverBenchmarkResultList) {
            if (previousSolverBenchmarkResult == null
                    || comparator.compare(previousSolverBenchmarkResult, solverBenchmarkResult) != 0) {
                // New rank
                sameRankingList = new ArrayList<SolverBenchmarkResult>();
                sameRankingListList.add(sameRankingList);
            }/*from   w w w .ja va  2  s.c  om*/
            sameRankingList.add(solverBenchmarkResult);
            previousSolverBenchmarkResult = solverBenchmarkResult;
        }
    } else if (benchmarkReport.getSolverRankingWeightFactory() != null) {
        SortedMap<Comparable, List<SolverBenchmarkResult>> rankedMap = new TreeMap<Comparable, List<SolverBenchmarkResult>>(
                Collections.reverseOrder());
        for (SolverBenchmarkResult solverBenchmarkResult : rankableSolverBenchmarkResultList) {
            Comparable rankingWeight = benchmarkReport.getSolverRankingWeightFactory()
                    .createRankingWeight(rankableSolverBenchmarkResultList, solverBenchmarkResult);
            List<SolverBenchmarkResult> sameRankingList = rankedMap.get(rankingWeight);
            if (sameRankingList == null) {
                sameRankingList = new ArrayList<SolverBenchmarkResult>();
                rankedMap.put(rankingWeight, sameRankingList);
            }
            sameRankingList.add(solverBenchmarkResult);
        }
        for (Map.Entry<Comparable, List<SolverBenchmarkResult>> entry : rankedMap.entrySet()) {
            sameRankingListList.add(entry.getValue());
        }
    } else {
        throw new IllegalStateException("Ranking is impossible"
                + " because solverRankingComparator and solverRankingWeightFactory are null.");
    }
    return sameRankingListList;
}

From source file:com.aurel.track.report.dashboard.StatusOverTimeGraph.java

/**
 * Add the time series to the timeSeriesCollection
 * SortedMap at first and second level (year and period)
 * (Sorted because the accumulated should be calculated in the right order)
 *///from  w ww.  j  av a  2  s  .  c o  m
private static String generateAxesValues(
        SortedMap<Integer, SortedMap<Integer, Map<Integer, Integer>>> yearToPeriodToEntityIDToWorkItemNumbersMap,
        Map entityMap, int selectedTimeInterval, boolean accumulated, Set<String> stateNameOrder) {

    Map timeSeriesMap = new HashMap();
    Map accumulatedMap = new HashMap();
    StringBuilder sb = new StringBuilder();
    sb.append("[");
    Map<String, String> valuesMap;
    Iterator yearIterator = yearToPeriodToEntityIDToWorkItemNumbersMap.keySet().iterator();
    while (yearIterator.hasNext()) {
        Integer year = (Integer) yearIterator.next();
        SortedMap<Integer, Map<Integer, Integer>> intervalToStatusChangeBeans = yearToPeriodToEntityIDToWorkItemNumbersMap
                .get(year);
        Iterator periodIterator = intervalToStatusChangeBeans.keySet().iterator();
        while (periodIterator.hasNext()) {
            Integer period = (Integer) periodIterator.next();
            Map<Integer, Integer> entityIDToWorkItemNumbersMap = intervalToStatusChangeBeans.get(period);
            if (entityIDToWorkItemNumbersMap != null) {
                Iterator entityIDIterator = entityIDToWorkItemNumbersMap.keySet().iterator();
                sb.append("{");
                valuesMap = new HashMap<String, String>();
                JSONUtility.appendStringValue(sb, "date", createRegularTimePeriodForJSON(period.intValue(),
                        year.intValue(), selectedTimeInterval));
                while (entityIDIterator.hasNext()) {
                    Integer entityID = (Integer) entityIDIterator.next();
                    Integer numberOfStates = entityIDToWorkItemNumbersMap.get(entityID);
                    if (numberOfStates != null) {
                        String sb1 = (String) timeSeriesMap.get(entityID);
                        Integer accumuletedValueForEntity = (Integer) accumulatedMap.get(entityID);
                        String label = "";
                        if (sb1 == null) {
                            ILabelBean iLabelBean = null;
                            if (entityMap != null) {
                                iLabelBean = (ILabelBean) entityMap.get(entityID);
                            }

                            if (iLabelBean != null) {
                                label = iLabelBean.getLabel();
                            }
                            String axeValue = new String();
                            timeSeriesMap.put(entityID, axeValue);
                            accumulatedMap.put(entityID, Integer.valueOf(0));
                            accumuletedValueForEntity = (Integer) accumulatedMap.get(entityID);
                        }

                        Integer timeSeriesValue;
                        if (accumulated) {
                            accumulatedMap.put(entityID, Integer
                                    .valueOf(accumuletedValueForEntity.intValue() + numberOfStates.intValue()));
                            timeSeriesValue = (Integer) accumulatedMap.get(entityID);
                        } else {
                            timeSeriesValue = numberOfStates;
                        }
                        String status = "";
                        ILabelBean iLabelBeanJSON = null;
                        if (entityMap != null) {
                            iLabelBeanJSON = (ILabelBean) entityMap.get(entityID);
                        }
                        if (iLabelBeanJSON != null) {
                            status = iLabelBeanJSON.getLabel();
                        }
                        if (status.equals("")) {
                            status = "opened";
                        }
                        //                            JSONUtility.appendStringValue(sb, status, timeSeriesValue.toString(), true);
                        //                            sb.append(",");
                        valuesMap.put(status, timeSeriesValue.toString());
                        timeSeriesMap.put(entityID, sb.toString());
                    }
                }

                if (entityMap != null) {
                    for (String stateName : stateNameOrder) {
                        if (valuesMap.get(stateName) != null) {
                            JSONUtility.appendStringValue(sb, stateName, valuesMap.get(stateName), true);
                            sb.append(",");
                        }
                    }
                } else {
                    if (valuesMap.get("opened") != null) {
                        JSONUtility.appendStringValue(sb, "opened", valuesMap.get("opened"), true);
                        sb.append(",");
                    }
                }
                sb.deleteCharAt(sb.length() - 1);
                sb.append("},");
            }
        }
    }
    sb.deleteCharAt(sb.length() - 1);
    if (sb.length() != 0) {
        sb.append("]");
    } else {
        sb.append("[{}]");
    }
    return sb.toString();
}

From source file:org.lmnl.xml.XMLImportHandlerTest.java

@Test
public void showTextContents() throws IOException {
    final String resource = "george-algabal-tei.xml";
    //final String resource = "homer-iliad-tei.xml";
    final Text source = source(resource);
    final Text document = document(resource);

    final int textLength = textRepository.length(document);
    assertTrue(textLength > 0);/*from www. j  a  v  a  2 s. c om*/

    if (LOG.isDebugEnabled()) {
        final SortedMap<String, Annotation> annotations = Maps.newTreeMap();
        for (Annotation annotation : annotationRepository.find(document)) {
            final Object data = annotation.getData();
            if (data == null || !Map.class.isAssignableFrom(data.getClass())) {
                LOG.debug(annotation + " has no attributes");
                continue;
            }
            @SuppressWarnings("unchecked")
            final Map<QName, String> attrs = (Map<QName, String>) data;
            final String nodePath = attrs.get(XMLParser.NODE_PATH_NAME);
            if (nodePath == null) {
                LOG.debug(annotation + " has no XML node path");
                continue;
            }
            if (annotations.containsKey(nodePath)) {
                LOG.debug(nodePath + " already assigned to " + annotations.get(nodePath));
            }
            annotations.put(nodePath, annotation);
        }
        for (Map.Entry<String, Annotation> annotation : annotations.entrySet()) {
            LOG.debug(annotation.getKey() + " ==> " + annotation.getValue());
        }

        if (LOG.isDebugEnabled()) {
            textRepository.read(document, new TextContentReader() {

                public void read(Reader content, int contentLength) throws IOException {
                    LOG.debug(CharStreams.toString(content));
                }
            });
        }

        final List<Range> textRanges = Lists.newArrayList();
        final List<Range> sourceRanges = Lists.newArrayList();

        for (Annotation offset : annotationRepository.find(document, OFFSET_DELTA_NAME)) {
            textRanges.add(offset.getRange());
            sourceRanges.add((Range) offset.getData());
        }

        final SortedMap<Range, String> texts = textRepository.bulkRead(document, Sets.newTreeSet(textRanges));
        final SortedMap<Range, String> sources = textRepository.bulkRead(source, Sets.newTreeSet(sourceRanges));

        final Iterator<Range> sourceRangesIt = sourceRanges.iterator();
        for (Range textRange : textRanges) {
            if (!sourceRangesIt.hasNext()) {
                break;
            }
            final Range sourceRange = sourceRangesIt.next();
            //LOG.debug(textRange + " ==> " + sourceRange);
            LOG.debug(texts.get(textRange) + " ==> " + sources.get(sourceRange));
        }
    }

}

From source file:eu.stratosphere.pact.runtime.hash.HashFunctionCollisionBenchmark.java

private void printStatistics() {
    for (int level = 0; level < maxLevel; level++) {
        int bucketCountInLevel = 0;

        SortedMap<Integer, Integer> levelMap = bucketSizesPerLevel.get(level);
        Iterator<Integer> bucketSizeIterator = levelMap.keySet().iterator();

        LOG.debug("Statistics for level: " + level);
        LOG.debug("----------------------------------------------");
        LOG.debug("");
        LOG.debug("Bucket Size |      Count");
        LOG.debug("------------------------");

        int i = 0;
        while (bucketSizeIterator.hasNext()) {
            int bucketSize = bucketSizeIterator.next();
            if (bucketSize != 0) {
                int countForBucketSize = levelMap.get(bucketSize);
                bucketCountInLevel += countForBucketSize;
                Formatter formatter = new Formatter();
                formatter.format(" %10d | %10d", bucketSize, countForBucketSize);

                if (levelMap.size() < 20 || i < 3 || i >= (levelMap.size() - 3)) {
                    LOG.debug(formatter.out());
                } else if (levelMap.size() / 2 == i) {
                    LOG.debug("         .. |         ..");
                    LOG.debug(formatter.out());
                    LOG.debug("         .. |         ..");
                }/*from  w  w  w  .  j ava 2  s .  c  o m*/
                i++;
                formatter.close();
            }
        }

        LOG.debug("");
        LOG.debug("Number of non-empty buckets in level: " + bucketCountInLevel);
        LOG.debug("Number of empty buckets in level    : " + levelMap.get(0));
        LOG.debug("Number of different bucket sizes    : " + (levelMap.size() - 1));
        LOG.debug("");
        LOG.debug("");
        LOG.debug("");
    }
}