BUG-865: deprecate pre-Beryllium parser elements
[yangtools.git] / yang / yang-parser-impl / src / main / java / org / opendaylight / yangtools / yang / parser / builder / impl / ModuleBuilder.java
index 120ebad9575f78081406eaa581fc3b203931042b..79e992028dc52f7e2ee3f299393f9b9e7e9c7f19 100644 (file)
@@ -1,9 +1,11 @@
 /*
- * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
+ * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
+ *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
+
 package org.opendaylight.yangtools.yang.parser.builder.impl;
 
 import com.google.common.base.Charsets;
@@ -21,6 +23,7 @@ import java.util.LinkedHashSet;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
+import java.util.Objects;
 import java.util.Set;
 import java.util.TreeSet;
 import org.opendaylight.yangtools.yang.common.QName;
@@ -58,9 +61,12 @@ import org.opendaylight.yangtools.yang.parser.util.YangParseException;
  * Builder of Module object. If this module is dependent on external
  * module/modules, these dependencies must be resolved before module is built,
  * otherwise result may not be valid.
+ *
+ * @deprecated Pre-Beryllium implementation, scheduled for removal.
  */
+@Deprecated
 public class ModuleBuilder extends AbstractDocumentedDataNodeContainerBuilder implements DocumentedNodeBuilder {
-
+    private static final QNameModule EMPTY_QNAME_MODULE = QNameModule.create(null, null).intern();
     private static final String GROUPING_STR = "Grouping";
     private static final String TYPEDEF_STR = "typedef";
     private ModuleImpl instance;
@@ -68,7 +74,7 @@ public class ModuleBuilder extends AbstractDocumentedDataNodeContainerBuilder im
     private final String sourcePath;
     private static final SchemaPath SCHEMA_PATH = SchemaPath.create(Collections.<QName> emptyList(), true);
     private String prefix;
-    private QNameModule qnameModule = QNameModule.create(null, null);
+    private QNameModule qnameModule = EMPTY_QNAME_MODULE;
 
     private final boolean submodule;
     private String belongsTo;
@@ -346,7 +352,7 @@ public class ModuleBuilder extends AbstractDocumentedDataNodeContainerBuilder im
     }
 
     public void setNamespace(final URI namespace) {
-        this.qnameModule = QNameModule.create(namespace, qnameModule.getRevision());
+        this.qnameModule = QNameModule.create(namespace, qnameModule.getRevision()).intern();
     }
 
     public String getPrefix() {
@@ -408,7 +414,7 @@ public class ModuleBuilder extends AbstractDocumentedDataNodeContainerBuilder im
     }
 
     public void setRevision(final Date revision) {
-        this.qnameModule = QNameModule.create(qnameModule.getNamespace(), revision);
+        this.qnameModule = QNameModule.create(qnameModule.getNamespace(), revision).intern();
     }
 
     public void setPrefix(final String prefix) {
@@ -430,7 +436,7 @@ public class ModuleBuilder extends AbstractDocumentedDataNodeContainerBuilder im
     public void addModuleImport(final String moduleName, final Date revision, final String prefix) {
         checkPrefix(prefix);
         checkNotSealed();
-        final ModuleImport moduleImport = createModuleImport(moduleName, revision, prefix);
+        final ModuleImport moduleImport = new ModuleImportImpl(moduleName, revision, prefix);
         imports.put(prefix, moduleImport);
     }
 
@@ -1049,10 +1055,6 @@ public class ModuleBuilder extends AbstractDocumentedDataNodeContainerBuilder im
         }
     }
 
-    private ModuleImport createModuleImport(final String moduleName, final Date revision, final String prefix) {
-        return new ModuleImportImpl(moduleName, revision, prefix);
-    }
-
     private void raiseYangParserException(final String cantAddType, final String type, final String name,
             final int currentLine, final int duplicateLine) {
 
@@ -1072,9 +1074,9 @@ public class ModuleBuilder extends AbstractDocumentedDataNodeContainerBuilder im
     public int hashCode() {
         final int prime = 31;
         int result = 1;
-        result = prime * result + ((name == null) ? 0 : name.hashCode());
+        result = prime * result + Objects.hashCode(name);
         result = prime * result + qnameModule.hashCode();
-        result = prime * result + ((prefix == null) ? 0 : prefix.hashCode());
+        result = prime * result + Objects.hashCode(prefix);
 
         return result;
     }