List of usage examples for com.google.common.collect ImmutableMultiset iterator
@Override
public UnmodifiableIterator<E> iterator()
From source file:de.topobyte.osm4j.utils.executables.OsmContributorHistogram.java
private void run() throws IOException { long total = 0; OsmIterator iterator = createIterator(); while (iterator.hasNext()) { EntityContainer entityContainer = iterator.next(); OsmEntity entity = entityContainer.getEntity(); OsmMetadata metadata = entity.getMetadata(); total++;/*from w ww .j a v a 2s. co m*/ if (metadata == null) { continue; } long uid = metadata.getUid(); String username = metadata.getUser(); counter.add(uid); if (!map.containsEntry(uid, username)) { map.put(uid, username); } } if (counter.isEmpty()) { System.out.println("No metadata found"); return; } long sum = 0; ImmutableMultiset<Long> histogram = Multisets.copyHighestCountFirst(counter); long first = histogram.iterator().next(); int firstCount = histogram.count(first); int firstLength = String.format("%d", firstCount).length(); String pattern = String.format("[%%6.2f%%%%] %%%dd: %%d (%%s)", firstLength); for (long id : histogram.elementSet()) { int count = histogram.count(id); sum += count; double done = sum / (double) total; List<String> names = new ArrayList<>(map.get(id)); Collections.sort(names); System.out.println(String.format(pattern, done * 100, count, id, Joiner.on(",").join(names))); } finish(); }