Skip to content

Commit 3e895ed

Browse files
committed
+ SmartLongIterator, SmartIntIterator
1 parent 09e7257 commit 3e895ed

File tree

3 files changed

+120
-5
lines changed

3 files changed

+120
-5
lines changed

src/main/java/com/trivago/fastutilconcurrentwrapper/util/ReadWriteLockCollection.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,10 @@ public boolean tryAdvance (Consumer<? super E> action) {
103103
E v;
104104
try (var __ = read()){
105105
var i = it();
106-
if (i.hasNext()){
107-
v = i.next();
108-
} else {
109-
return false;
110-
}
106+
if (i.hasNext())
107+
v = i.next();
108+
else
109+
return false;
111110
}
112111
action.accept(v);
113112
return true;
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package com.trivago.fastutilconcurrentwrapper.util;
2+
3+
import it.unimi.dsi.fastutil.ints.IntIterator;
4+
import it.unimi.dsi.fastutil.ints.IntSpliterator;
5+
import org.jspecify.annotations.Nullable;
6+
7+
import java.util.function.Consumer;
8+
import java.util.function.IntConsumer;
9+
10+
/**
11+
@see SmartIterator
12+
@see IntIterator
13+
@see it.unimi.dsi.fastutil.ints.IntIterators
14+
@see IntSpliterator
15+
@see it.unimi.dsi.fastutil.ints.IntSpliterators
16+
*/
17+
public interface SmartIntIterator extends SmartIterator<Integer>, IntIterator, IntSpliterator {
18+
@Override
19+
default @Nullable SmartIntIterator trySplit () {
20+
return null;// cannot be split
21+
}
22+
23+
@Override @Deprecated
24+
default void forEachRemaining (Consumer<? super Integer> action) {
25+
IntIterator.super.forEachRemaining(action);
26+
}
27+
28+
@Override
29+
default void forEachRemaining (IntConsumer action) {
30+
IntSpliterator.super.forEachRemaining(action);
31+
}
32+
@Override
33+
default void forEachRemaining (it.unimi.dsi.fastutil.ints.IntConsumer action) {
34+
IntSpliterator.super.forEachRemaining((IntConsumer)action);
35+
}
36+
37+
@Override
38+
default int skip (int n) {
39+
return IntIterator.super.skip(n);
40+
}
41+
@Override
42+
default long skip (long n) {
43+
return IntSpliterator.super.skip(n);
44+
}
45+
46+
@Override
47+
default boolean tryAdvance (IntConsumer action) {
48+
if (hasNext()){
49+
action.accept(nextInt());
50+
return true;
51+
} else
52+
return false;
53+
}
54+
55+
@Override @Deprecated
56+
default boolean tryAdvance (Consumer<? super Integer> action) {
57+
return IntSpliterator.super.tryAdvance(action);
58+
}
59+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package com.trivago.fastutilconcurrentwrapper.util;
2+
3+
import it.unimi.dsi.fastutil.longs.LongIterator;
4+
import it.unimi.dsi.fastutil.longs.LongSpliterator;
5+
import org.jspecify.annotations.Nullable;
6+
7+
import java.util.function.Consumer;
8+
import java.util.function.LongConsumer;
9+
10+
/**
11+
@see SmartIterator
12+
@see it.unimi.dsi.fastutil.longs.LongIterator
13+
@see it.unimi.dsi.fastutil.longs.LongSpliterator
14+
*/
15+
public interface SmartLongIterator extends SmartIterator<Long>, LongIterator, LongSpliterator {
16+
@Override
17+
default @Nullable SmartLongIterator trySplit () {
18+
return null;// cannot be split
19+
}
20+
21+
@Override @Deprecated
22+
default void forEachRemaining (Consumer<? super Long> action) {
23+
LongIterator.super.forEachRemaining(action);
24+
}
25+
26+
@Override
27+
default void forEachRemaining (LongConsumer action) {
28+
LongSpliterator.super.forEachRemaining(action);
29+
}
30+
@Override
31+
default void forEachRemaining (it.unimi.dsi.fastutil.longs.LongConsumer action) {
32+
LongSpliterator.super.forEachRemaining((LongConsumer)action);
33+
}
34+
35+
@Override
36+
default int skip (int n) {
37+
return LongIterator.super.skip(n);
38+
}
39+
@Override
40+
default long skip (long n) {
41+
return LongSpliterator.super.skip(n);
42+
}
43+
44+
@Override
45+
default boolean tryAdvance (LongConsumer action) {
46+
if (hasNext()){
47+
action.accept(nextLong());
48+
return true;
49+
} else
50+
return false;
51+
}
52+
53+
@Override @Deprecated
54+
default boolean tryAdvance (Consumer<? super Long> action) {
55+
return LongSpliterator.super.tryAdvance(action);
56+
}
57+
}

0 commit comments

Comments
 (0)