From 971d21806ad9fc0aec0739302f63faeb29bd1d61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Victor=20No=C3=ABl?= Date: Sat, 29 Feb 2020 18:00:49 +0100 Subject: [PATCH] (#1292) SetOf and Sorted are real in memory sets --- src/main/java/org/cactoos/set/SetOf.java | 18 +++------------ src/main/java/org/cactoos/set/Sorted.java | 22 ++++++------------- .../java/org/cactoos/set/package-info.java | 3 --- 3 files changed, 10 insertions(+), 33 deletions(-) diff --git a/src/main/java/org/cactoos/set/SetOf.java b/src/main/java/org/cactoos/set/SetOf.java index d91ca3d193..dccff0dba2 100644 --- a/src/main/java/org/cactoos/set/SetOf.java +++ b/src/main/java/org/cactoos/set/SetOf.java @@ -26,14 +26,9 @@ import java.util.HashSet; import java.util.Set; import org.cactoos.iterable.IterableOf; -import org.cactoos.scalar.Unchecked; /** - * Iterable as {@link Set}. - * - *

This class should be used very carefully. You must understand that - * it will fetch the entire content of the encapsulated {@link Set} on each - * method call. It doesn't cache the data anyhow.

+ * Iterable as {@link Set} based on {@link HashSet}. * *

There is no thread-safety guarantee. * @@ -57,14 +52,7 @@ public SetOf(final T... array) { * @param src An {@link Iterable} */ public SetOf(final Iterable src) { - super( - new Unchecked<>( - () -> { - final Set tmp = new HashSet<>(); - src.forEach(tmp::add); - return tmp; - } - ).value() - ); + super(new HashSet<>()); + src.forEach(super::add); } } diff --git a/src/main/java/org/cactoos/set/Sorted.java b/src/main/java/org/cactoos/set/Sorted.java index 3e8f943850..fc3d61b82f 100644 --- a/src/main/java/org/cactoos/set/Sorted.java +++ b/src/main/java/org/cactoos/set/Sorted.java @@ -27,19 +27,17 @@ import java.util.Set; import java.util.TreeSet; import org.cactoos.iterable.IterableOf; -import org.cactoos.scalar.Unchecked; /** - * Sorted Iterable as {@link Set}. - * - *

This class should be used very carefully. You must understand that - * it will fetch the entire content of the encapsulated {@link Set} on each - * method call. It doesn't cache the data anyhow.

+ * Iterable as Sorted {@link Set} based on {@link TreeSet}. * *

There is no thread-safety guarantee. * * @param Set type * @since 1.0.0 + * @todo #1292:30min This class should also implements SortedSet + * from the java collection framework by delegating to the + * wrapped set. Some tests must be added for it. */ public final class Sorted extends SetEnvelope { @@ -58,15 +56,9 @@ public Sorted(final Comparator cmp, final T... array) { * @param cmp Comparator * @param src An {@link Iterable} */ + @SuppressWarnings("PMD.ConstructorOnlyInitializesOrCallOtherConstructors") public Sorted(final Comparator cmp, final Iterable src) { - super( - new Unchecked<>( - () -> { - final Set set = new TreeSet<>(cmp); - src.forEach(set::add); - return set; - } - ).value() - ); + super(new TreeSet<>(cmp)); + src.forEach(super::add); } } diff --git a/src/main/java/org/cactoos/set/package-info.java b/src/main/java/org/cactoos/set/package-info.java index 9f502ee864..fdc4dfbbcc 100644 --- a/src/main/java/org/cactoos/set/package-info.java +++ b/src/main/java/org/cactoos/set/package-info.java @@ -26,8 +26,5 @@ * Sets. * * @since 0.49.2 - * @todo #1242:30min The SetOf class should be implemented as an in-memory set, - * for example based on HashSet. See ListOf for an example and #1242 for the - * rationale behind this design. */ package org.cactoos.set;