Un-deprecate CopyableNode, AddedByUsesAware
[yangtools.git] / yang / yang-parser-spi / src / main / java / org / opendaylight / yangtools / yang / parser / spi / meta / CopyHistory.java
index 32f21c907632b3504917bb08ccec5b155ed668f1..8b4e5846b532e656f0a5ab426e3d762c3df0a04d 100644 (file)
@@ -9,11 +9,15 @@ package org.opendaylight.yangtools.yang.parser.spi.meta;
 
 import com.google.common.annotations.Beta;
 import com.google.common.annotations.VisibleForTesting;
+import com.google.common.base.MoreObjects;
 import com.google.common.base.Verify;
+import java.util.Arrays;
+import java.util.stream.Collectors;
 import org.opendaylight.yangtools.concepts.Immutable;
+import org.opendaylight.yangtools.yang.model.api.CopyableNode;
 
 @Beta
-public final class CopyHistory implements Immutable {
+public final class CopyHistory implements Immutable, CopyableNode {
     private static final CopyType[] VALUES = CopyType.values();
 
     private static final CopyHistory[][] CACHE = new CopyHistory[VALUES.length][];
@@ -31,6 +35,10 @@ public final class CopyHistory implements Immutable {
     }
 
     private static final CopyHistory ORIGINAL = cacheObject(CopyType.ORIGINAL, CopyType.ORIGINAL.bit());
+    private static final int IS_ADDED_BY_USES_BITS =
+        CopyType.ADDED_BY_USES_AUGMENTATION.bit() | CopyType.ADDED_BY_USES.bit();
+    private static final int IS_AUGMENTING_BITS =
+        CopyType.ADDED_BY_USES_AUGMENTATION.bit() | CopyType.ADDED_BY_AUGMENTATION.bit();
 
     private final short operations;
     private final short lastOperation;
@@ -80,14 +88,25 @@ public final class CopyHistory implements Immutable {
         return ret;
     }
 
-    public boolean contains(final CopyType type) {
-        return (operations & type.bit()) != 0;
-    }
-
     public CopyType getLastOperation() {
         return VALUES[lastOperation];
     }
 
+    @Override
+    public boolean isAugmenting() {
+        return (operations & IS_AUGMENTING_BITS) != 0;
+    }
+
+    @Override
+    public boolean isAddedByUses() {
+        return (operations & IS_ADDED_BY_USES_BITS) != 0;
+    }
+
+    @VisibleForTesting
+    boolean contains(final CopyType type) {
+        return (operations & type.bit()) != 0;
+    }
+
     @VisibleForTesting
     CopyHistory append(final CopyType typeOfCopy, final CopyHistory toAppend) {
         final int newOperations = operations | toAppend.operations | typeOfCopy.bit();
@@ -114,4 +133,12 @@ public final class CopyHistory implements Immutable {
         final CopyHistory other = (CopyHistory) obj;
         return operations == other.operations && lastOperation == other.lastOperation;
     }
+
+    @Override
+    public String toString() {
+        return MoreObjects.toStringHelper(this).add("lastOperation", getLastOperation())
+                .add("operations", Arrays.stream(VALUES).filter(value -> (value.bit() & operations) != 0)
+                    .collect(Collectors.toList()))
+                .toString();
+    }
 }