Bug 2894 - Yang Data Codec Gson: null pointer exception when trying to
[yangtools.git] / yang / yang-model-util / src / main / java / org / opendaylight / yangtools / yang / model / util / RevisionAwareXPathImpl.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 org.opendaylight.yangtools.yang.model.api.RevisionAwareXPath;
11
12 /**
13  * The <code>helper</code> implementation of Instance Rewision Aware XPath
14  * interface.
15  *
16  * @see RevisionAwareXPath
17  */
18 public class RevisionAwareXPathImpl implements RevisionAwareXPath {
19
20     private final String xpath;
21     private final boolean absolute;
22
23     private static final int HASH_BOOLEAN_TRUE = 1231;
24     private static final int HASH_BOOLEAN_FALSE = 1237;
25
26     public RevisionAwareXPathImpl(final String xpath, final boolean absolute) {
27         this.xpath = xpath;
28         this.absolute = absolute;
29     }
30
31     @Override
32     public boolean isAbsolute() {
33         return absolute;
34     }
35
36     @Override
37     public int hashCode() {
38         final int prime = 31;
39         int result = 1;
40         result = prime * result + ((xpath == null) ? 0 : xpath.hashCode());
41         result = prime * result + (absolute ? HASH_BOOLEAN_TRUE : HASH_BOOLEAN_FALSE);
42         return result;
43     }
44
45     @Override
46     public boolean equals(final Object obj) {
47         if (this == obj) {
48             return true;
49         }
50         if (obj == null) {
51             return false;
52         }
53         if (getClass() != obj.getClass()) {
54             return false;
55         }
56         RevisionAwareXPathImpl other = (RevisionAwareXPathImpl) obj;
57         if (xpath == null) {
58             if (other.xpath != null) {
59                 return false;
60             }
61         } else if (!xpath.equals(other.xpath)) {
62             return false;
63         }
64         if (absolute != other.absolute) {
65             return false;
66         }
67         return false;
68     }
69
70     @Override
71     public String toString() {
72         return xpath;
73     }
74 }