From d13072adc38e13fdf8800cbf27816628dd9eb6ca Mon Sep 17 00:00:00 2001 From: Deipher Date: Tue, 28 Oct 2014 09:01:14 +0100 Subject: [PATCH] Replaces ArrayList by HashSet to increase the performance The removeAll() will use the contain method. HashSet has a more efficient implementation of contains than ArrayList. --- src/main/java/de/danielbechler/util/Collections.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main/java/de/danielbechler/util/Collections.java b/src/main/java/de/danielbechler/util/Collections.java index b34666fe..b1141962 100644 --- a/src/main/java/de/danielbechler/util/Collections.java +++ b/src/main/java/de/danielbechler/util/Collections.java @@ -88,18 +88,20 @@ public static int indexOf(final Iterable haystack, final T need public static Collection filteredCopyOf(final Collection source, final Collection filter) { + // Patched : Replaces collection and arrayList by HashSet to improve the removeAll performance using the + // implementation of contains() of the hashset final Collection copy; if (source != null) { - copy = new LinkedList(source); + copy = new HashSet(source); } else { - copy = new LinkedList(); + copy = new HashSet(); } if (filter != null) { - copy.removeAll(new ArrayList(filter)); + copy.removeAll(new HashSet(filter)); } return copy; }