Skip to content

Commit 51030c5

Browse files
committed
Deprecate classes where functionality is already provided
1 parent a37c370 commit 51030c5

File tree

2 files changed

+34
-41
lines changed

2 files changed

+34
-41
lines changed

gdsc-core/src/main/java/uk/ac/sussex/gdsc/core/utils/OpenHashMaps.java

Lines changed: 21 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,17 @@
4242
* href="https://github.com/vigna/fastutil">fastutil collections library</a>.
4343
*
4444
* <p>The extensions provide zero-allocation forEach iteration of the entries in the map.
45+
*
46+
* @deprecated Functionality is now available in the fastutil OpenHashMap implementations.
4547
*/
48+
@Deprecated
4649
public final class OpenHashMaps {
4750
/**
4851
* Customisation of Long2IntOpenHashMap.
52+
*
53+
* @deprecated Functionality is now available in the fastutil OpenHashMap implementations.
4954
*/
55+
@Deprecated
5056
public static class CustomLong2IntOpenHashMap extends Long2IntOpenHashMap {
5157
private static final long serialVersionUID = 1L;
5258

@@ -72,20 +78,17 @@ public CustomLong2IntOpenHashMap(int expected) {
7278
* @param action the action
7379
*/
7480
public void forEach(LongIntConsumer action) {
75-
if (containsNullKey) {
76-
action.accept(key[n], value[n]);
77-
}
78-
for (int pos = n; pos-- != 0;) {
79-
if (key[pos] != 0) {
80-
action.accept(key[pos], value[pos]);
81-
}
82-
}
81+
// Delegate
82+
super.forEach(action::accept);
8383
}
8484
}
8585

8686
/**
8787
* Customisation of Int2IntOpenHashMap.
88+
*
89+
* @deprecated Functionality is now available in the fastutil OpenHashMap implementations.
8890
*/
91+
@Deprecated
8992
public static class CustomInt2IntOpenHashMap extends Int2IntOpenHashMap {
9093
private static final long serialVersionUID = 1L;
9194

@@ -111,22 +114,18 @@ public CustomInt2IntOpenHashMap(int expected) {
111114
* @param action the action
112115
*/
113116
public void forEach(IntIntConsumer action) {
114-
if (containsNullKey) {
115-
action.accept(key[n], value[n]);
116-
}
117-
for (int pos = n; pos-- != 0;) {
118-
if (key[pos] != 0) {
119-
action.accept(key[pos], value[pos]);
120-
}
121-
}
117+
// Delegate
118+
super.forEach(action::accept);
122119
}
123120
}
124121

125122
/**
126123
* Customisation of Int2ObjectOpenHashMap.
127124
*
128125
* @param <T> the element type
126+
* @deprecated Functionality is now available in the fastutil OpenHashMap implementations.
129127
*/
128+
@Deprecated
130129
public static class CustomInt2ObjectOpenHashMap<T> extends Int2ObjectOpenHashMap<T> {
131130
private static final long serialVersionUID = 1L;
132131

@@ -152,22 +151,18 @@ public CustomInt2ObjectOpenHashMap(int expected) {
152151
* @param action the action
153152
*/
154153
public void forEach(IntObjConsumer<T> action) {
155-
if (containsNullKey) {
156-
action.accept(key[n], value[n]);
157-
}
158-
for (int pos = n; pos-- != 0;) {
159-
if (key[pos] != 0) {
160-
action.accept(key[pos], value[pos]);
161-
}
162-
}
154+
// Delegate
155+
super.forEach(action::accept);
163156
}
164157
}
165158

166159
/**
167160
* Customisation of Object2IntOpenHashMap.
168161
*
169162
* @param <T> the element type
163+
* @deprecated Functionality is now available in the fastutil OpenHashMap implementations.
170164
*/
165+
@Deprecated
171166
public static class CustomObject2IntOpenHashMap<T> extends Object2IntOpenHashMap<T> {
172167
private static final long serialVersionUID = 1L;
173168

@@ -193,14 +188,8 @@ public CustomObject2IntOpenHashMap(int expected) {
193188
* @param action the action
194189
*/
195190
public void forEach(ObjIntConsumer<T> action) {
196-
if (containsNullKey) {
197-
action.accept(key[n], value[n]);
198-
}
199-
for (int pos = n; pos-- != 0;) {
200-
if (key[pos] != null) {
201-
action.accept(key[pos], value[pos]);
202-
}
203-
}
191+
// Delegate
192+
super.forEach(action::accept);
204193
}
205194
}
206195

gdsc-core/src/test/java/uk/ac/sussex/gdsc/core/utils/OpenHashMapsTest.java

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,75 +28,79 @@
2828

2929
package uk.ac.sussex.gdsc.core.utils;
3030

31+
import java.util.function.ObjIntConsumer;
3132
import org.apache.commons.rng.UniformRandomProvider;
3233
import org.junit.jupiter.api.Assertions;
3334
import uk.ac.sussex.gdsc.core.utils.OpenHashMaps.CustomInt2IntOpenHashMap;
3435
import uk.ac.sussex.gdsc.core.utils.OpenHashMaps.CustomInt2ObjectOpenHashMap;
3536
import uk.ac.sussex.gdsc.core.utils.OpenHashMaps.CustomLong2IntOpenHashMap;
3637
import uk.ac.sussex.gdsc.core.utils.OpenHashMaps.CustomObject2IntOpenHashMap;
38+
import uk.ac.sussex.gdsc.core.utils.function.IntIntConsumer;
39+
import uk.ac.sussex.gdsc.core.utils.function.IntObjConsumer;
40+
import uk.ac.sussex.gdsc.core.utils.function.LongIntConsumer;
3741
import uk.ac.sussex.gdsc.test.junit5.SeededTest;
3842
import uk.ac.sussex.gdsc.test.rng.RngFactory;
3943
import uk.ac.sussex.gdsc.test.utils.RandomSeed;
4044

41-
@SuppressWarnings({"javadoc"})
45+
@SuppressWarnings({"javadoc", "deprecation"})
4246
class OpenHashMapsTest {
4347
@SeededTest
4448
void testLong2IntForEach(RandomSeed seed) {
4549
final UniformRandomProvider rng = RngFactory.create(seed.get());
4650
final CustomLong2IntOpenHashMap m = new CustomLong2IntOpenHashMap();
47-
m.forEach((long k, int v) -> {
51+
m.forEach((LongIntConsumer) (long k, int v) -> {
4852
Assertions.fail();
4953
});
5054
for (int i = 0; i < 5; i++) {
5155
m.put(rng.nextLong(), rng.nextInt());
5256
}
5357
final CustomLong2IntOpenHashMap m2 = new CustomLong2IntOpenHashMap(16);
54-
m.forEach((long k, int v) -> m2.put(k, v));
58+
m.forEach((LongIntConsumer) (long k, int v) -> m2.put(k, v));
5559
Assertions.assertEquals(m2, m);
5660
}
5761

5862
@SeededTest
5963
void testInt2IntForEach(RandomSeed seed) {
6064
final UniformRandomProvider rng = RngFactory.create(seed.get());
6165
final CustomInt2IntOpenHashMap m = new CustomInt2IntOpenHashMap();
62-
m.forEach((int k, int v) -> {
66+
m.forEach((IntIntConsumer) (int k, int v) -> {
6367
Assertions.fail();
6468
});
6569
for (int i = 0; i < 5; i++) {
6670
m.put(rng.nextInt(), rng.nextInt());
6771
}
6872
final CustomInt2IntOpenHashMap m2 = new CustomInt2IntOpenHashMap(16);
69-
m.forEach((int k, int v) -> m2.put(k, v));
73+
m.forEach((IntIntConsumer) (int k, int v) -> m2.put(k, v));
7074
Assertions.assertEquals(m2, m);
7175
}
7276

7377
@SeededTest
7478
void testObject2IntForEach(RandomSeed seed) {
7579
final UniformRandomProvider rng = RngFactory.create(seed.get());
7680
final CustomObject2IntOpenHashMap<Double> m = new CustomObject2IntOpenHashMap<>();
77-
m.forEach((Double k, int v) -> {
81+
m.forEach((ObjIntConsumer<Double>) (Double k, int v) -> {
7882
Assertions.fail();
7983
});
8084
for (int i = 0; i < 5; i++) {
8185
m.put(Double.valueOf(rng.nextDouble()), rng.nextInt());
8286
}
8387
final CustomObject2IntOpenHashMap<Double> m2 = new CustomObject2IntOpenHashMap<>(16);
84-
m.forEach((Double k, int v) -> m2.put(k, v));
88+
m.forEach((ObjIntConsumer<Double>) (Double k, int v) -> m2.put(k, v));
8589
Assertions.assertEquals(m2, m);
8690
}
8791

8892
@SeededTest
8993
void testInt2ObjectForEach(RandomSeed seed) {
9094
final UniformRandomProvider rng = RngFactory.create(seed.get());
9195
final CustomInt2ObjectOpenHashMap<Double> m = new CustomInt2ObjectOpenHashMap<>();
92-
m.forEach((int k, Double v) -> {
96+
m.forEach((IntObjConsumer<Double>) (int k, Double v) -> {
9397
Assertions.fail();
9498
});
9599
for (int i = 0; i < 5; i++) {
96100
m.put(rng.nextInt(), Double.valueOf(rng.nextDouble()));
97101
}
98102
final CustomInt2ObjectOpenHashMap<Double> m2 = new CustomInt2ObjectOpenHashMap<>(16);
99-
m.forEach((int k, Double v) -> m2.put(k, v));
103+
m.forEach((IntObjConsumer<Double>) (int k, Double v) -> m2.put(k, v));
100104
Assertions.assertEquals(m2, m);
101105
}
102106
}

0 commit comments

Comments
 (0)