Memory hog: ImmutableSet is appropriate here 99/6899/1
authorRobert Varga <rovarga@cisco.com>
Mon, 12 May 2014 13:07:29 +0000 (15:07 +0200)
committerRobert Varga <rovarga@cisco.com>
Mon, 12 May 2014 13:07:29 +0000 (15:07 +0200)
Change-Id: Idf204d69636af931c1e2cd454528a276947f29d9
Signed-off-by: Robert Varga <rovarga@cisco.com>
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/builder/impl/ConstraintsBuilder.java

index 712de5cc72612dc5a3f3747714e5cab5df1c57f6..63c0bc4078ee1401d155b3a14c2b90c3d6a25cf9 100644 (file)
@@ -16,6 +16,8 @@ import org.opendaylight.yangtools.yang.model.api.MustDefinition;
 import org.opendaylight.yangtools.yang.model.api.RevisionAwareXPath;
 import org.opendaylight.yangtools.yang.model.util.RevisionAwareXPathImpl;
 
+import com.google.common.collect.ImmutableSet;
+
 public final class ConstraintsBuilder {
     private static final int HASH_IF_BOOL_TRUE = 1231;
     private static final int HASH_IF_BOOL_FALSE = 1237;
@@ -125,7 +127,7 @@ public final class ConstraintsBuilder {
 
     private static final class ConstraintDefinitionImpl implements ConstraintDefinition {
         private RevisionAwareXPath whenCondition;
-        private Set<MustDefinition> mustConstraints;
+        private Set<MustDefinition> mustConstraints = Collections.emptySet();
         private boolean mandatory;
         private Integer minElements;
         private Integer maxElements;
@@ -141,16 +143,12 @@ public final class ConstraintsBuilder {
 
         @Override
         public Set<MustDefinition> getMustConstraints() {
-            if (mustConstraints == null) {
-                return Collections.emptySet();
-            } else {
-                return mustConstraints;
-            }
+            return mustConstraints;
         }
 
         private void setMustConstraints(final Set<MustDefinition> mustConstraints) {
             if (mustConstraints != null) {
-                this.mustConstraints = mustConstraints;
+                this.mustConstraints = ImmutableSet.copyOf(mustConstraints);
             }
         }