Fixing sonar issues 4
[yangtools.git] / yang / yang-model-api / src / main / java / org / opendaylight / yangtools / yang / model / api / SchemaPath.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.api;
9
10 import java.util.ArrayList;
11 import java.util.Collections;
12 import java.util.List;
13
14 import org.opendaylight.yangtools.yang.common.QName;
15
16 /**
17  * 
18  * Represents unique path to the every node inside the module.
19  * 
20  */
21 public class SchemaPath {
22     private final int hashBooleanTrue = 1231;
23     private final int hashBooleanFalse = 1237;
24
25     /**
26      * List of QName instances which represents complete path to the node.
27      */
28     private final List<QName> path;
29
30     /**
31      * Boolean value which represents type of schema path (relative or
32      * absolute).
33      */
34     private final boolean absolute;
35
36     /**
37      * Constructs new instance of this class with the concrete path.
38      * 
39      * @param path
40      *            list of QName instances which specifies exact path to the
41      *            module node
42      * @param absolute
43      *            boolean value which specifies if the path is absolute or
44      *            relative
45      */
46     public SchemaPath(final List<QName> path, boolean absolute) {
47         this.path = Collections.unmodifiableList(new ArrayList<QName>(path));
48         this.absolute = absolute;
49     }
50
51     /**
52      * Returns the complete path to schema node.
53      * 
54      * @return list of <code>QName</code> instances which represents complete
55      *         path to schema node
56      */
57     public List<QName> getPath() {
58         return path;
59     }
60
61     /**
62      * Describes whether schema path is|isn't absolute.
63      * 
64      * @return boolean value which is <code>true</code> if schema path is
65      *         absolute.
66      */
67     public boolean isAbsolute() {
68         return absolute;
69     }
70
71     @Override
72     public int hashCode() {
73         final int prime = 31;
74         int result = 1;
75         result = prime * result + (absolute ? hashBooleanTrue : hashBooleanFalse);
76         result = prime * result + ((path == null) ? 0 : path.hashCode());
77         return result;
78     }
79
80     @Override
81     public boolean equals(Object obj) {
82         if (this == obj) {
83             return true;
84         }
85         if (obj == null) {
86             return false;
87         }
88         if (getClass() != obj.getClass()) {
89             return false;
90         }
91         SchemaPath other = (SchemaPath) obj;
92         if (absolute != other.absolute) {
93             return false;
94         }
95         if (path == null) {
96             if (other.path != null) {
97                 return false;
98             }
99         } else if (!path.equals(other.path)) {
100             return false;
101         }
102         return true;
103     }
104
105     @Override
106     public String toString() {
107         StringBuilder builder = new StringBuilder();
108         builder.append("SchemaPath [path=");
109         builder.append(path);
110         builder.append(", absolute=");
111         builder.append(absolute);
112         builder.append("]");
113         return builder.toString();
114     }
115 }