Introduce YangInstanceIdentifier.getAncestor() 92/26892/4
authorRobert Varga <rovarga@cisco.com>
Sun, 13 Sep 2015 16:57:58 +0000 (18:57 +0200)
committerGerrit Code Review <gerrit@opendaylight.org>
Mon, 14 Sep 2015 16:45:05 +0000 (16:45 +0000)
commita6ef07f41fcc69bbccc13edb8cc35348517821e2
tree076a7a460a7ebce892291f5bfd92c7cb6cb33db4
parent6e4d9343c877d180c707b660c91abf35cf51bca0
Introduce YangInstanceIdentifier.getAncestor()

We have callsites which want to create a truncated
YangInstanceIdentifier and open-code instantiation. This is not
efficient, as those users do not have an understanding of the
implementation details, thus they have to resort to Iterables.limit()
and similar -- which forces copying of path arguments and untrusted
instantiation of YangInstanceIdentifier.

This patch introduces getAncestor(int), which performs this operation
with explicit knowledge of a particular implementation, resulting in
as much reuse as possible: for FixedYangInstanceIdentifier it uses a
subList(), for StackedYangInstanceIdentifier we return either a
direct/indirect parent, or use FixedYangInstanceIdentifier's version.

Change-Id: I355200199ac9791bb6d027fcdfa2a1162208a627
Signed-off-by: Robert Varga <rovarga@cisco.com>
yang/yang-data-api/src/main/java/org/opendaylight/yangtools/yang/data/api/FixedYangInstanceIdentifier.java
yang/yang-data-api/src/main/java/org/opendaylight/yangtools/yang/data/api/StackedYangInstanceIdentifier.java
yang/yang-data-api/src/main/java/org/opendaylight/yangtools/yang/data/api/YangInstanceIdentifier.java