List of usage examples for java.util LinkedHashSet LinkedHashSet
public LinkedHashSet(Collection<? extends E> c)
From source file:Main.java
public static <T> LinkedHashSet<T> createLinkedHashSet(Iterable<? extends T> c) { LinkedHashSet<T> set;// w w w.j av a 2 s . c om if (c instanceof Collection<?>) { set = new LinkedHashSet<T>((Collection<? extends T>) c); } else { set = new LinkedHashSet<T>(); iterableToCollection(c, set); } return set; }
From source file:Main.java
@SafeVarargs private static <T> Set<T> set(T... args) { return addAll(new LinkedHashSet<T>(args.length), args); }
From source file:Main.java
/** * Returns a set of the comma-separated input values. * * @param <A> Value type/*ww w .j a v a 2 s .c o m*/ * @param values Comma-separated input values * @return Set of values (iteration order equal to insertion order) */ public static <A> Set<A> setOf(A... values) { return new LinkedHashSet<A>(Arrays.asList(values)); }
From source file:de.mpg.imeji.logic.search.util.CollectionUtils.java
@SuppressWarnings({ "rawtypes", "unchecked" }) public static Collection union(final Collection a, final Collection b) { ArrayList list = new ArrayList(); Map mapa = getCardinalityMap(a); Map mapb = getCardinalityMap(b); Set elts = new LinkedHashSet(a); elts.addAll(b);/*w ww . j ava 2 s. c o m*/ Iterator it = elts.iterator(); while (it.hasNext()) { Object obj = it.next(); for (int i = 0, m = Math.max(getFreq(obj, mapa), getFreq(obj, mapb)); i < m; i++) { list.add(obj); } } return list; }
From source file:Main.java
@SuppressWarnings({ "unchecked" }) public static <E> Set<E> asSet(E... elements) { if (elements == null || elements.length == 0) { return Collections.EMPTY_SET; }// w w w . j a v a 2s . com LinkedHashSet<E> set = new LinkedHashSet<E>(elements.length * 4 / 3 + 1); Collections.addAll(set, elements); return set; }
From source file:Main.java
/** * Converts the given objects into a {@link Set}. * @param <T> The type of the objects. * @param objects The objects array to convert. * @return The created {@link Set}./*from w ww . jav a 2 s .c o m*/ */ public static <T> Set<T> toSet(T... objects) { if (objects != null) { Set<T> result = new LinkedHashSet<T>(objects.length); for (T obj : objects) { result.add(obj); } return result; } else { return new LinkedHashSet<T>(0); } }
From source file:SetOps.java
/** * //ww w . ja v a 2 s .c om * @param <T> * @param s1 * @param s2 * @return the intersection of s1 and s2. (The intersection of two sets is * the set containing only the elements common to both sets.) */ public static <T> Set<T> intersection(Set<T> s1, Set<T> s2) { Set<T> intersection = new LinkedHashSet<T>(s1); intersection.retainAll(s2); return intersection; }
From source file:Main.java
public static <E> Set<E> asSet(E... elements) { if (elements == null || elements.length == 0) { return Collections.emptySet(); }//from w ww. j a v a 2s. co m if (elements.length == 1) { return Collections.singleton(elements[0]); } LinkedHashSet<E> set = new LinkedHashSet<E>(elements.length * 4 / 3 + 1); Collections.addAll(set, elements); return set; }
From source file:Main.java
private static Set<String> toStringSet(String... metrics) { return new LinkedHashSet<String>(Arrays.asList(metrics)); }
From source file:Main.java
/** * Appends value to collection. If value is collection all elements are added, if value is object it is simply * added. If skipDuplicates is set to true, objects already contained in the collection are not added again. Note * that element would be type casted to collection type. * //from w ww .j av a 2s. co m * @param data * is the collection to update - set, list, etc. Should be modifiable * @param value * is value of type T or {@link Collection} of elements of type T * @param skipDuplicates * whether to treat data as {@link Set}. Note if data is already {@link Set} parameter does not affect * the result. Note if data already contains duplicate elements they are not affected. * @return the updated data collection */ @SuppressWarnings("unchecked") public static <T> Collection<T> addValue(Collection<T> data, Object value, boolean skipDuplicates) { if (value instanceof Collection) { Collection<T> toBeAdded = (Collection<T>) value; if (skipDuplicates && !(data instanceof Set)) { Set<T> nonDuplicates = new LinkedHashSet<>(toBeAdded); nonDuplicates.removeAll(data); data.addAll(nonDuplicates); } else { data.addAll(toBeAdded); } } else if (value != null) { if (skipDuplicates && !(data instanceof Set) && data.contains(value)) { return data; } data.add((T) value); } return data; }