package sandbox.changeset; import java.io.File; import java.io.PrintStream; import java.util.ArrayList; import java.util.Arrays; import java.util.EnumMap; import java.util.List; import java.util.Map; import java.util.Set; public class ChangeSet{ private final String[] keyList; private final Status[] statusList; private final EnumMap> byStatus; public ChangeSet(Map change_set){ keyList = change_set.keySet().toArray(new String[]{}); Arrays.sort(keyList); statusList = new Status[keyList.length]; byStatus = new EnumMap>(Status.class); for(Status s : Status.values()) byStatus.put(s, new ArrayList(keyList.length)); for (int i = 0; i < keyList.length; i++) { statusList[i] = change_set.get(keyList[i]); keyList[i] = toClassName(keyList[i]); byStatus.get(statusList[i]).add(keyList[i]); } } @Override public String toString() { // TODO Auto-generated method stub return super.toString(); } public void printTo(PrintStream out,Status... order){ for(Status s : order){ for(String id : byStatus.get(s)){ out.print(s); out.print(" "); out.println(id); } } out.format("# %d changed, %d new, %d old, %d same, (total: %d)\n", byStatus.get(Status.CHANGED).size(), byStatus.get(Status.NEW).size(), byStatus.get(Status.OLD).size(), byStatus.get(Status.SAME).size(), keyList.length ); } public List getClasses(Set status_filter){ ArrayList ret = new ArrayList(keyList.length); for(Status s:status_filter){ ret.addAll(byStatus.get(s)); } return ret; } private String toClassName(final String s){ //".class".length() == 6 return s.substring(0, s.length()-6).replace(File.separatorChar, '.'); } }