/** * Use {@link HashSet} to create a unique {@link Collection} based on the * one passed in. The method protects against <strong>null</strong>. The * returned {@link Collection} is unmodifiable. */ public static <T> Collection<T> unique(final Collection<T> c) { return Collections.<T>unmodifiableSet(newSet(c)); }
/** * Use {@link HashSet} to create a unique {@link Collection} based on the * one passed in. The method protects against <strong>null</strong>. The * returned {@link Collection} is unmodifiable. */ public static <T> Collection<T> unique(final Collection<T> c) { return Collections.<T> unmodifiableSet(newSet(c)); }
/** * Creates an unmodifiable set from a {@link Collection}. */ public static <T> Set<T> newReadOnlySet(Collection<T> c) { return Collections.unmodifiableSet(newSet(c)); }
/** * Creates an unmodifiable set from a {@link Collection}. */ public static <T> Set<T> newReadOnlySet(Collection<T> c) { return Collections.unmodifiableSet(newSet(c)); }
/** * Creates an unmodifiable set from a {@link Collection}. */ public static <T> Set<T> newReadOnlySet(Collection<T> c) { return Collections.unmodifiableSet(newSet(c)); }
/** * Creates an unmodifiable set from a variable number arguments. */ public static <T> Set<T> newReadOnlySet(T... arr) { return Collections.unmodifiableSet(newSet(arr)); }
/** * Use {@link HashSet} to create a unique {@link Collection} based on the * one passed in. The method protects against <strong>null</strong>. The * returned {@link Collection} is unmodifiable. */ public static <T> Collection<T> unique(final Collection<T> c) { return Collections.<T>unmodifiableSet(newSet(c)); }
/** * Returns the union of two {@link Collection}s as an unmodifiable set. */ public static <T> Set<T> union(Collection<T> c1, Collection<T> c2) { Set<T> union = newSet(c1); union.addAll(c2); return Collections.<T>unmodifiableSet(union); }
/** * Returns the intersection of two {@link Collection}s as an unmodifiable * set. */ public static <T> Set<T> intersection(Collection<T> c1, Collection<T> c2) { Set<T> intersection = newSet(c1); intersection.retainAll(c2); return Collections.<T> unmodifiableSet(intersection); }
/** * Creates an unmodifiable set from a variable number arguments. */ @SafeVarargs public static <T> Set<T> newReadOnlySet(T... arr) { return Collections.unmodifiableSet(newSet(arr)); }
/** * Creates an unmodifiable set from a variable number arguments. */ @SafeVarargs public static <T> Set<T> newReadOnlySet(T... arr) { return Collections.unmodifiableSet(newSet(arr)); }
/** * Returns the intersection of two {@link Collection}s as an unmodifiable * set. */ public static <T> Set<T> intersection(Collection<T> c1, Collection<T> c2) { Set<T> intersection = newSet(c1); intersection.retainAll(c2); return Collections.<T>unmodifiableSet(intersection); }
/** * Returns the union of two {@link Collection}s as an unmodifiable set. */ public static <T> Set<T> union(Collection<T> c1, Collection<T> c2) { Set<T> union = newSet(c1); union.addAll(c2); return Collections.<T> unmodifiableSet(union); }
/** * Returns the union of two {@link Collection}s as an unmodifiable set. */ public static <T> Set<T> union(Collection<T> c1, Collection<T> c2) { Set<T> union = newSet(c1); union.addAll(c2); return Collections.<T>unmodifiableSet(union); }
/** * Returns the intersection of two {@link Collection}s as an unmodifiable * set. */ public static <T> Set<T> intersection(Collection<T> c1, Collection<T> c2) { Set<T> intersection = newSet(c1); intersection.retainAll(c2); return Collections.<T>unmodifiableSet(intersection); }
/** * Constructs an instance of {@link ObjectClassInfo} with any * characteristics that were previously specified using this builder. * * @return an instance of {@link ObjectClassInfo} with the characteristics * previously specified. */ public ObjectClassInfo build() { // determine if name is missing and add it by default if (!_info.containsKey(Name.NAME)) { _info.put(Name.NAME, Name.INFO); } return new ObjectClassInfo(_type, CollectionUtil.newSet(_info.values()),_isContainer); } }
/** * Constructs an instance of {@link ObjectClassInfo} with any * characteristics that were previously specified using this builder. * * @return an instance of {@link ObjectClassInfo} with the characteristics * previously specified. */ public ObjectClassInfo build() { // determine if name is missing and add it by default if (!attributeInfoMap.containsKey(Name.NAME)) { attributeInfoMap.put(Name.NAME, Name.INFO); } return new ObjectClassInfo(type, CollectionUtil.newSet(attributeInfoMap.values()), isContainer, isAuxiliary); } }
/** * Constructs an instance of {@link ObjectClassInfo} with any * characteristics that were previously specified using this builder. * * @return an instance of {@link ObjectClassInfo} with the characteristics * previously specified. */ public ObjectClassInfo build() { // determine if name is missing and add it by default if (!attributeInfoMap.containsKey(Name.NAME)) { attributeInfoMap.put(Name.NAME, Name.INFO); } return new ObjectClassInfo(type, CollectionUtil.newSet(attributeInfoMap.values()), isContainer, isAuxiliary); } }
@Test public void testAsSet() { Collection<Integer> c = new ArrayList<>(); c.add(1); c.add(2); Set<Integer> set = CollectionUtil.newSet(c); assertTrue(set.contains(1)); assertTrue(set.contains(2)); // make sure it can be modified.. set.add(2); // make sure asset can handle null.. c = null; CollectionUtil.newSet(c); // test vargs.. set = CollectionUtil.newSet(1, 2); assertTrue(set.contains(1)); assertTrue(set.contains(2)); }