List of usage examples for java.util Set contains
boolean contains(Object o);
From source file:Main.java
final static private boolean _already_logged(String message) { String today = _logged_fmt.format(Calendar.getInstance().getTime()); if (!_logged_msgs.containsKey(today)) { _logged_msgs.clear();/*from w w w . j a va 2 s .c om*/ _logged_msgs.put(today, new HashSet<String>()); } Set<String> msgs = _logged_msgs.get(today); if (msgs != null && msgs.contains(message)) { return true; } if (msgs != null) { msgs.add(message); } return false; }
From source file:Main.java
public static <E> Collection<E> unique(Collection<? extends E> src, Collection<E> dest) { Set<E> set = new HashSet<>(); for (E element : src) { if (!set.contains(element)) { set.add(element);//from w w w . j ava 2 s . c om dest.add(element); } } set.clear(); return dest; }
From source file:Main.java
public static <T> Set<T> intersection(Set<T> setA, Set<T> setB) { Set<T> tmp = new TreeSet<T>(); for (T x : setA) if (setB.contains(x)) tmp.add(x);//from w w w.j a v a 2s .c o m return tmp; }
From source file:Main.java
public static <E> Set<E> intersect(Set<E> a, Set<E> b) { Set<E> intersect = new HashSet<>(); for (E entryA : a) { if (b.contains(entryA)) { intersect.add(entryA);/* ww w .j a v a 2 s .co m*/ } } for (E entryB : b) { if (a.contains(entryB)) { intersect.add(entryB); } } return intersect; }
From source file:Main.java
public static <T> Set<T> removeSorted(Set<T> set, T element) { final int size = set.size(); if (size == 0 || (size == 1 && set.contains(element))) { return ImmutableSet.of(); } else {//w ww .j av a2 s . c o m set.remove(element); } return set; }
From source file:SetUtils.java
public static boolean containsAny(Set a, Set b) { for (Iterator iter = b.iterator(); iter.hasNext();) { if (a.contains(iter.next())) { return true; }/*from www . j a v a2 s . c o m*/ } return false; }
From source file:Main.java
/** * @param sa a set/* w w w . ja v a 2s . c om*/ * @param sb anotehr set * @return the intersection of <code>sa</code> and <code>sb</code> */ public static <E> Set<E> intersection(Set<E> sa, Set<E> sb) { Set<E> result = new HashSet<E>(); if (sa == null || sb == null || sa.isEmpty() || sb.isEmpty()) return result; Set<E> smallest = sa.size() < sb.size() ? sa : sb; Set<E> biggest = smallest == sa ? sb : sa; for (E entry : smallest) { if (biggest.contains(entry)) result.add(entry); } return result; }
From source file:Main.java
public static boolean intersects(Set<?> a, Set<?> b) { if (a.size() < b.size()) { for (Object obj : a) { if (b.contains(obj)) { return true; }/*from w w w . j a v a 2 s .c o m*/ } } else { for (Object obj : b) { if (a.contains(obj)) { return true; } } } return false; }
From source file:Main.java
public static Set<Integer> getIntersection(Set<Integer> set1, Set<Integer> set2) { Set<Integer> ret = new HashSet<Integer>(); for (Integer i : set1) { if (set2.contains(i)) { ret.add(i);//from w w w . j av a2 s . c o m } } return ret; }
From source file:Main.java
public static Set<Long> crossing(Set<Long> list1, Set<Long> list2) { Set<Long> resultList = new HashSet(); for (Long l : list1) { if (list2.contains(l)) { resultList.add(l);// w w w . ja v a2s . com } } return resultList; }