@Test public void testSomeLookups() throws IOException { IPLookup ipArt = new IPLookup(() -> new AdaptiveRadixTree<>(InetAddressBinaryComparable.INSTANCE)); IPLookup ipRbt = new IPLookup(() -> new TreeMap<>(InetAddressComparator.INSTANCE)); InetAddress inetAddress = InetAddress.getByName("61.11.0.1"); Optional<String> country = ipArt.lookup(inetAddress); assertTrue(country.isPresent()); assertEquals(country.get(), "India"); assertEquals(country, ipRbt.lookup(inetAddress)); inetAddress = InetAddress.getByName("61.11.127.255"); country = ipArt.lookup(inetAddress); assertTrue(country.isPresent()); assertEquals(country.get(), "India"); assertEquals(country, ipRbt.lookup(inetAddress)); inetAddress = InetAddress.getByName("61.11.0.0"); country = ipArt.lookup(inetAddress); assertTrue(country.isPresent()); assertEquals(country.get(), "India"); assertEquals(country, ipRbt.lookup(inetAddress)); inetAddress = InetAddress.getByName("0.0.0.0"); country = ipArt.lookup(inetAddress); assertFalse(country.isPresent()); assertEquals(country, ipRbt.lookup(inetAddress)); }
Optional<String> lookup(InetAddress lookup) { Map.Entry<InetAddress, Record> entry = m.floorEntry(lookup); if (entry != null) { InetAddress end = entry.getValue().getEnd(); if (InetAddressComparator.INSTANCE.compare(end, lookup) >= 0) { return Optional.of(entry.getValue().getCountry()); } } return Optional.empty(); }
IPLookup { Optional<String> lookup(InetAddress lookup) { Map.Entry<InetAddress, Record> entry = m.floorEntry(lookup); if (entry != null) { InetAddress end = entry.getValue().getEnd(); if (InetAddressComparator.INSTANCE.compare(end, lookup) >= 0) { return Optional.of(entry.getValue().getCountry()); } } return Optional.empty(); } }
IPLookup { Optional<String> lookup(InetAddress lookup) { Map.Entry<InetAddress, Record> entry = m.floorEntry(lookup); if (entry != null) { InetAddress end = entry.getValue().getEnd(); if (InetAddressComparator.INSTANCE.compare(end, lookup) >= 0) { return Optional.of(entry.getValue().getCountry()); } } return Optional.empty(); } IPLookup(Supplier<NavigableMap<InetAddress, Record>> s); }
IPLookup { Optional<String> lookup(InetAddress lookup) { Map.Entry<InetAddress, Record> entry = m.floorEntry(lookup); if (entry != null) { InetAddress end = entry.getValue().getEnd(); if (InetAddressComparator.INSTANCE.compare(end, lookup) >= 0) { return Optional.of(entry.getValue().getCountry()); } } return Optional.empty(); } IPLookup(Supplier<NavigableMap<InetAddress, Record>> s);  }
IPLookup { Optional<String> lookup(InetAddress lookup) { Map.Entry<InetAddress, Record> entry = m.floorEntry(lookup); if (entry != null) { InetAddress end = entry.getValue().getEnd(); if (InetAddressComparator.INSTANCE.compare(end, lookup) >= 0) { return Optional.of(entry.getValue().getCountry()); } } return Optional.empty(); } IPLookup(Supplier<NavigableMap<InetAddress, Record>> s);   }