diff --git a/java/src/org/broadinstitute/sting/utils/Utils.java b/java/src/org/broadinstitute/sting/utils/Utils.java index 90d9eea1c..f5dee2171 100755 --- a/java/src/org/broadinstitute/sting/utils/Utils.java +++ b/java/src/org/broadinstitute/sting/utils/Utils.java @@ -53,7 +53,7 @@ public class Utils { * @return new list built from elements of passing the filter * @see #filterInPlace(Predicate pred, Collection c) */ - public static List filter(Predicate pred, Collection c) { + public static List filter(Predicate pred, Collection c) { List filtered = new ArrayList(); // loop through all the elements in c for (T obj : c) { @@ -84,7 +84,7 @@ public class Utils { * @return reference to the same (modified) collection * @see #filter(Predicate pred, Collection c) */ - public static Collection filterInPlace(Predicate pred, Collection c) { + public static Collection filterInPlace(Predicate pred, Collection c) { if (c instanceof ArrayList) { // arraylists are a special case that we know how to process efficiently // (generic implementation below removes one element at a time and is not well suited @@ -237,15 +237,15 @@ public class Utils { // Java Generics can't do primitive types, so I had to do this the simplistic way public static Integer[] SortPermutation(final int[] A) { - class comparator implements Comparator { - public int compare(Object a, Object b) { - if (A[(Integer) a] < A[(Integer) b]) { + class comparator implements Comparator { + public int compare(Integer a, Integer b) { + if (A[a.intValue()] < A[b.intValue()]) { return -1; } - if (A[(Integer) a] == A[(Integer) b]) { + if (A[a.intValue()] == A[b.intValue()]) { return 0; } - if (A[(Integer) a] > A[(Integer) b]) { + if (A[a.intValue()] > A[b.intValue()]) { return 1; } return 0; @@ -260,15 +260,15 @@ public class Utils { } public static Integer[] SortPermutation(final double[] A) { - class comparator implements Comparator { - public int compare(Object a, Object b) { - if (A[(Integer) a] < A[(Integer) b]) { + class comparator implements Comparator { + public int compare(Integer a, Integer b) { + if (A[a.intValue()] < A[ b.intValue() ]) { return -1; } - if (A[(Integer) a] == A[(Integer) b]) { + if (A[ a.intValue() ] == A[ b.intValue() ]) { return 0; } - if (A[(Integer) a] > A[(Integer) b]) { + if (A[ a.intValue() ] > A[ b.intValue() ]) { return 1; } return 0; @@ -350,7 +350,12 @@ public class Utils { return ans; } -/* TEST ME + + public static double percentage(double x, double base) { return (base> 0 ? (x/base)*100.0 : 0); } + public static double percentage(int x, int base) { return (base> 0 ? ((double)x/(double)base)*100.0 : 0); } + public static double percentage(long x, long base) { return (base> 0 ? ((double)x/(double)base)*100.0 : 0); } + + /* TEST ME public static void main(String[] argv) { List l1 = new LinkedList(); List l2 = new ArrayList();