Use Objects.hashCode()
[yangtools.git] / yang / yang-parser-impl / src / main / java / org / opendaylight / yangtools / yang / parser / builder / impl / TypeDefinitionBuilderImpl.java
index 07afa895d3ccdd1068afc1f3c809cbae809e5152..42104ddeccd496ce3515d378a710d92006da0050 100644 (file)
@@ -7,9 +7,11 @@
  */
 package org.opendaylight.yangtools.yang.parser.builder.impl;
 
+import com.google.common.base.Optional;
 import com.google.common.base.Preconditions;
 import java.util.Collections;
 import java.util.List;
+import java.util.Objects;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
 import org.opendaylight.yangtools.yang.model.api.Status;
@@ -18,7 +20,6 @@ import org.opendaylight.yangtools.yang.model.api.type.LengthConstraint;
 import org.opendaylight.yangtools.yang.model.api.type.PatternConstraint;
 import org.opendaylight.yangtools.yang.model.api.type.RangeConstraint;
 import org.opendaylight.yangtools.yang.model.util.ExtendedType;
-import org.opendaylight.yangtools.yang.model.util.UnknownType;
 import org.opendaylight.yangtools.yang.parser.builder.api.TypeDefinitionBuilder;
 import org.opendaylight.yangtools.yang.parser.builder.api.UnknownSchemaNodeBuilder;
 import org.opendaylight.yangtools.yang.parser.builder.util.AbstractTypeAwareBuilder;
@@ -67,14 +68,16 @@ public final class TypeDefinitionBuilderImpl extends AbstractTypeAwareBuilder im
     public TypeDefinition<? extends TypeDefinition<?>> build() {
         TypeDefinition<?> result;
         ExtendedType.Builder typeBuilder;
-        if ((type == null || type instanceof UnknownType) && typedef == null) {
-            throw new YangParseException("Unresolved type: '" + qname.getLocalName() + "'.");
-        }
-        if (type == null || type instanceof UnknownType) {
-            type = typedef.build();
+        if (type == null) {
+            if (typedef == null) {
+                throw new YangParseException("Unresolved type: '" + qname.getLocalName() + "'.");
+            } else {
+                type = typedef.build();
+            }
         }
 
-        typeBuilder = new ExtendedType.Builder(qname, type, description, reference, schemaPath);
+        typeBuilder = ExtendedType.builder(qname, type, Optional.fromNullable(description),
+                Optional.fromNullable(reference), schemaPath);
         typeBuilder.status(status);
         typeBuilder.units(units);
         typeBuilder.defaultValue(defaultValue);
@@ -171,11 +174,6 @@ public final class TypeDefinitionBuilderImpl extends AbstractTypeAwareBuilder im
         this.defaultValue = defaultValue;
     }
 
-    @Override
-    public List<UnknownSchemaNodeBuilder> getUnknownNodes() {
-        return Collections.emptyList();
-    }
-
     @Override
     public List<RangeConstraint> getRanges() {
         return ranges;
@@ -231,7 +229,7 @@ public final class TypeDefinitionBuilderImpl extends AbstractTypeAwareBuilder im
     public int hashCode() {
         final int prime = 31;
         int result = super.hashCode();
-        result = prime * result + ((schemaPath == null) ? 0 : schemaPath.hashCode());
+        result = prime * result + Objects.hashCode(schemaPath);
 
         return result;
     }