Stuart McCulloch | bb01437 | 2012-06-07 21:57:32 +0000 | [diff] [blame] | 1 | package aQute.lib.collections; |
| 2 | |
| 3 | import java.util.*; |
| 4 | |
| 5 | public class Logic { |
Stuart McCulloch | 2286f23 | 2012-06-15 13:27:53 +0000 | [diff] [blame^] | 6 | |
| 7 | public static <T> Collection<T> retain(Collection<T> first, Collection<T>... sets) { |
Stuart McCulloch | bb01437 | 2012-06-07 21:57:32 +0000 | [diff] [blame] | 8 | Set<T> result = new HashSet<T>(first); |
Stuart McCulloch | 2286f23 | 2012-06-15 13:27:53 +0000 | [diff] [blame^] | 9 | for (Collection<T> set : sets) { |
Stuart McCulloch | bb01437 | 2012-06-07 21:57:32 +0000 | [diff] [blame] | 10 | result.retainAll(set); |
| 11 | } |
| 12 | return result; |
| 13 | } |
Stuart McCulloch | 2286f23 | 2012-06-15 13:27:53 +0000 | [diff] [blame^] | 14 | |
| 15 | public static <T> Collection<T> remove(Collection<T> first, Collection<T>... sets) { |
Stuart McCulloch | bb01437 | 2012-06-07 21:57:32 +0000 | [diff] [blame] | 16 | Set<T> result = new HashSet<T>(first); |
Stuart McCulloch | 2286f23 | 2012-06-15 13:27:53 +0000 | [diff] [blame^] | 17 | for (Collection<T> set : sets) { |
Stuart McCulloch | bb01437 | 2012-06-07 21:57:32 +0000 | [diff] [blame] | 18 | result.removeAll(set); |
| 19 | } |
| 20 | return result; |
| 21 | } |
| 22 | } |