@Test public void testNetTree3() throws Exception { List<String> ips = new ArrayList<>(); NetworkOrganizer.VirtualTree tree = new NetworkOrganizer.VirtualTree(); for (int i = 0; i < 3000; i++) ips.add(getRandomIp()); for (int i = 0; i < 20; i++) ips.add("192.168.12." + i); Collections.shuffle(ips); Set<String> uniqueIps = new HashSet<>(ips); for (String ip : uniqueIps) tree.map(NetworkOrganizer.convertIpToOctets(ip)); assertEquals(uniqueIps.size(), tree.getTotalBranches()); assertEquals(uniqueIps.size(), tree.getUniqueBranches()); }
protected static String convertIpToOctets(@NonNull String ip) { String[] octets = ip.split("\\."); if (octets.length != 4) throw new UnsupportedOperationException(); StringBuilder builder = new StringBuilder(); for (int i = 0; i < 3; i++) builder.append(toBinaryOctet(octets[i])).append("."); builder.append(toBinaryOctet(octets[3])); return builder.toString(); }
NetworkOrganizer { protected static String convertIpToOctets(@NonNull String ip) { String[] octets = ip.split("\\."); if (octets.length != 4) throw new UnsupportedOperationException(); StringBuilder builder = new StringBuilder(); for (int i = 0; i < 3; i++) builder.append(toBinaryOctet(octets[i])).append("."); builder.append(toBinaryOctet(octets[3])); return builder.toString(); } }
NetworkOrganizer { protected static String convertIpToOctets(@NonNull String ip) { String[] octets = ip.split("\\."); if (octets.length != 4) throw new UnsupportedOperationException(); StringBuilder builder = new StringBuilder(); for (int i = 0; i < 3; i++) builder.append(toBinaryOctet(octets[i])).append("."); builder.append(toBinaryOctet(octets[3])); return builder.toString(); } protected  NetworkOrganizer(@NonNull Collection<NetworkInformation> infoSet);  NetworkOrganizer(@NonNull Collection<NetworkInformation> infoSet, String mask);  NetworkOrganizer(@NonNull String networkMask); }
NetworkOrganizer { protected static String convertIpToOctets(@NonNull String ip) { String[] octets = ip.split("\\."); if (octets.length != 4) throw new UnsupportedOperationException(); StringBuilder builder = new StringBuilder(); for (int i = 0; i < 3; i++) builder.append(toBinaryOctet(octets[i])).append("."); builder.append(toBinaryOctet(octets[3])); return builder.toString(); } protected  NetworkOrganizer(@NonNull Collection<NetworkInformation> infoSet);  NetworkOrganizer(@NonNull Collection<NetworkInformation> infoSet, String mask);  NetworkOrganizer(@NonNull String networkMask); String getMatchingAddress(); List<String> getSubset(int numShards); List<String> getSubset(int numShards, Collection<String> primary); }
NetworkOrganizer { protected static String convertIpToOctets(@NonNull String ip) { String[] octets = ip.split("\\."); if (octets.length != 4) throw new UnsupportedOperationException(); StringBuilder builder = new StringBuilder(); for (int i = 0; i < 3; i++) builder.append(toBinaryOctet(octets[i])).append("."); builder.append(toBinaryOctet(octets[3])); return builder.toString(); } protected  NetworkOrganizer(@NonNull Collection<NetworkInformation> infoSet);  NetworkOrganizer(@NonNull Collection<NetworkInformation> infoSet, String mask);  NetworkOrganizer(@NonNull String networkMask); String getMatchingAddress(); List<String> getSubset(int numShards); List<String> getSubset(int numShards, Collection<String> primary);  }