Skip to content

Commit

Permalink
Long::sum used (thanks to @holger)
Browse files Browse the repository at this point in the history
  • Loading branch information
amaembo committed May 29, 2015
1 parent 5803491 commit 8cc7f63
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions src/main/java/javax/util/streamex/DistinctSpliterator.java
Expand Up @@ -34,14 +34,14 @@ void setCur(T t) {
public boolean tryAdvance(Consumer<? super T> action) {
if (nullCounter == null) {
while (source.tryAdvance(this::setCur)) {
if (counts.merge(cur, 1L, (u, v) -> u + v) == atLeast) {
if (counts.merge(cur, 1L, Long::sum) == atLeast) {
action.accept(cur);
return true;
}
}
} else {
while (source.tryAdvance(this::setCur)) {
long count = cur == null ? nullCounter.incrementAndGet() : counts.merge(cur, 1L, (u, v) -> u + v);
long count = cur == null ? nullCounter.incrementAndGet() : counts.merge(cur, 1L, Long::sum);
if (count == atLeast) {
action.accept(cur);
return true;
Expand All @@ -55,13 +55,13 @@ public boolean tryAdvance(Consumer<? super T> action) {
public void forEachRemaining(Consumer<? super T> action) {
if (nullCounter == null) {
source.forEachRemaining(e -> {
if (counts.merge(e, 1L, (u, v) -> u + v) == atLeast) {
if (counts.merge(e, 1L, Long::sum) == atLeast) {
action.accept(e);
}
});
} else {
source.forEachRemaining(e -> {
long count = e == null ? nullCounter.incrementAndGet() : counts.merge(e, 1L, (u, v) -> u + v);
long count = e == null ? nullCounter.incrementAndGet() : counts.merge(e, 1L, Long::sum);
if (count == atLeast) {
action.accept(e);
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/javax/util/streamex/StreamEx.java
Expand Up @@ -999,7 +999,7 @@ public StreamEx<T> distinct(long atLeast) {
if (t == null) {
return nullCount.incrementAndGet() == atLeast;
}
return map.merge(t, 1L, (u, v) -> (u + v)) == atLeast;
return map.merge(t, 1L, Long::sum) == atLeast;
});
}

Expand Down

0 comments on commit 8cc7f63

Please sign in to comment.