Skip to content

Commit 58c4672

Browse files
committed
Fix raw type warnings
1 parent 87fcccb commit 58c4672

File tree

3 files changed

+39
-44
lines changed

3 files changed

+39
-44
lines changed

src/test/java/com/maxmind/db/DecoderTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -257,10 +257,10 @@ private static Map<Boolean, byte[]> booleans() {
257257
return booleans;
258258
}
259259

260-
private static Map<Map, byte[]> maps() {
261-
Map<Map, byte[]> maps = new HashMap<>();
260+
private static Map<Map<String, ?>, byte[]> maps() {
261+
Map<Map<String, ?>, byte[]> maps = new HashMap<>();
262262

263-
Map empty = new HashMap();
263+
Map<String, Object> empty = Map.of();
264264
maps.put(empty, new byte[] {(byte) 0xe0});
265265

266266
Map<String, String> one = new HashMap<>();

src/test/java/com/maxmind/db/MultiThreadedTest.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public class MultiThreadedTest {
1919
@Test
2020
public void multipleMmapOpens() throws InterruptedException,
2121
ExecutionException {
22-
Callable<Map> task = () -> {
22+
Callable<Map<?, ?>> task = () -> {
2323
try (Reader reader = new Reader(ReaderTest.getFile("MaxMind-DB-test-decoder.mmdb"))) {
2424
return reader.get(InetAddress.getByName("::1.1.1.0"), Map.class);
2525
}
@@ -45,20 +45,20 @@ public void mmapThreadTest() throws IOException, InterruptedException,
4545

4646
private static void threadTest(final Reader reader)
4747
throws InterruptedException, ExecutionException {
48-
Callable<Map> task = () -> reader.get(InetAddress.getByName("::1.1.1.0"), Map.class);
48+
Callable<Map<?, ?>> task = () -> reader.get(InetAddress.getByName("::1.1.1.0"), Map.class);
4949
MultiThreadedTest.runThreads(task);
5050
}
5151

52-
private static void runThreads(Callable<Map> task)
52+
private static void runThreads(Callable<Map<?, ?>> task)
5353
throws InterruptedException, ExecutionException {
5454
int threadCount = 256;
55-
List<Callable<Map>> tasks = Collections.nCopies(threadCount, task);
55+
List<Callable<Map<?, ?>>> tasks = Collections.nCopies(threadCount, task);
5656
ExecutorService executorService = Executors
5757
.newFixedThreadPool(threadCount);
58-
List<Future<Map>> futures = executorService.invokeAll(tasks);
58+
List<Future<Map<?, ?>>> futures = executorService.invokeAll(tasks);
5959

60-
for (Future<Map> future : futures) {
61-
Map record = future.get();
60+
for (Future<Map<?, ?>> future : futures) {
61+
Map<?, ?> record = future.get();
6262
assertEquals(268435456, (long) record.get("uint32"));
6363
assertEquals("unicode! ☯ - ♫", record.get("utf8_string"));
6464
}

src/test/java/com/maxmind/db/ReaderTest.java

Lines changed: 29 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,13 @@ public void testNetworks() throws IOException, InvalidDatabaseException, Invalid
8585
File file = getFile("MaxMind-DB-test-ipv" + ipVersion + "-" + recordSize + ".mmdb");
8686

8787
Reader reader = new Reader(file);
88-
Networks networks = reader.networks(false, Map.class);
88+
Networks<?> networks = reader.networks(false, Map.class);
8989

9090
while(networks.hasNext()) {
91-
DatabaseRecord<Map<String, String>> iteration = networks.next();
92-
Map<String, String> data = iteration.getData();
91+
DatabaseRecord<?> iteration = networks.next();
92+
Map<?, ?> data = (Map<?, ?>) iteration.getData();
9393

94-
InetAddress actualIPInData = InetAddress.getByName(data.get("ip"));
94+
InetAddress actualIPInData = InetAddress.getByName((String) data.get("ip"));
9595

9696
assertEquals(
9797
iteration.getNetwork().getNetworkAddress(),
@@ -110,11 +110,11 @@ public void testNetworksWithInvalidSearchTree() throws IOException, InvalidNetwo
110110
File file = getFile("MaxMind-DB-test-broken-search-tree-24.mmdb");
111111
Reader reader = new Reader(file);
112112

113-
Networks networks = reader.networks(false, Map.class);
113+
Networks<?> networks = reader.networks(false, Map.class);
114114

115115
Exception exception = assertThrows(RuntimeException.class, () -> {
116116
while(networks.hasNext()){
117-
DatabaseRecord iteration = networks.next();
117+
assertNotNull(networks.next());
118118
}
119119
});
120120

@@ -339,11 +339,11 @@ public void testNetworksWithin() throws IOException, InvalidNetworkException{
339339
Network network = new Network(address, test.prefix);
340340

341341
boolean includeAliasedNetworks = !test.skipAliasedNetworks;
342-
Networks networks = reader.networksWithin(network, includeAliasedNetworks, Map.class);
342+
Networks<?> networks = reader.networksWithin(network, includeAliasedNetworks, Map.class);
343343

344-
ArrayList<String> innerIPs = new ArrayList<>();
344+
List<String> innerIPs = new ArrayList<>();
345345
while(networks.hasNext()){
346-
DatabaseRecord<Map<String,String>> iteration = networks.next();
346+
DatabaseRecord<?> iteration = networks.next();
347347
innerIPs.add(iteration.getNetwork().toString());
348348
}
349349

@@ -376,11 +376,11 @@ public void testGeoIPNetworksWithin() throws IOException, InvalidNetworkExceptio
376376
InetAddress address = InetAddress.getByName(test.network);
377377
Network network = new Network(address, test.prefix);
378378

379-
Networks networks = reader.networksWithin(network, test.skipAliasedNetworks, Map.class);
379+
Networks<?> networks = reader.networksWithin(network, test.skipAliasedNetworks, Map.class);
380380

381381
ArrayList<String> innerIPs = new ArrayList<>();
382382
while(networks.hasNext()){
383-
DatabaseRecord<Map<String,String>> iteration = networks.next();
383+
DatabaseRecord<?> iteration = networks.next();
384384
innerIPs.add(iteration.getNetwork().toString());
385385
}
386386

@@ -408,7 +408,7 @@ public void testGetRecord() throws IOException {
408408
};
409409
for (GetRecordTest test : mapTests) {
410410
try (Reader reader = new Reader(test.db)) {
411-
DatabaseRecord record = reader.getRecord(test.ip, Map.class);
411+
DatabaseRecord<?> record = reader.getRecord(test.ip, Map.class);
412412

413413
assertEquals(test.network, record.getNetwork().toString());
414414

@@ -432,7 +432,7 @@ public void testGetRecord() throws IOException {
432432
};
433433
for (GetRecordTest test : stringTests) {
434434
try (Reader reader = new Reader(test.db)) {
435-
DatabaseRecord record = reader.getRecord(test.ip, String.class);
435+
DatabaseRecord<String> record = reader.getRecord(test.ip, String.class);
436436

437437
assertEquals(test.network, record.getNetwork().toString());
438438

@@ -497,7 +497,7 @@ public void testDecodingTypesPointerDecoderFile() throws IOException {
497497
}
498498

499499
private void testDecodingTypes(Reader reader, boolean booleanValue) throws IOException {
500-
Map record = reader.get(InetAddress.getByName("::1.1.1.0"), Map.class);
500+
Map<?, ?> record = reader.get(InetAddress.getByName("::1.1.1.0"), Map.class);
501501

502502
if (booleanValue) {
503503
assertTrue((boolean) record.get("boolean"));
@@ -510,21 +510,19 @@ private void testDecodingTypes(Reader reader, boolean booleanValue) throws IOExc
510510

511511
assertEquals("unicode! ☯ - ♫", record.get("utf8_string"));
512512

513-
@SuppressWarnings("unchecked")
514-
List<Object> array = (List<Object>) record.get("array");
513+
List<?> array = (List<?>) record.get("array");
515514
assertEquals(3, array.size());
516515
assertEquals(1, (long) array.get(0));
517516
assertEquals(2, (long) array.get(1));
518517
assertEquals(3, (long) array.get(2));
519518

520-
Map map = (Map) record.get("map");
519+
Map<?, ?> map = (Map<?, ?>) record.get("map");
521520
assertEquals(1, map.size());
522521

523-
Map mapX = (Map) map.get("mapX");
522+
Map<?, ?> mapX = (Map<?, ?>) map.get("mapX");
524523
assertEquals(2, mapX.size());
525524

526-
@SuppressWarnings("unchecked")
527-
List<Object> arrayX = (List<Object>) mapX.get("arrayX");
525+
List<?> arrayX = (List<?>) mapX.get("arrayX");
528526
assertEquals(3, arrayX.size());
529527
assertEquals(7, (long) arrayX.get(0));
530528
assertEquals(8, (long) arrayX.get(1));
@@ -816,19 +814,18 @@ public void testZerosStream() throws IOException {
816814
}
817815

818816
private void testZeros(Reader reader) throws IOException {
819-
Map record = reader.get(InetAddress.getByName("::"), Map.class);
817+
Map<?, ?> record = reader.get(InetAddress.getByName("::"), Map.class);
820818

821819
assertFalse((boolean) record.get("boolean"));
822820

823821
assertArrayEquals(new byte[0], (byte[]) record.get("bytes"));
824822

825823
assertEquals("", record.get("utf8_string"));
826824

827-
@SuppressWarnings("unchecked")
828-
List<Object> array = (List<Object>) record.get("array");
825+
List<?> array = (List<?>) record.get("array");
829826
assertEquals(0, array.size());
830827

831-
Map map = (Map) record.get("map");
828+
Map<?, ?> map = (Map<?, ?>) record.get("map");
832829
assertEquals(0, map.size());
833830

834831
assertEquals(0, (double) record.get("double"), 0.000000001);
@@ -1009,16 +1006,14 @@ public TestDataTypeMismatchInModel(
10091006
public void testDecodeConcurrentHashMap() throws IOException {
10101007
this.testReader = new Reader(getFile("GeoIP2-City-Test.mmdb"));
10111008

1012-
@SuppressWarnings("unchecked")
1013-
ConcurrentHashMap<String, Object> m = this.testReader.get(
1009+
Map<?, ?> m = this.testReader.get(
10141010
InetAddress.getByName("2.125.160.216"),
10151011
ConcurrentHashMap.class
10161012
);
10171013

1018-
@SuppressWarnings("unchecked")
1019-
List<Map<String, Object>> subdivisions = (List) m.get("subdivisions");
1014+
List<?> subdivisions = (List<?>) m.get("subdivisions");
10201015

1021-
Map<String, Object> eng = subdivisions.get(0);
1016+
Map<?, ?> eng = (Map<?, ?>) subdivisions.get(0);
10221017

10231018
String isoCode = (String) eng.get("iso_code");
10241019
assertEquals("ENG", isoCode);
@@ -1100,17 +1095,17 @@ public TestModelB(
11001095
public void testCacheKey() {
11011096
Class<TestModelCacheKey> cls = TestModelCacheKey.class;
11021097

1103-
CacheKey a = new CacheKey(1, cls, getType(cls, 0));
1104-
CacheKey b = new CacheKey(1, cls, getType(cls, 0));
1098+
CacheKey<TestModelCacheKey> a = new CacheKey<>(1, cls, getType(cls, 0));
1099+
CacheKey<TestModelCacheKey> b = new CacheKey<>(1, cls, getType(cls, 0));
11051100
assertEquals(a, b);
11061101

1107-
CacheKey c = new CacheKey(2, cls, getType(cls, 0));
1102+
CacheKey<TestModelCacheKey> c = new CacheKey<>(2, cls, getType(cls, 0));
11081103
assertNotEquals(a, c);
11091104

1110-
CacheKey d = new CacheKey(1, String.class, getType(cls, 0));
1105+
CacheKey<String> d = new CacheKey<>(1, String.class, getType(cls, 0));
11111106
assertNotEquals(a, d);
11121107

1113-
CacheKey e = new CacheKey(1, cls, getType(cls, 1));
1108+
CacheKey<TestModelCacheKey> e = new CacheKey<>(1, cls, getType(cls, 1));
11141109
assertNotEquals(a, e);
11151110
}
11161111

0 commit comments

Comments
 (0)