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