Do not instantiate new maps in LeafRefContextBuilder
[yangtools.git] / yang / yang-data-impl / src / main / java / org / opendaylight / yangtools / yang / data / impl / leafref / QNamePredicateImpl.java
1 /**
2  * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.yangtools.yang.data.impl.leafref;
9
10 import com.google.common.base.Preconditions;
11 import java.io.Serializable;
12 import org.opendaylight.yangtools.concepts.Immutable;
13 import org.opendaylight.yangtools.yang.common.QName;
14
15 class QNamePredicateImpl implements Immutable, Serializable, QNamePredicate {
16
17     private static final long serialVersionUID = 1L;
18     private final QName identifier;
19     private final LeafRefPath pathKeyExpression;
20
21     public QNamePredicateImpl(final QName identifier, final LeafRefPath pathKeyExpression) {
22         this.identifier = Preconditions.checkNotNull(identifier, "QNamePredicate: identifier should not be null");
23         this.pathKeyExpression = Preconditions.checkNotNull(pathKeyExpression, "QNamePredicate: pathKeyExpression should not be null");
24     }
25
26     @Override
27     public QName getIdentifier() {
28         return identifier;
29     }
30
31     @Override
32     public LeafRefPath getPathKeyExpression() {
33         return pathKeyExpression;
34     }
35
36     @Override
37     public String toString() {
38         final StringBuilder sb = new StringBuilder();
39         sb.append('[');
40
41         sb.append(identifier);
42         sb.append("=current()");
43
44         final Iterable<QNameWithPredicate> pathFromRoot = pathKeyExpression
45                 .getPathFromRoot();
46
47         for (final QNameWithPredicate qName : pathFromRoot) {
48             sb.append('/').append(qName);
49         }
50
51         sb.append(']');
52         return sb.toString();
53     }
54
55 }