public SparseHistogram getSparseHistogram (HistogramDefinition def) { if (def == null) { throw new IllegalArgumentException("No target definition"); } if (def.equals(getHistogramDefinition())) { return this; } Map<Integer,MutableDouble> binCountsMap=translate(def); if (MapUtil.size(binCountsMap) <= 0) { return new SparseHistogram(def, null); } List<IndexedBin> resBins=new ArrayList<IndexedBin>(binCountsMap.size()); for (Map.Entry<Integer,MutableDouble> binEntry : binCountsMap.entrySet()) { Integer binNumber=binEntry.getKey(); MutableDouble binValue=binEntry.getValue(); long binCount=Math.round(binValue.get()); if (binCount == 0L) { continue; } resBins.add(new IndexedBin(binNumber.intValue(), binCount)); } Collections.sort(resBins); return new SparseHistogram(def, resBins); }