Remove unnecessary String() constructor invocations
[yangtools.git] / yang / yang-model-util / src / main / java / org / opendaylight / yangtools / yang / model / util / Leafref.java
1 /*
2  * Copyright (c) 2013 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.model.util;
9
10 import com.google.common.base.Preconditions;
11 import java.util.Collections;
12 import java.util.List;
13 import java.util.Objects;
14 import org.opendaylight.yangtools.yang.common.QName;
15 import org.opendaylight.yangtools.yang.model.api.RevisionAwareXPath;
16 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
17 import org.opendaylight.yangtools.yang.model.api.Status;
18 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
19 import org.opendaylight.yangtools.yang.model.api.type.LeafrefTypeDefinition;
20
21 /**
22  * The <code>default</code> implementation of Instance Leafref Type Definition
23  * interface.
24  *
25  * @see LeafrefTypeDefinition
26  * @deprecated Use {@link org.opendaylight.yangtools.yang.model.util.type.BaseTypes#leafrefTypeBuilder(SchemaPath)} instead
27  */
28 @Deprecated
29 public final class Leafref implements LeafrefTypeDefinition {
30     private static final QName NAME = BaseTypes.constructQName("leafref");
31     private static final SchemaPath PATH = SchemaPath.create(true, NAME);
32     private static final String DESCRIPTION = "The leafref type is used to reference a particular leaf instance in the data tree.";
33     private static final String REF = "https://tools.ietf.org/html/rfc6020#section-9.9";
34
35     private final RevisionAwareXPath xpath;
36     private final SchemaPath path;
37
38     @Deprecated
39     public Leafref(final RevisionAwareXPath xpath) {
40         this(PATH, xpath);
41     }
42
43     private Leafref(final SchemaPath path, final RevisionAwareXPath target) {
44         this.path = Preconditions.checkNotNull(path,"path must be specified");
45         this.xpath = Preconditions.checkNotNull(target,"target must not be null.");
46     }
47
48     public static Leafref create(final SchemaPath path, final RevisionAwareXPath target) {
49         return new Leafref(path,target);
50     }
51
52     @Override
53     public LeafrefTypeDefinition getBaseType() {
54         return null;
55     }
56
57     @Override
58     public String getUnits() {
59         return "";
60     }
61
62     @Override
63     public Object getDefaultValue() {
64         return null;
65     }
66
67     @Override
68     public QName getQName() {
69         return NAME;
70     }
71
72     @Override
73     public SchemaPath getPath() {
74         return path;
75     }
76
77     @Override
78     public String getDescription() {
79         return DESCRIPTION;
80     }
81
82     @Override
83     public String getReference() {
84         return REF;
85     }
86
87     @Override
88     public Status getStatus() {
89         return Status.CURRENT;
90     }
91
92     @Override
93     public List<UnknownSchemaNode> getUnknownSchemaNodes() {
94         return Collections.emptyList();
95     }
96
97     @Override
98     public RevisionAwareXPath getPathStatement() {
99         return xpath;
100     }
101
102     @Override
103     public int hashCode() {
104         final int prime = 31;
105         int result = 1;
106         result = prime * result + Objects.hashCode(xpath);
107         return result;
108     }
109
110     @Override
111     public boolean equals(final Object obj) {
112         if (this == obj) {
113             return true;
114         }
115         if (obj == null) {
116             return false;
117         }
118         if (getClass() != obj.getClass()) {
119             return false;
120         }
121         Leafref other = (Leafref) obj;
122         return Objects.equals(xpath, other.xpath);
123     }
124
125     @Override
126     public String toString() {
127         StringBuilder builder = new StringBuilder();
128         builder.append("type ");
129         builder.append(NAME);
130         builder.append(" [xpath=");
131         builder.append(xpath);
132         builder.append("]");
133         return builder.toString();
134     }
135 }