Skip to content

Commit

Permalink
Merge branch '__rultor'
Browse files Browse the repository at this point in the history
  • Loading branch information
rultor committed Mar 15, 2020
2 parents 867e20e + 971d218 commit 90ff77d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 33 deletions.
18 changes: 3 additions & 15 deletions src/main/java/org/cactoos/set/SetOf.java
Original file line number Diff line number Diff line change
Expand Up @@ -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}.
*
* <p>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. </p>
* Iterable as {@link Set} based on {@link HashSet}.
*
* <p>There is no thread-safety guarantee.
*
Expand All @@ -57,14 +52,7 @@ public SetOf(final T... array) {
* @param src An {@link Iterable}
*/
public SetOf(final Iterable<T> src) {
super(
new Unchecked<>(
() -> {
final Set<T> tmp = new HashSet<>();
src.forEach(tmp::add);
return tmp;
}
).value()
);
super(new HashSet<>());
src.forEach(super::add);
}
}
22 changes: 7 additions & 15 deletions src/main/java/org/cactoos/set/Sorted.java
Original file line number Diff line number Diff line change
Expand Up @@ -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}.
*
* <p>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. </p>
* Iterable as Sorted {@link Set} based on {@link TreeSet}.
*
* <p>There is no thread-safety guarantee.
*
* @param <T> 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<T> extends SetEnvelope<T> {

Expand All @@ -58,15 +56,9 @@ public Sorted(final Comparator<T> cmp, final T... array) {
* @param cmp Comparator
* @param src An {@link Iterable}
*/
@SuppressWarnings("PMD.ConstructorOnlyInitializesOrCallOtherConstructors")
public Sorted(final Comparator<T> cmp, final Iterable<T> src) {
super(
new Unchecked<>(
() -> {
final Set<T> set = new TreeSet<>(cmp);
src.forEach(set::add);
return set;
}
).value()
);
super(new TreeSet<>(cmp));
src.forEach(super::add);
}
}
3 changes: 0 additions & 3 deletions src/main/java/org/cactoos/set/package-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

2 comments on commit 90ff77d

@0pdd
Copy link
Collaborator

@0pdd 0pdd commented on 90ff77d Mar 15, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle 1242-a8a7ac97 disappeared from src/main/java/org/cactoos/set/package-info.java, that's why I closed #1292. Please, remember that the puzzle was not necessarily removed in this particular commit. Maybe it happened earlier, but we discovered this fact only now.

@0pdd
Copy link
Collaborator

@0pdd 0pdd commented on 90ff77d Mar 15, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle 1292-c2a188c0 discovered in src/main/java/org/cactoos/set/Sorted.java and submitted as #1325. Please, remember that the puzzle was not necessarily added in this particular commit. Maybe it was added earlier, but we discovered it only now.

Please sign in to comment.