X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fsal%2Fyang-prototype%2Fyang%2Fyang-model-util%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fyang%2Fmodel%2Futil%2FUnionType.java;h=1063f3b22b6bfe4720af2539803f6296875c9c72;hb=refs%2Fchanges%2F60%2F260%2F2;hp=ad40393291d748a0a428fed9674789589e0e0d0e;hpb=184e4f61d034f6c83da75de288d4f56ec48f60bf;p=controller.git diff --git a/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/UnionType.java b/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/UnionType.java index ad40393291..1063f3b22b 100644 --- a/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/UnionType.java +++ b/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/UnionType.java @@ -7,7 +7,9 @@ */ package org.opendaylight.controller.yang.model.util; +import java.net.URI; import java.util.Collections; +import java.util.Date; import java.util.List; import org.opendaylight.controller.yang.common.QName; @@ -20,23 +22,34 @@ import org.opendaylight.controller.yang.model.api.type.UnionTypeDefinition; public class UnionType implements UnionTypeDefinition { private final QName name = BaseTypes.constructQName("union"); - private final SchemaPath path = BaseTypes.schemaPath(name); + private final SchemaPath path; private final String description = "The union built-in type represents a value that corresponds to one of its member types."; private final String reference = "https://tools.ietf.org/html/rfc6020#section-9.12"; - + private final UnionTypeDefinition baseType; private final List> types; + private UnionType(List> types) { + if(types == null) { + throw new NullPointerException("When the type is 'union', the 'type' statement MUST be present."); + } + path = BaseTypes.schemaPath(name); + this.types = types; + this.baseType = this; + } - public UnionType(List> types) { + public UnionType(final List actualPath, final URI namespace, + final Date revision, List> types) { if(types == null) { throw new NullPointerException("When the type is 'union', the 'type' statement MUST be present."); } + path = BaseTypes.schemaPath(actualPath, namespace, revision); this.types = types; + this.baseType = new UnionType(types); } @Override public UnionTypeDefinition getBaseType() { - return this; + return baseType; } @Override @@ -86,8 +99,12 @@ public class UnionType implements UnionTypeDefinition { @Override public int hashCode() { - // TODO: implement hashcode - return 4; + final int prime = 31; + int result = 1; + result = prime * result + ((name == null) ? 0 : name.hashCode()); + result = prime * result + ((path == null) ? 0 : path.hashCode()); + result = prime * result + ((types == null) ? 0 : types.hashCode()); + return result; } @Override