class UrlUtils {

  public static Map<String, String> revertSubscribe(Map<String, String> subscribe) {
    Map<String, String> newSubscribe = new HashMap<String, String>();
    for (Map.Entry<String, String> entry : subscribe.entrySet()) {
      String serviceName = entry.getKey();
      String serviceQuery = entry.getValue();
      if (serviceName.contains(":") || serviceName.contains("/")) {
        Map<String, String> params = StringUtils.parseQueryString(serviceQuery);
        String name = serviceName;
        int i = name.indexOf('/');
        if (i >= 0) {
          params.put("group", name.substring(0, i));
          name = name.substring(i + 1);
        }
        i = name.lastIndexOf(':');
        if (i >= 0) {
          params.put("version", name.substring(i + 1));
          name = name.substring(0, i);
        }
        newSubscribe.put(name, StringUtils.toQueryString(params));
      } else {
        newSubscribe.put(serviceName, serviceQuery);
      }
    }
    return newSubscribe;
  }

}