1 19 20 25 26 package edu.umd.cs.findbugs.gui; 27 28 import java.util.Collection ; 29 import java.util.Comparator ; 30 import java.util.Iterator ; 31 32 39 public class Grouper <ElementType> { 40 41 public interface Callback <ElementType2> { 42 public void startGroup(ElementType2 firstMember); 43 44 public void addToGroup(ElementType2 member); 45 } 46 47 private Callback<ElementType> callback; 48 49 54 public Grouper(Callback<ElementType> callback) { 55 this.callback = callback; 56 } 57 58 66 public void group(Collection <ElementType> collection, Comparator <ElementType> comparator) { 67 Iterator <ElementType> i = collection.iterator(); 68 ElementType last = null; 69 while (i.hasNext()) { 70 ElementType current = i.next(); 71 if (last != null && comparator.compare(last, current) == 0) { 72 callback.addToGroup(current); 74 } else { 75 callback.startGroup(current); 77 } 78 79 last = current; 80 } 81 } 82 83 } 84 | Popular Tags |