1
2
3
4
5
6 package org.weda;
7
8 import java.util.HashSet;
9 import java.util.Set;
10
11 /**
12 *
13 * @author Mikhail Titov
14 */
15 public final class Utils {
16 private Utils(){
17 }
18
19 public final static <T> Set<T> intersection(
20 Set<T> set1, Iterable<T> set2)
21 {
22 Set<T> res = null;
23 if (set1!=null && set2!=null){
24 for (T value: set2)
25 if (set1.contains(value)){
26 if (res==null)
27 res = new HashSet<T>();
28 res.add(value);
29 }
30 }
31 return res;
32 }
33
34 public final static <T> Set<T> toSet(Iterable<T> source){
35 Set<T> res = new HashSet<T>();
36 for (T value: source)
37 res.add(value);
38 return res;
39 }
40 }