package com.hubspot.blazar.discovery.hsstatic;

import java.util.Collections;
import java.util.Map;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.base.Objects;

public class StaticConfig {

  private final String name;
  private final int majorVersion;
  private final boolean isCurrentVersion;
  private Map<String, Integer> runtimeDeps;
  private final Map<String, Integer> deps;

  @JsonCreator
  public StaticConfig(@JsonProperty("name") String name,
                      @JsonProperty("majorVersion") int majorVersion,
                      @JsonProperty("isCurrentVersion") boolean isCurrentVersion,
                      @JsonProperty("runtimeDeps") Map<String, Integer> runtimeDeps,
                      @JsonProperty("deps") Map<String, Integer> deps) {
    this.name = name;
    this.majorVersion = majorVersion;
    this.isCurrentVersion = isCurrentVersion;
    this.runtimeDeps = Objects.firstNonNull(runtimeDeps, Collections.<String, Integer>emptyMap());
    this.deps = Objects.firstNonNull(deps, Collections.<String, Integer>emptyMap());
  }

  public String getName() {
    return name;
  }

  public int getMajorVersion() {
    return majorVersion;
  }

  public boolean isCurrentVersion() {
    return isCurrentVersion;
  }

  public Map<String, Integer> getRuntimeDeps() {
    return runtimeDeps;
  }

  public Map<String, Integer> getDeps() {
    return deps;
  }
}

@@ -88,19 +88,67 @@
 va.util.
-Map
+HashSet;%0Aimport java.util.Map;%0Aimport java.util.Set
 ;%0A%0Aimpor
@@ -279,23 +279,138 @@
 on.base.
-Objects
+Function;%0Aimport com.google.common.base.Splitter;%0Aimport com.google.common.collect.Maps;%0A%0Aimport javax.annotation.Nullable
 ;%0A%0Apubli
@@ -905,39 +905,38 @@
 s%22) Map%3CString, 
-Integer
+String
 %3E runtimeDeps,%0A 
@@ -986,31 +986,30 @@
 Map%3CString, 
-Integer
+String
 %3E deps) %7B%0A  
@@ -1139,166 +1139,80 @@
 s = 
-Objects.firstNonNull(runtimeDeps, Collections.%3CString, Integer%3EemptyMap());%0A    this.deps = Objects.firstNonNull(deps, Collections.%3CString, Integer%3EemptyMap()
+parseMajorVersions(runtimeDeps);%0A    this.deps = parseMajorVersions(deps
 );%0A 
@@ -1540,11 +1540,824 @@
 eps;%0A  %7D
+%0A%0A  private static Map%3CString, Integer%3E parseMajorVersions(@Nullable Map%3CString, String%3E versionMap) %7B%0A    if (versionMap == null) %7B%0A      return Collections.emptyMap();%0A    %7D%0A%0A    return Maps.transformValues(versionMap, new Function%3CString, Integer%3E() %7B%0A%0A      @Override%0A      public Integer apply(String input) %7B%0A        Set%3CInteger%3E majorVersions = new HashSet%3C%3E();%0A        for (String version : Splitter.on(%22%7C%7C%22).trimResults().split(input)) %7B%0A          final int majorVersion;%0A          if (version.contains(%22.%22)) %7B%0A            majorVersion = Integer.valueOf(version.substring(0, version.indexOf('.')));%0A          %7D else %7B%0A            majorVersion = Integer.valueOf(version);%0A          %7D%0A%0A          majorVersions.add(majorVersion);%0A        %7D%0A%0A        return Collections.max(majorVersions);%0A      %7D%0A    %7D);%0A  %7D
 %0A%7D%0A

Support pipe-separated major versions