예제 #1
0
  public Source findParent(String prefix, Source source) {
    while (source != null && !hasPrefix(prefix, source)) {
      source = source.getParent();
    }

    return source;
  }
예제 #2
0
  public Source findRoot(String prefix, Source source) {
    Source parent = findParent(prefix, source);
    int parents = new StringTokenizer(prefix, ".").countTokens();
    for (int i = 0; i < parents; i++) {
      parent = parent.getParent();
    }

    return parent;
  }
예제 #3
0
  public boolean hasPrefix(String prefix, Source source) {
    List packages = CollectionUtil.toList(new StringTokenizer(prefix, "."));
    Collections.reverse(packages);

    for (int i = 0; i < packages.size(); i++) {
      String aPackage = (String) packages.get(i);
      if (!aPackage.equals(source.getName())) {
        return false;
      }
      source = source.getParent();
    }
    return true;
  }