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