class UrlUtils {

  public static Map<String, Map<String, String>> revertNotify(Map<String, Map<String, String>> notify) {
    if (notify != null && notify.size() > 0) {
      Map<String, Map<String, String>> newNotify = new HashMap<String, Map<String, String>>();
      for (Map.Entry<String, Map<String, String>> entry : notify.entrySet()) {
        String serviceName = entry.getKey();
        Map<String, String> serviceUrls = entry.getValue();
        if (!serviceName.contains(":") && !serviceName.contains("/")) {
          if (serviceUrls != null && serviceUrls.size() > 0) {
            for (Map.Entry<String, String> entry2 : serviceUrls.entrySet()) {
              String url = entry2.getKey();
              String query = entry2.getValue();
              Map<String, String> params = StringUtils.parseQueryString(query);
              String group = params.get("group");
              String version = params.get("version");
              // params.remove("group");
              // params.remove("version");
              String name = serviceName;
              if (group != null && group.length() > 0) {
                name = group + "/" + name;
              }
              if (version != null && version.length() > 0) {
                name = name + ":" + version;
              }
              Map<String, String> newUrls = newNotify.get(name);
              if (newUrls == null) {
                newUrls = new HashMap<String, String>();
                newNotify.put(name, newUrls);
              }
              newUrls.put(url, StringUtils.toQueryString(params));
            }
          }
        } else {
          newNotify.put(serviceName, serviceUrls);
        }
      }
      return newNotify;
    }
    return notify;
  }

}