예제 #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;
  }
예제 #2
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;
  }
예제 #3
0
  /**
   * Construct a class plan for set of identical resources.
   *
   * @param meta
   */
  ClassPlan(List<ResourceMetaData> meta) {

    // type assertion to make things more obvious
    ResourceMetaData prime = meta.get(0);
    String primeType = prime.getAddress().getResourceType();
    meta.forEach(
        resourceMetaData -> {
          String resourceType = resourceMetaData.getAddress().getResourceType();
          if (!resourceType.equals(primeType))
            throw new IllegalArgumentException(
                "Illegal partition, resourceType's don't match: "
                    + primeType
                    + " > "
                    + resourceType);
        });

    this.meta.addAll(meta);
    this.addr = prime.getAddress();
    this.packageName = determinePackageName(0);
    this.originalClassName = determineClassName(0);
    this.className = NameFixer.fixClassName(this.originalClassName);

    this.type = addr.getResourceType();
  }