예제 #1
0
 public Builder addType(ResourceType type) {
   Preconditions.checkNotNull(type);
   Preconditions.checkArgument(
       !types.contains(type), String.format("%s is already registered", type.getQualifier()));
   types.add(type);
   return this;
 }
예제 #2
0
 public ResourceTypeTree build() {
   Collection<String> children = relations.values();
   for (ResourceType type : types) {
     if (!children.contains(type.getQualifier())) {
       root = type;
       break;
     }
   }
   return new ResourceTypeTree(this);
 }
예제 #3
0
  public ResourceTypes(ResourceTypeTree[] trees) {
    Preconditions.checkNotNull(trees);

    Map<String, ResourceTypeTree> treeMap = Maps.newHashMap();
    Map<String, ResourceType> typeMap = Maps.newLinkedHashMap();
    Collection<ResourceType> rootsSet = Sets.newHashSet();

    for (ResourceTypeTree tree : trees) {
      rootsSet.add(tree.getRootType());
      for (ResourceType type : tree.getTypes()) {
        if (treeMap.containsKey(type.getQualifier())) {
          throw new IllegalStateException(
              "Qualifier " + type.getQualifier() + " is defined in several trees");
        }
        treeMap.put(type.getQualifier(), tree);
        typeMap.put(type.getQualifier(), type);
      }
    }
    treeByQualifier = ImmutableMap.copyOf(treeMap);
    typeByQualifier = ImmutableMap.copyOf(typeMap);
    rootTypes = ImmutableList.copyOf(rootsSet);
  }
예제 #4
0
 @Override
 public String toString() {
   return root.getQualifier();
 }