Move TypeDefinitions into yang-model-api
[yangtools.git] / yang / yang-model-util / src / main / java / org / opendaylight / yangtools / yang / model / util / type / IdentityrefTypeBuilder.java
index b31994f36e59f193cfedba31ad5142997e650c1f..d71b30819f9e4837c196ffdfbf84990b0756f87f 100644 (file)
@@ -7,27 +7,32 @@
  */
 package org.opendaylight.yangtools.yang.model.util.type;
 
-import com.google.common.base.Preconditions;
+import static com.google.common.base.Preconditions.checkState;
+
+import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.ImmutableSet.Builder;
+import java.util.Set;
 import javax.annotation.Nonnull;
 import org.opendaylight.yangtools.yang.model.api.IdentitySchemaNode;
 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
 import org.opendaylight.yangtools.yang.model.api.type.IdentityrefTypeDefinition;
 
 public final class IdentityrefTypeBuilder extends TypeBuilder<IdentityrefTypeDefinition> {
-    private IdentitySchemaNode identity;
+    private final Builder<IdentitySchemaNode> builder = ImmutableSet.builder();
 
     IdentityrefTypeBuilder(final SchemaPath path) {
         super(null, path);
     }
 
-    public IdentityrefTypeBuilder setIdentity(@Nonnull final IdentitySchemaNode identity) {
-        Preconditions.checkState(this.identity == null, "Identity already set to %s", this.identity);
-        this.identity = Preconditions.checkNotNull(identity);
+    public IdentityrefTypeBuilder addIdentity(@Nonnull final IdentitySchemaNode identity) {
+        builder.add(identity);
         return this;
     }
 
     @Override
     public IdentityrefTypeDefinition build() {
-        return new BaseIdentityrefType(getPath(), getUnknownSchemaNodes(), identity);
+        final Set<IdentitySchemaNode> identities = builder.build();
+        checkState(!identities.isEmpty(), "No identities specified in %s, at least one is required", getPath());
+        return new BaseIdentityrefType(getPath(), getUnknownSchemaNodes(), identities);
     }
 }