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; }
public ResourceTypeTree build() { Collection<String> children = relations.values(); for (ResourceType type : types) { if (!children.contains(type.getQualifier())) { root = type; break; } } return new ResourceTypeTree(this); }
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); }
@Override public String toString() { return root.getQualifier(); }