Skip to content

Commit

Permalink
Revert "[#37] toSet() parallel optimization implementation"
Browse files Browse the repository at this point in the history
This reverts commit 596cf9c.
  • Loading branch information
amaembo committed Dec 12, 2015
1 parent 596cf9c commit c39e547
Showing 1 changed file with 1 addition and 24 deletions.
25 changes: 1 addition & 24 deletions src/main/java/one/util/streamex/AbstractStreamEx.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.Comparator;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
Expand All @@ -28,8 +27,6 @@
import java.util.Set;
import java.util.Spliterator;
import java.util.Spliterators.AbstractSpliterator;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.BiConsumer;
import java.util.function.BiFunction;
import java.util.function.BinaryOperator;
Expand Down Expand Up @@ -1114,27 +1111,7 @@ public <R> R toListAndThen(Function<List<T>, R> finisher) {
* @see Collectors#toSet()
*/
public Set<T> toSet() {
if(isParallel()) {
AtomicBoolean hasNull = new AtomicBoolean();
Set<T> set = ConcurrentHashMap.newKeySet();
forEach(val -> {
if(val == null)
hasNull.set(true);
else
set.add(val);
});
if(hasNull.get()) {
Set<T> result = new HashSet<>(set);
result.add(null);
return result;
} else {
return set;
}
} else {
Set<T> result = new HashSet<>();
forEach(result::add);
return result;
}
return rawCollect(Collectors.toSet());
}

/**
Expand Down

0 comments on commit c39e547

Please sign in to comment.