- private static class BuilderImpl implements InstanceIdentifierBuilder {
- private final HashCodeBuilder<PathArgument> hash;
- private final List<PathArgument> path;
-
- public BuilderImpl() {
- this.hash = new HashCodeBuilder<>();
- this.path = new ArrayList<>();
- }
-
- public BuilderImpl(final Iterable<PathArgument> prefix, final int hash) {
- this.path = Lists.newArrayList(prefix);
- this.hash = new HashCodeBuilder<>(hash);
- }
-
- @Override
- public InstanceIdentifierBuilder node(final QName nodeType) {
- final PathArgument arg = new NodeIdentifier(nodeType);
- path.add(arg);
- hash.addArgument(arg);
- return this;
- }
-
- @Override
- public InstanceIdentifierBuilder nodeWithKey(final QName nodeType, final QName key, final Object value) {
- final PathArgument arg = new NodeIdentifierWithPredicates(nodeType, key, value);
- path.add(arg);
- hash.addArgument(arg);
- return this;
- }
-
- @Override
- public InstanceIdentifierBuilder nodeWithKey(final QName nodeType, final Map<QName, Object> keyValues) {
- final PathArgument arg = new NodeIdentifierWithPredicates(nodeType, keyValues);
- path.add(arg);
- hash.addArgument(arg);
- return this;
- }
-
- @Override
- @Deprecated
- public YangInstanceIdentifier toInstance() {
- return build();
- }
-
- @Override
- public YangInstanceIdentifier build() {
- return new YangInstanceIdentifier(ImmutableList.copyOf(path), hash.toInstance());
- }
- }
-
- @Override
- public boolean contains(final YangInstanceIdentifier other) {
- Preconditions.checkArgument(other != null, "other should not be null");
-
- final Iterator<?> lit = pathArguments.iterator();
- final Iterator<?> oit = other.pathArguments.iterator();
-
- while (lit.hasNext()) {
- if (!oit.hasNext()) {
- return false;
- }
-
- if (!lit.next().equals(oit.next())) {
- return false;
- }
- }
-
- return true;
- }
-
- @Override
- public String toString() {
- /*
- * The toStringCache is safe, since the object contract requires
- * immutability of the object and all objects referenced from this
- * object.
- * Used lists, maps are immutable. Path Arguments (elements) are also
- * immutable, since the PathArgument contract requires immutability.
- * The cache is thread-safe - if multiple computations occurs at the
- * same time, cache will be overwritten with same result.