2 * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.yangtools.yang.data.impl.leafref;
10 import java.util.ArrayList;
11 import java.util.List;
12 import java.util.Objects;
13 import org.opendaylight.yangtools.yang.common.QNameModule;
15 class QNameWithPredicateBuilder {
17 private final List<QNamePredicate> qnamePredicates = new ArrayList<>();
18 private QNameModule moduleQname;
19 private String localName;
21 public static final QNameWithPredicateBuilder UP_PARENT_BUILDER = new QNameWithPredicateBuilder(
24 public QNameWithPredicate build() {
25 return QNameWithPredicate.UP_PARENT;
29 public QNameWithPredicateBuilder(final QNameModule moduleQname, final String localName) {
30 this.moduleQname = moduleQname;
31 this.localName = localName;
34 public QNameWithPredicate build() {
35 final QNameWithPredicateImpl qNameWithPredicateImpl = new QNameWithPredicateImpl(
36 moduleQname, localName, qnamePredicates);
38 // QNameWithPredicateImpl has taken a copy
39 qnamePredicates.clear();
40 return qNameWithPredicateImpl;
43 public List<QNamePredicate> getQNamePredicates() {
44 return qnamePredicates;
47 public void addQNamePredicate(final QNamePredicate qnamePredicate) {
48 qnamePredicates.add(qnamePredicate);
51 public QNameModule getModuleQname() {
55 public void setModuleQname(final QNameModule moduleQname) {
56 this.moduleQname = moduleQname;
59 public String getLocalName() {
63 public void setLocalName(final String localName) {
64 this.localName = localName;
67 // FIXME: check also predicates ...
69 public boolean equals(final Object obj) {
73 if (!(obj instanceof QNameWithPredicateBuilder)) {
76 final QNameWithPredicateBuilder other = (QNameWithPredicateBuilder) obj;
77 return Objects.equals(localName, other.localName) && moduleQname.equals(other.moduleQname);
81 public int hashCode() {
82 int result = moduleQname != null ? moduleQname.hashCode() : 0;
83 result = 31 * result + Objects.hashCode(localName);
88 public String toString() {
89 final StringBuilder sb = new StringBuilder();
91 if (moduleQname != null) {
92 sb.append('(').append(moduleQname.getNamespace());
93 sb.append("?revision=").append(moduleQname.getRevision());
99 for (final QNamePredicate predicate : qnamePredicates) {
100 sb.append(predicate);
103 return sb.toString();