Merge branch 'master' of ../controller
[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 static java.util.Objects.requireNonNull;
11
12 import java.util.Objects;
13 import org.eclipse.jdt.annotation.NonNull;
14 import org.opendaylight.yangtools.yang.model.api.RevisionAwareXPath;
15
16 /**
17  * The <code>helper</code> implementation of Instance Revision Aware XPath interface.
18  *
19  * @see RevisionAwareXPath
20  */
21 public class RevisionAwareXPathImpl implements RevisionAwareXPath {
22     private final @NonNull String xpath;
23     private final boolean absolute;
24
25     public RevisionAwareXPathImpl(final String xpath, final boolean absolute) {
26         this.xpath = requireNonNull(xpath);
27         this.absolute = absolute;
28     }
29
30     @Override
31     public boolean isAbsolute() {
32         return absolute;
33     }
34
35     @Override
36     public int hashCode() {
37         final int prime = 31;
38         int result = 1;
39         result = prime * result + Objects.hashCode(xpath);
40         result = prime * result + Boolean.hashCode(absolute);
41         return result;
42     }
43
44     @Override
45     public boolean equals(final Object obj) {
46         if (this == obj) {
47             return true;
48         }
49         if (obj == null) {
50             return false;
51         }
52         if (getClass() != obj.getClass()) {
53             return false;
54         }
55         RevisionAwareXPathImpl other = (RevisionAwareXPathImpl) obj;
56         return absolute == other.absolute && Objects.equals(xpath, other.xpath);
57     }
58
59     @Override
60     public String getOriginalString() {
61         return xpath;
62     }
63 }