@Test public void testGetIps() { String nodeName = "nodeName"; String int1 = "int1"; String int2 = "int2"; Ip ip1 = Ip.parse("10.1.3.7"); Ip ip2 = Ip.parse("128.212.155.30"); Ip ip3 = Ip.parse("124.51.32.2"); String address1 = ip1 + "/30"; String address2 = ip2 + "/24"; String address3 = ip3 + "/20"; InterfaceAddress interfaceAddress1 = ConcreteInterfaceAddress.parse(address1); InterfaceAddress interfaceAddress2 = ConcreteInterfaceAddress.parse(address2); InterfaceAddress interfaceAddress3 = ConcreteInterfaceAddress.parse(address3); Map<String, Configuration> configs = new HashMap<>(); Configuration config = createTestConfiguration(nodeName, ConfigurationFormat.HOST, int1, int2); Interface iface1 = config.getAllInterfaces().get(int1); iface1.setAllAddresses(ImmutableSet.of(interfaceAddress1, interfaceAddress2)); Interface iface2 = config.getAllInterfaces().get(int2); iface2.setAllAddresses(ImmutableSet.of(interfaceAddress2, interfaceAddress3)); configs.put(nodeName, config); assertThat( getIps(configs), equalTo( ImmutableMap.builder() .put( ip1, new IpCompletionMetadata( new IpCompletionRelevance( interfaceDisplayString(config, iface1), config.getHostname(), iface1.getName()))) .put( ip2, new IpCompletionMetadata( ImmutableList.of( new IpCompletionRelevance( interfaceDisplayString(config, iface1), config.getHostname(), iface1.getName()), new IpCompletionRelevance( interfaceDisplayString(config, iface2), config.getHostname(), iface2.getName())))) .put( ip3, new IpCompletionMetadata( new IpCompletionRelevance( interfaceDisplayString(config, iface2), config.getHostname(), iface2.getName()))) .putAll(createWellKnownIpCompletion(WELL_KNOWN_IPS)) .build())); }
public static Map<Ip, IpCompletionMetadata> getIps(Map<String, Configuration> configurations) { Map<Ip, IpCompletionMetadata> ips = new HashMap<>(); configurations .values() .forEach( configuration -> { configuration .getAllInterfaces() .values() .forEach( iface -> iface.getAllConcreteAddresses().stream() .map(interfaceAddress -> interfaceAddress.getIp()) .forEach( ip -> ips.computeIfAbsent(ip, k -> new IpCompletionMetadata()) .addRelevance( new IpCompletionRelevance( interfaceDisplayString(configuration, iface), configuration.getHumanName(), configuration.getHostname(), iface.getName())))); configuration .getGeneratedReferenceBooks() .values() .forEach( book -> book.getAddressGroups() .forEach( ag -> ag.getAddresses() .forEach( a -> addGeneratedRefBookAddress( a, configuration, book.getName(), ag.getName(), ips)))); }); WELL_KNOWN_IPS.forEach( (ip, description) -> { if (!ips.containsKey(ip)) { ips.put( ip, new IpCompletionMetadata(new IpCompletionRelevance(description, description))); } }); return ImmutableMap.copyOf(ips); }
CompletionMetadataUtils { public static Map<Ip, IpCompletionMetadata> getIps(Map<String, Configuration> configurations) { Map<Ip, IpCompletionMetadata> ips = new HashMap<>(); configurations .values() .forEach( configuration -> { configuration .getAllInterfaces() .values() .forEach( iface -> iface.getAllConcreteAddresses().stream() .map(interfaceAddress -> interfaceAddress.getIp()) .forEach( ip -> ips.computeIfAbsent(ip, k -> new IpCompletionMetadata()) .addRelevance( new IpCompletionRelevance( interfaceDisplayString(configuration, iface), configuration.getHumanName(), configuration.getHostname(), iface.getName())))); configuration .getGeneratedReferenceBooks() .values() .forEach( book -> book.getAddressGroups() .forEach( ag -> ag.getAddresses() .forEach( a -> addGeneratedRefBookAddress( a, configuration, book.getName(), ag.getName(), ips)))); }); WELL_KNOWN_IPS.forEach( (ip, description) -> { if (!ips.containsKey(ip)) { ips.put( ip, new IpCompletionMetadata(new IpCompletionRelevance(description, description))); } }); return ImmutableMap.copyOf(ips); } }
CompletionMetadataUtils { public static Map<Ip, IpCompletionMetadata> getIps(Map<String, Configuration> configurations) { Map<Ip, IpCompletionMetadata> ips = new HashMap<>(); configurations .values() .forEach( configuration -> { configuration .getAllInterfaces() .values() .forEach( iface -> iface.getAllConcreteAddresses().stream() .map(interfaceAddress -> interfaceAddress.getIp()) .forEach( ip -> ips.computeIfAbsent(ip, k -> new IpCompletionMetadata()) .addRelevance( new IpCompletionRelevance( interfaceDisplayString(configuration, iface), configuration.getHumanName(), configuration.getHostname(), iface.getName())))); configuration .getGeneratedReferenceBooks() .values() .forEach( book -> book.getAddressGroups() .forEach( ag -> ag.getAddresses() .forEach( a -> addGeneratedRefBookAddress( a, configuration, book.getName(), ag.getName(), ips)))); }); WELL_KNOWN_IPS.forEach( (ip, description) -> { if (!ips.containsKey(ip)) { ips.put( ip, new IpCompletionMetadata(new IpCompletionRelevance(description, description))); } }); return ImmutableMap.copyOf(ips); } private  CompletionMetadataUtils(); }
CompletionMetadataUtils { public static Map<Ip, IpCompletionMetadata> getIps(Map<String, Configuration> configurations) { Map<Ip, IpCompletionMetadata> ips = new HashMap<>(); configurations .values() .forEach( configuration -> { configuration .getAllInterfaces() .values() .forEach( iface -> iface.getAllConcreteAddresses().stream() .map(interfaceAddress -> interfaceAddress.getIp()) .forEach( ip -> ips.computeIfAbsent(ip, k -> new IpCompletionMetadata()) .addRelevance( new IpCompletionRelevance( interfaceDisplayString(configuration, iface), configuration.getHumanName(), configuration.getHostname(), iface.getName())))); configuration .getGeneratedReferenceBooks() .values() .forEach( book -> book.getAddressGroups() .forEach( ag -> ag.getAddresses() .forEach( a -> addGeneratedRefBookAddress( a, configuration, book.getName(), ag.getName(), ips)))); }); WELL_KNOWN_IPS.forEach( (ip, description) -> { if (!ips.containsKey(ip)) { ips.put( ip, new IpCompletionMetadata(new IpCompletionRelevance(description, description))); } }); return ImmutableMap.copyOf(ips); } private  CompletionMetadataUtils(); static Set<String> getFilterNames(Map<String, Configuration> configurations); static Set<NodeInterfacePair> getInterfaces(Map<String, Configuration> configurations); static Map<Ip, IpCompletionMetadata> getIps(Map<String, Configuration> configurations); static Set<String> getMlagIds(Map<String, Configuration> configurations); static Map<String, NodeCompletionMetadata> getNodes(
      Map<String, Configuration> configurations); static Set<String> getPrefixes(Map<String, Configuration> configurations); static Set<String> getRoutingPolicyNames(Map<String, Configuration> configurations); static Set<Location> getSourceLocationsWithSrcIps(
      Map<Location, LocationInfo> locationInfo); static Set<String> getStructureNames(Map<String, Configuration> configurations); static Set<String> getVrfs(Map<String, Configuration> configurations); static Set<String> getZones(Map<String, Configuration> configurations); }
