Fix warnings reported by maven
[yangtools.git] / yang / yang-binding / src / main / java / org / opendaylight / yangtools / yang / binding / InstanceIdentifier.java
1 /*\r
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.\r
3  *\r
4  * This program and the accompanying materials are made available under the\r
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
6  * and is available at http://www.eclipse.org/legal/epl-v10.html\r
7  */\r
8 package org.opendaylight.yangtools.yang.binding;\r
9 \r
10 import java.util.ArrayList;\r
11 import java.util.Collections;\r
12 import java.util.List;\r
13 \r
14 /**\r
15  * Uniquely identifies instance of data tree.\r
16  * \r
17  * \r
18  */\r
19 public class InstanceIdentifier {\r
20 \r
21     private final List<PathArgument> path;\r
22     private final Class<? extends DataObject> targetType;\r
23 \r
24     public InstanceIdentifier(Class<? extends DataObject> type) {\r
25         path = Collections.emptyList();\r
26         this.targetType = type;\r
27     }\r
28 \r
29     public InstanceIdentifier(List<PathArgument> path, Class<? extends DataObject> type) {\r
30         this.path = Collections.<PathArgument> unmodifiableList(new ArrayList<>(path));\r
31         this.targetType = type;\r
32     }\r
33 \r
34     /**\r
35      * \r
36      * @return path\r
37      */\r
38     public List<PathArgument> getPath() {\r
39         return this.path;\r
40     }\r
41 \r
42     public Class<?> getTargetType() {\r
43         return this.targetType;\r
44     }\r
45 \r
46     @Override\r
47     public String toString() {\r
48         return "InstanceIdentifier [path=" + path + "]";\r
49     }\r
50 \r
51     /**\r
52      * Path argument of instance identifier.\r
53      * \r
54      * Interface which implementations are used as path components of the\r
55      * instance path.\r
56      * \r
57      * @author ttkacik\r
58      * \r
59      */\r
60     public interface PathArgument {\r
61 \r
62     }\r
63 \r
64     public static class IdentifiableItem<I extends Identifiable<T>, T extends Identifier<I>> implements PathArgument {\r
65 \r
66         private final T key;\r
67         private final Class<? extends I> type;\r
68 \r
69         public IdentifiableItem(Class<I> type, T key) {\r
70             this.type = type;\r
71             this.key = key;\r
72         }\r
73 \r
74         T getKey() {\r
75             return this.key;\r
76         }\r
77 \r
78         Class<? extends I> getType() {\r
79             return this.type;\r
80         }\r
81 \r
82         @Override\r
83         public boolean equals(Object obj) {\r
84             if (obj == null) {\r
85                 return false;\r
86             }\r
87             if (obj.hashCode() != hashCode()) {\r
88                 return false;\r
89             }\r
90             if (!(obj instanceof IdentifiableItem<?, ?>)) {\r
91                 return false;\r
92             }\r
93             IdentifiableItem<?, ?> foreign = (IdentifiableItem<?, ?>) obj;\r
94             return key.equals(foreign.getKey());\r
95         }\r
96 \r
97         @Override\r
98         public int hashCode() {\r
99             return key.hashCode();\r
100         }\r
101 \r
102         @Override\r
103         public String toString() {\r
104             return "IdentifiableItem [key=" + key + "]";\r
105         }\r
106     }\r
107 }\r