2 * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
3 * This program and the accompanying materials are made available under the
4 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
5 * and is available at http://www.eclipse.org/legal/epl-v10.html
7 package org.opendaylight.yangtools.yang.data.api;
9 import com.google.common.collect.ImmutableList;
10 import com.google.common.collect.Lists;
11 import java.util.ArrayList;
12 import java.util.List;
14 import org.opendaylight.yangtools.util.HashCodeBuilder;
15 import org.opendaylight.yangtools.yang.common.QName;
16 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.InstanceIdentifierBuilder;
17 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
18 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
19 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
21 final class YangInstanceIdentifierBuilder implements InstanceIdentifierBuilder {
22 private final HashCodeBuilder<PathArgument> hash;
23 private final List<PathArgument> path;
25 public YangInstanceIdentifierBuilder() {
26 this.hash = new HashCodeBuilder<>();
27 this.path = new ArrayList<>();
30 public YangInstanceIdentifierBuilder(final Iterable<PathArgument> prefix, final int hash) {
31 this.path = Lists.newArrayList(prefix);
32 this.hash = new HashCodeBuilder<>(hash);
36 public InstanceIdentifierBuilder node(final QName nodeType) {
37 final PathArgument arg = new NodeIdentifier(nodeType);
39 hash.addArgument(arg);
44 public InstanceIdentifierBuilder nodeWithKey(final QName nodeType, final QName key, final Object value) {
45 final PathArgument arg = new NodeIdentifierWithPredicates(nodeType, key, value);
47 hash.addArgument(arg);
52 public InstanceIdentifierBuilder nodeWithKey(final QName nodeType, final Map<QName, Object> keyValues) {
53 final PathArgument arg = new NodeIdentifierWithPredicates(nodeType, keyValues);
55 hash.addArgument(arg);
61 public YangInstanceIdentifier toInstance() {
66 public YangInstanceIdentifier build() {
67 return new YangInstanceIdentifier(ImmutableList.copyOf(path), hash.build());