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 com.google.common.collect.ImmutableList;
11 import java.io.Serializable;
12 import java.util.List;
13 import java.util.Objects;
14 import java.util.Optional;
15 import org.opendaylight.yangtools.concepts.Immutable;
16 import org.opendaylight.yangtools.yang.common.QName;
17 import org.opendaylight.yangtools.yang.common.QNameModule;
18 import org.opendaylight.yangtools.yang.common.Revision;
20 final class QNameWithPredicateImpl implements Immutable, Serializable, QNameWithPredicate {
22 private static final long serialVersionUID = 1L;
24 private final List<QNamePredicate> qnamePredicates;
25 private final QNameModule moduleQname;
26 private final String localName;
28 QNameWithPredicateImpl(final QNameModule moduleQname, final String localName,
29 final List<QNamePredicate> qnamePredicates) {
30 this.moduleQname = moduleQname;
31 this.localName = localName;
32 this.qnamePredicates = ImmutableList.copyOf(qnamePredicates);
36 public List<QNamePredicate> getQNamePredicates() {
37 return qnamePredicates;
41 public QNameModule getModuleQname() {
46 public String getLocalName() {
51 public QName getQName() {
52 return QName.create(moduleQname, localName);
55 // FIXME: check also predicates ...
57 public boolean equals(final Object obj) {
61 if (!(obj instanceof QNameWithPredicateImpl)) {
64 final QNameWithPredicateImpl other = (QNameWithPredicateImpl) obj;
65 return Objects.equals(localName, other.localName) && moduleQname.equals(other.moduleQname);
69 public int hashCode() {
70 int result = moduleQname != null ? moduleQname.hashCode() : 0;
71 result = 31 * result + (localName != null ? localName.hashCode() : 0);
76 public String toString() {
77 final StringBuilder sb = new StringBuilder();
79 if (moduleQname != null) {
80 sb.append('(').append(moduleQname.getNamespace());
81 final Optional<Revision> rev = moduleQname.getRevision();
82 if (rev.isPresent()) {
83 sb.append("?revision=").append(rev.get());
90 for (final QNamePredicate predicate : qnamePredicates) {