Exemplo n.º 1
0
  String determineClassName(int uniqueRound) {
    AddressTemplate address = this.meta.get(0).getAddress();

    String type = address.getResourceType();
    String name = address.getResourceName();

    String clsName = null;

    if (address.tokenLength() == 1 && type.equals("subsystem")) {
      clsName = CaseFormat.LOWER_HYPHEN.to(CaseFormat.UPPER_CAMEL, name);
    } else if (name.equals("*")) {
      clsName = CaseFormat.LOWER_HYPHEN.to(CaseFormat.UPPER_CAMEL, type);
    } else {
      if (type.toLowerCase().startsWith(name.toLowerCase())) {
        clsName = CaseFormat.LOWER_HYPHEN.to(CaseFormat.UPPER_CAMEL, type);
      } else if (name.toLowerCase().endsWith(type.toLowerCase())) {
        clsName = CaseFormat.LOWER_HYPHEN.to(CaseFormat.UPPER_CAMEL, name);
      } else if (name.contains(".")) {
        int dotLoc = name.indexOf(".");
        this.packageName = this.packageName + "." + name.substring(0, dotLoc);
        String rest = name.substring(dotLoc + 1);
        if (rest.chars().allMatch(c -> Character.isUpperCase(c) || Character.isDigit(c))) {
          clsName = rest;
        } else {
          clsName = CaseFormat.LOWER_HYPHEN.to(CaseFormat.UPPER_CAMEL, rest);
        }
      } else {
        clsName = CaseFormat.LOWER_HYPHEN.to(CaseFormat.UPPER_CAMEL, name + "-" + type);
      }
    }

    return clsName;
  }
Exemplo n.º 2
0
  String determinePackageName(int uniqueRound) {
    if (this.meta.size() == 1) {
      AddressTemplate address = this.meta.get(0).getAddress();

      int numTokens = address.tokenLength() - 1;

      List<String> segments = determineSegments(address, uniqueRound);

      return packagize(segments);
    }

    List<List<String>> allSegments = new ArrayList<>();

    for (ResourceMetaData resourceMetaData : this.meta) {
      allSegments.add(determineSegments(resourceMetaData.getAddress(), uniqueRound));
    }

    List<String> commonSegments = new ArrayList<>();

    int i = 0;
    OUTER:
    while (true) {

      String cur = null;

      INNER:
      for (List<String> each : allSegments) {
        if (!(each.size() > i)) {
          break OUTER;
        }

        if (cur == null) {
          cur = each.get(i);
        } else {
          if (!cur.equals(each.get(i))) {
            break OUTER;
          }
        }
      }

      commonSegments.add(cur);
      cur = null;
      ++i;
    }

    return packagize(commonSegments);
  }
Exemplo n.º 3
0
  private List<String> determineSegments(AddressTemplate address, int uniqueRound) {

    int numTokens = address.tokenLength() - 1;

    List<String> segments = new ArrayList<>();

    for (int i = 0; i < numTokens; ++i) {
      AddressTemplate part = address.subTemplate(i, i + 1);
      if (i == 0) {
        segments.add(part.getResourceName());
      } else {
        if (i >= ((numTokens - uniqueRound))) {
          segments.add(part.getResourceType());
          if (!part.getResourceName().equals("*")) {
            segments.add(part.getResourceName());
          }
        } else {
          segments.add(part.getResourceType());
        }
      }
    }

    return segments;
  }