class NpmMetadataUtils {

  @Nonnull
  public static NestedAttributesMap merge(final String key, final List<NestedAttributesMap> packages) {
    final NestedAttributesMap result = new NestedAttributesMap(key, Maps.<String, Object>newHashMap());
    String latestVersion = null;
    for (NestedAttributesMap pkg : packages) {
      String pkgLatestVersion = pkg.child(DIST_TAGS).get(LATEST, String.class);
      if (pkgLatestVersion != null
          && (latestVersion == null || versionComparator.compare(pkgLatestVersion, latestVersion) > 0)) {
        latestVersion = pkgLatestVersion;
      }
      overlay(result.backing(), pkg.backing(), false);
    }
    result.child(DIST_TAGS).set(LATEST, latestVersion);
    result.remove(META_ID);
    result.remove(META_REV);

    return result;
  }

  private  NpmMetadataUtils();

}