Remove AttributesContainer
[yangtools.git] / yang / yang-data-util / src / main / java / org / opendaylight / yangtools / yang / data / util / LeafsetEntryInterner.java
index aca67fda3657859b6c9914349e3a693d15cd416a..b43662a214c1575632ac52dd437e42d3f57df835 100644 (file)
@@ -10,13 +10,14 @@ package org.opendaylight.yangtools.yang.data.util;
 import com.google.common.annotations.Beta;
 import com.google.common.collect.Interner;
 import com.google.common.collect.Interners;
-import javax.annotation.Nonnull;
-import javax.annotation.Nullable;
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.Nullable;
 import org.opendaylight.yangtools.yang.data.api.schema.LeafSetEntryNode;
 import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
 import org.opendaylight.yangtools.yang.model.api.type.BooleanTypeDefinition;
 import org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition;
+import org.opendaylight.yangtools.yang.model.api.type.IdentityrefTypeDefinition;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -24,10 +25,12 @@ import org.slf4j.LoggerFactory;
  * Utility class for sharing instances of {@link LeafSetEntryNode}s which have low cardinality -- e.g. those which hold
  * boolean or enumeration values. Instances containing attributes are not interned.
  *
+ * <p>
  * Such objects have cardinality which is capped at the product of QNAMES * TYPE_CARDINALITY, where QNAMES is the total
  * number of different QNames where the type is used and TYPE_CARDINALITY is the number of possible values for the type.
  * Boolean has cardinality of 2, enumerations have cardinality equal to the number of enum statements.
  *
+ * <p>
  * The theory here is that we tend to have a large number (100K+) of entries in a few places, which could end up hogging
  * the heap retained via the DataTree with duplicate objects (same QName, same value, different object). Using this
  * utility, such objects will end up reusing the same object, preventing this overhead.
@@ -43,19 +46,14 @@ public final class LeafsetEntryInterner {
     }
 
     @SuppressWarnings("static-method")
-    public <T extends LeafSetEntryNode<?>> T intern(@Nonnull final T sample) {
-        if (!sample.getAttributes().isEmpty()) {
-            // Non-empty attributes, do not intern
-            return sample;
-        }
-
+    public <T extends LeafSetEntryNode<?>> @NonNull T intern(final @NonNull T sample) {
         /*
          * We do not perform type checks here as they are implied by #forSchema(LeafListSchemaNode). Any misuse can
          * result in inappropriate candidates being interned, but the alternative would be quite a bit slower.
          */
         @SuppressWarnings("unchecked")
         final T ret = (T) INTERNER.intern(sample);
-        LOG.trace("Interned object %s to %s", sample, ret);
+        LOG.trace("Interned object {} to {}", sample, ret);
         return ret;
     }
 
@@ -66,10 +64,11 @@ public final class LeafsetEntryInterner {
      * @param schema Schema of the parent leaf set
      * @return An interner instance, or null if the leafset's type should not be interned.
      */
-    @Nullable public static LeafsetEntryInterner forSchema(@Nullable final LeafListSchemaNode schema) {
+    public static @Nullable LeafsetEntryInterner forSchema(final @Nullable LeafListSchemaNode schema) {
         if (schema != null) {
             final TypeDefinition<?> type = schema.getType();
-            if (type instanceof BooleanTypeDefinition || type instanceof EnumTypeDefinition) {
+            if (type instanceof BooleanTypeDefinition || type instanceof EnumTypeDefinition
+                    || type instanceof IdentityrefTypeDefinition) {
                 return INSTANCE;
             }
         }