From e793e62fc959811243e09c82e5de15c6c1d5a5d0 Mon Sep 17 00:00:00 2001 From: depristo Date: Mon, 30 Nov 2009 20:57:20 +0000 Subject: [PATCH] minor code cleanup git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@2189 348d0f76-0448-11de-a6fe-93d51630548a --- .../org/broadinstitute/sting/utils/Utils.java | 77 ------------------- 1 file changed, 77 deletions(-) diff --git a/java/src/org/broadinstitute/sting/utils/Utils.java b/java/src/org/broadinstitute/sting/utils/Utils.java index e41aa817d..e0f95c22a 100755 --- a/java/src/org/broadinstitute/sting/utils/Utils.java +++ b/java/src/org/broadinstitute/sting/utils/Utils.java @@ -94,83 +94,6 @@ public class Utils { return new SAMFileWriterFactory().makeSAMOrBAMWriter(header, presorted, new File(file)); } - /** - * Returns a new list built from those objects found in collection that satisfy the - * predicate ( i.e. pred.apply() is true for the objects in th eresulting list ). - * - * @param pred filtering condition ( objects, for which pred.apply() is true pass the filter ) - * @param c collection to filter (will not be modified) - * - * @return new list built from elements of passing the filter - * @see #filterInPlace(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) { - // if the predicate is true for the current element - if (pred.apply(obj)) { - // append it to the result list - filtered.add(obj); - } - } - return filtered; - } - - /** - * Removes from the collection all the elements that do not pass the filter (i.e. those elements, - * for which pred.apply() is false ). This is an in-place method - the argument is modified, and no new - * objects are created/copied. Collection's iterator (as returned by iterator()) must implement - * optional remove() interface method that allows multiple subsequent removals of elements from the - * underlying collection (this is the standard contract). This method - * works best for collections that support cheap, constant time - * object removal (such as LinkedList, HashSet etc.). It is also specifically designed to - * detect ArrayLists and use optimized strategy for them. However - * with other, custom lists that 1) do not inherit (are not instanceof) from ArrayList and 2) do not implement - * fast (constant time) remove() operation, the performance can degrade significantly (linear traversal times, - * e.g., linear removal ~ N^2). - * - * @param pred filtering condition (only elements, for which pred.apply() is true will be kept in the collection) - * @param c collection to filter (will be modified - should be mutable and should implement remove() ) - * - * @return reference to the same (modified) collection - * @see #filter(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 - // for ArrayLists - List list = (List) c; - int j = 0; // copy-to location - // perform one linear pass copying forward all elements that pass the filter, - // so that the head of the list is continuous sequence of such elements: - for (int i = 0; i < list.size(); i++) { - // if object passes, copy it forward and increment j (=copy-to location); - // otherwise keep the same copy-to location and move on to the next element - if (pred.apply(list.get(i))) list.set(j++, list.get(i)); - } - // j now points to first unused copy-to location; elements 0...j-1 pass the filter - list.subList(j, list.size()).clear(); // remove tail of the list - } -/* - // loop through all the elements in c - for (T obj : c) { - // if the predicate is false for the current element - if (! pred.apply(obj)) { - // remove that element from the collection - c.remove(obj); - } - } - */ - Iterator it = c.iterator(); - while (it.hasNext()) { - if (pred.apply(it.next())) continue; - it.remove(); - } - return c; - } - public static ArrayList subseq(char[] fullArray) { byte[] fullByteArray = new byte[fullArray.length]; StringUtil.charsToBytes(fullArray, 0, fullArray.length, fullByteArray, 0);