/* A wrapper for some common sorting/searching/filtering methods etc, mostly using java.util.Collections */ public static class TransactionUtils { public static final int ASCENDING = 1; public static final int DESCENDING = -1; //pass in a List of Transactions and it returns a List of Map.Entrys mapping the unique subject name --> num times found in Transactions /*public static ArrayList countDeweyBooksPerDay(ArrayList transactions, int k) { Map deweyBooksPerDay = new HashMap(); //t.deweyClass & t.ckidate for (int i = 0; i < transactions.size(); i++) { Transaction t = (Transaction) transactions.get(i); Integer cnt = (Integer) deweyBooksPerDay.get(t.ckidate); if (cnt == null) { uniqueLettersToCount.put(t.ckidate, new Integer(1)); } else { uniqueLettersToCount.put(t.ckidate, new Integer(cnt + 1)); } } return new ArrayList(uniqueLettersToCount.entrySet()); }*/ // // public static String getStringKeyForEntry(Object o) // { // Map.Entry me = (Map.Entry) o; // return (String) me.getKey(); // } // // public static int getIntValueForEntry(Object o) // { // Map.Entry me = (Map.Entry) o; // return ((Integer) me.getValue()).intValue(); // } // // //sort a list of Map.Entrys by their value. This assumes that the value is an Integer! // //order = 1 for Ascending, order = -1 for descending. // public static void sortUniqueLetterCountsByLetter(ArrayList entryList, final int order) // { // Collections.sort(entryList, new Comparator() // { // public int compare(Object o1, Object o2) // { // Map.Entry me1 = (Map.Entry) o1; // Map.Entry me2 = (Map.Entry) o2; // // return (((Character)me1.getKey()) - ((Character)me2.getKey())) * order; // } // } // ); // } //sort a List of transactions by the title public static void sortTransactionsByWeather(ArrayList transactions) { Collections.sort(transactions, new Comparator() { public int compare(Object o1, Object o2) { WetDay t1 = (WetDay) o1; WetDay t2 = (WetDay) o2; return t1.precip.compareTo(t2.precip); } } ); } //reverse order of List /*public static void reverse(ArrayList transactions) { Collections.reverse(transactions); } public static void filterOutNonAlphabeticalTitles(ArrayList transactions) { for (int i = transactions.size() - 1; i >= 0; i--) { Transaction t = (Transaction) transactions.get(i); if (t.title.length() < 1) { transactions.remove(t); continue; } char firstLetter = t.title.charAt(0); if (! ((firstLetter >= 'a' && firstLetter <= 'z') || (firstLetter >= 'A' && firstLetter <= 'Z')) ) { transactions.remove(t); continue; } } }*/ }