CompletionMetadataUtils { public static Map<Ip, IpCompletionMetadata> getIps(Map<String, Configuration> configurations) { Map<Ip, IpCompletionMetadata> ips = new HashMap<>(); configurations .values() .forEach( configuration -> { configuration .getAllInterfaces() .values() .forEach( iface -> iface.getAllConcreteAddresses().stream() .map(interfaceAddress -> interfaceAddress.getIp()) .forEach( ip -> ips.computeIfAbsent(ip, k -> new IpCompletionMetadata()) .addRelevance( new IpCompletionRelevance( interfaceDisplayString(configuration, iface), configuration.getHumanName(), configuration.getHostname(), iface.getName())))); configuration .getGeneratedReferenceBooks() .values() .forEach( book -> book.getAddressGroups() .forEach( ag -> ag.getAddresses() .forEach( a -> addGeneratedRefBookAddress( a, configuration, book.getName(), ag.getName(), ips)))); }); WELL_KNOWN_IPS.forEach( (ip, description) -> { if (!ips.containsKey(ip)) { ips.put( ip, new IpCompletionMetadata(new IpCompletionRelevance(description, description))); } }); return ImmutableMap.copyOf(ips); } private  CompletionMetadataUtils(); static Set<String> getFilterNames(Map<String, Configuration> configurations); static Set<NodeInterfacePair> getInterfaces(Map<String, Configuration> configurations); static Map<Ip, IpCompletionMetadata> getIps(Map<String, Configuration> configurations); static Set<String> getMlagIds(Map<String, Configuration> configurations); static Map<String, NodeCompletionMetadata> getNodes(
      Map<String, Configuration> configurations); static Set<String> getPrefixes(Map<String, Configuration> configurations); static Set<String> getRoutingPolicyNames(Map<String, Configuration> configurations); static Set<Location> getSourceLocationsWithSrcIps(
      Map<Location, LocationInfo> locationInfo); static Set<String> getStructureNames(Map<String, Configuration> configurations); static Set<String> getVrfs(Map<String, Configuration> configurations); static Set<String> getZones(Map<String, Configuration> configurations); static Map<Ip, String> WELL_KNOWN_IPS; }