@Override public <U> LinkedHashSet<U> flatMap(Function<? super T, ? extends Iterable<? extends U>> mapper) { Objects.requireNonNull(mapper, "mapper is null"); if (isEmpty()) { return empty(); } else { final LinkedHashMap<U, Object> that = foldLeft(LinkedHashMap.empty(), (tree, t) -> addAll(tree, mapper.apply(t))); return new LinkedHashSet<>(that); } }
/** * Creates a LinkedHashSet of the given elements. * * @param elements Set elements * @param <T> The value type * @return A new LinkedHashSet containing the given entries */ @SuppressWarnings("unchecked") public static <T> LinkedHashSet<T> ofAll(Iterable<? extends T> elements) { Objects.requireNonNull(elements, "elements is null"); if (elements instanceof LinkedHashSet) { return (LinkedHashSet<T>) elements; } else { final LinkedHashMap<T, Object> mao = addAll(LinkedHashMap.empty(), elements); return mao.isEmpty() ? empty() : new LinkedHashSet<>(mao); } }
/** * Adds all of the given elements to this set, replacing existing one if they are not already contained. * <p> * Note that this method has a worst-case quadratic complexity. * * @param elements The elements to be added. * @return A new set containing all elements of this set and the given {@code elements}, if not already contained. */ @Override public LinkedHashSet<T> addAll(Iterable<? extends T> elements) { Objects.requireNonNull(elements, "elements is null"); if (isEmpty() && elements instanceof LinkedHashSet) { @SuppressWarnings("unchecked") final LinkedHashSet<T> set = (LinkedHashSet<T>) elements; return set; } final LinkedHashMap<T, Object> that = addAll(map, elements); if (that.size() == map.size()) { return this; } else { return new LinkedHashSet<>(that); } }
return this; } else { final LinkedHashMap<T, Object> that = addAll(map, elements); if (that.size() == map.size()) { return this;
@Override public <U> LinkedHashSet<U> flatMap(Function<? super T, ? extends Iterable<? extends U>> mapper) { Objects.requireNonNull(mapper, "mapper is null"); if (isEmpty()) { return empty(); } else { final LinkedHashMap<U, Object> that = foldLeft(LinkedHashMap.empty(), (tree, t) -> addAll(tree, mapper.apply(t))); return new LinkedHashSet<>(that); } }
/** * Creates a LinkedHashSet of the given elements. * * @param elements Set elements * @param <T> The value type * @return A new LinkedHashSet containing the given entries */ @SuppressWarnings("unchecked") public static <T> LinkedHashSet<T> ofAll(Iterable<? extends T> elements) { Objects.requireNonNull(elements, "elements is null"); if (elements instanceof LinkedHashSet) { return (LinkedHashSet<T>) elements; } else { final LinkedHashMap<T, Object> mao = addAll(LinkedHashMap.empty(), elements); return mao.isEmpty() ? empty() : new LinkedHashSet<>(mao); } }
/** * Adds all of the given elements to this set, replacing existing one if they are not already contained. * <p> * Note that this method has a worst-case quadratic complexity. * * @param elements The elements to be added. * @return A new set containing all elements of this set and the given {@code elements}, if not already contained. */ @Override public LinkedHashSet<T> addAll(Iterable<? extends T> elements) { Objects.requireNonNull(elements, "elements is null"); if (isEmpty() && elements instanceof LinkedHashSet) { @SuppressWarnings("unchecked") final LinkedHashSet<T> set = (LinkedHashSet<T>) elements; return set; } final LinkedHashMap<T, Object> that = addAll(map, elements); if (that.size() == map.size()) { return this; } else { return new LinkedHashSet<>(that); } }
return this; } else { final LinkedHashMap<T, Object> that = addAll(map, elements); if (that.size() == map.size()) { return this;