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.Lists;
10 import java.util.ArrayList;
11 import java.util.List;
13 import org.opendaylight.yangtools.util.HashCodeBuilder;
14 import org.opendaylight.yangtools.yang.common.QName;
15 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.InstanceIdentifierBuilder;
16 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
17 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
18 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
20 final class YangInstanceIdentifierBuilder implements InstanceIdentifierBuilder {
21 private final HashCodeBuilder<PathArgument> hash;
22 private final List<PathArgument> path;
24 public YangInstanceIdentifierBuilder() {
25 this.hash = new HashCodeBuilder<>();
26 this.path = new ArrayList<>();
29 public YangInstanceIdentifierBuilder(final Iterable<PathArgument> prefix, final int hash) {
30 this.path = Lists.newArrayList(prefix);
31 this.hash = new HashCodeBuilder<>(hash);
35 public InstanceIdentifierBuilder node(final QName nodeType) {
36 final PathArgument arg = new NodeIdentifier(nodeType);
38 hash.addArgument(arg);
43 public InstanceIdentifierBuilder nodeWithKey(final QName nodeType, final QName key, final Object value) {
44 final PathArgument arg = new NodeIdentifierWithPredicates(nodeType, key, value);
46 hash.addArgument(arg);
51 public InstanceIdentifierBuilder nodeWithKey(final QName nodeType, final Map<QName, Object> keyValues) {
52 final PathArgument arg = new NodeIdentifierWithPredicates(nodeType, keyValues);
54 hash.addArgument(arg);
60 public YangInstanceIdentifier toInstance() {
65 public YangInstanceIdentifier build() {
66 return FixedYangInstanceIdentifier.create(path, hash.build());