X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=yang%2Fyang-parser-spi%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fyangtools%2Fyang%2Fparser%2Fspi%2Fmeta%2FCopyHistory.java;h=5b039d6e239ee417a7acb7111dcf37000ab2123e;hb=712c3ae6a666023f8febb1c7eb7c72ede2e31022;hp=10eb0fa252dee83ab45005fe449642cd034f68e4;hpb=c92cfb59f67ee6307423132f7b059cea81be7a78;p=yangtools.git diff --git a/yang/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/CopyHistory.java b/yang/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/CopyHistory.java index 10eb0fa252..5b039d6e23 100644 --- a/yang/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/CopyHistory.java +++ b/yang/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/CopyHistory.java @@ -9,14 +9,19 @@ 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][]; + static { /* * Cache size is dependent on number of items in CopyType, it costs N * 2^N objects. @@ -30,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; @@ -79,6 +88,8 @@ public final class CopyHistory implements Immutable { return ret; } + @VisibleForTesting + // FIXME: 7.0.0: hide this method public boolean contains(final CopyType type) { return (operations & type.bit()) != 0; } @@ -87,6 +98,18 @@ public final class CopyHistory implements Immutable { return VALUES[lastOperation]; } + @Override + @Deprecated + public boolean isAugmenting() { + return (operations & IS_AUGMENTING_BITS) != 0; + } + + @Override + @Deprecated + public boolean isAddedByUses() { + return (operations & IS_ADDED_BY_USES_BITS) != 0; + } + @VisibleForTesting CopyHistory append(final CopyType typeOfCopy, final CopyHistory toAppend) { final int newOperations = operations | toAppend.operations | typeOfCopy.bit(); @@ -113,4 +136,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(); + } }