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