class 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()
                                          // we are ignoring child groups; their IPs will be caught
                                          // when we process that group itself
                                          .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();

}