Use String concatenation instead of StringBuffer/Builder
[yangtools.git] / yang / yang-parser-impl / src / main / java / org / opendaylight / yangtools / yang / parser / builder / impl / ModuleImpl.java
index 4e4bc8cf18c0b0035f89ae29069c08fd8919ee81..a17dc56f1fc3daba303661f0c51f9305bbca9ed4 100644 (file)
@@ -1,17 +1,24 @@
+/*
+ * Copyright (c) 2014, 2015 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 static com.google.common.base.Preconditions.checkNotNull;
-
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableSet;
-
 import java.net.URI;
 import java.util.Collections;
 import java.util.Date;
 import java.util.List;
+import java.util.NavigableSet;
+import java.util.Objects;
 import java.util.Set;
 import java.util.TreeSet;
-
 import org.opendaylight.yangtools.concepts.Immutable;
 import org.opendaylight.yangtools.yang.common.QNameModule;
 import org.opendaylight.yangtools.yang.model.api.AugmentationSchema;
@@ -28,6 +35,10 @@ import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
 import org.opendaylight.yangtools.yang.parser.builder.util.AbstractDocumentedDataNodeContainer;
 import org.opendaylight.yangtools.yang.parser.builder.util.Comparators;
 
+/**
+ * @deprecated Pre-Beryllium implementation, scheduled for removal.
+ */
+@Deprecated
 public final class ModuleImpl extends AbstractDocumentedDataNodeContainer implements Module, Immutable {
 
     private final QNameModule qnameModule;
@@ -38,6 +49,7 @@ public final class ModuleImpl extends AbstractDocumentedDataNodeContainer implem
     private final String organization;
     private final String contact;
     private final Set<ModuleImport> imports;
+    private final Set<Module> submodules;
     private final Set<FeatureDefinition> features;
     private final Set<NotificationDefinition> notifications;
     private final Set<AugmentationSchema> augmentations;
@@ -62,11 +74,12 @@ public final class ModuleImpl extends AbstractDocumentedDataNodeContainer implem
         super(builder);
         this.name = checkNotNull(name, "Missing name");
         this.sourcePath = sourcePath; //TODO: can this be nullable?
-        this.imports = ImmutableSet.copyOf(builder.imports);
+        this.imports = ImmutableSet.<ModuleImport> copyOf(builder.imports.values());
+        this.submodules = ImmutableSet.<Module> copyOf(builder.submodules);
         this.prefix = builder.getPrefix();
 
         this.qnameModule = QNameModule.create(builder.getNamespace(),
-                builder.getRevision() == null ? null : new Date(builder.getRevision().getTime()));
+                builder.getRevision() == null ? null : new Date(builder.getRevision().getTime())).intern();
         this.yangVersion = builder.getYangVersion();
         this.organization = builder.getOrganization();
         this.contact = builder.getContact();
@@ -127,6 +140,11 @@ public final class ModuleImpl extends AbstractDocumentedDataNodeContainer implem
         return imports;
     }
 
+    @Override
+    public Set<Module> getSubmodules() {
+        return submodules;
+    }
+
     @Override
     public Set<FeatureDefinition> getFeatures() {
         return features;
@@ -176,8 +194,8 @@ public final class ModuleImpl extends AbstractDocumentedDataNodeContainer implem
     public int hashCode() {
         final int prime = 31;
         int result = 1;
-        result = prime * result + ((name == null) ? 0 : name.hashCode());
-        result = prime * result + ((yangVersion == null) ? 0 : yangVersion.hashCode());
+        result = prime * result + Objects.hashCode(name);
+        result = prime * result + Objects.hashCode(yangVersion);
         result = prime * result + qnameModule.hashCode();
         return result;
     }
@@ -215,22 +233,20 @@ public final class ModuleImpl extends AbstractDocumentedDataNodeContainer implem
     }
 
     private static <T extends SchemaNode> Set<T> toImmutableSortedSet(final Set<T> original) {
-        TreeSet<T> sorted = new TreeSet<>(Comparators.SCHEMA_NODE_COMP);
+        NavigableSet<T> sorted = new TreeSet<>(Comparators.SCHEMA_NODE_COMP);
         sorted.addAll(original);
         return Collections.unmodifiableSet(sorted);
     }
 
     @Override
     public String toString() {
-        StringBuilder sb = new StringBuilder(ModuleImpl.class.getSimpleName());
-        sb.append("[");
-        sb.append("name=").append(name);
-        sb.append(", namespace=").append(getNamespace());
-        sb.append(", revision=").append(getRevision());
-        sb.append(", prefix=").append(prefix);
-        sb.append(", yangVersion=").append(yangVersion);
-        sb.append("]");
-        return sb.toString();
+        return ModuleImpl.class.getSimpleName() + "[" +
+                "name=" + name +
+                ", namespace=" + getNamespace() +
+                ", revision=" + getRevision() +
+                ", prefix=" + prefix +
+                ", yangVersion=" + yangVersion +
+                "]";
     }
 
     @Override