Fixing sonar issues 3
[yangtools.git] / yang / yang-binding / src / main / java / org / opendaylight / yangtools / yang / binding / InstanceIdentifier.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.binding;
9
10 import java.util.ArrayList;
11 import java.util.Collections;
12 import java.util.List;
13
14 /**
15  * Uniquely identifies instance of data tree.
16  * 
17  * 
18  */
19 public class InstanceIdentifier {
20
21     private final List<PathArgument> path;
22     private final Class<? extends DataObject> targetType;
23
24     public InstanceIdentifier(Class<? extends DataObject> type) {
25         path = Collections.emptyList();
26         this.targetType = type;
27     }
28
29     public InstanceIdentifier(List<PathArgument> path, Class<? extends DataObject> type) {
30         this.path = Collections.<PathArgument> unmodifiableList(new ArrayList<>(path));
31         this.targetType = type;
32     }
33
34     /**
35      * 
36      * @return
37      */
38     public List<PathArgument> getPath() {
39         return this.path;
40     }
41
42     public Class<?> getTargetType() {
43         return this.targetType;
44     }
45
46     /**
47      * Path argument of instance identifier.
48      * 
49      * Interface which implementations are used as path components of the
50      * instance path.
51      * 
52      * @author ttkacik
53      * 
54      */
55     interface PathArgument {
56
57     }
58
59     public static class IdentifiableItem<I extends Identifiable<T>, T extends Identifier<I>> implements PathArgument {
60
61         private final T key;
62         private final Class<? extends I> type;
63
64         public IdentifiableItem(Class<I> type, T key) {
65             this.type = type;
66             this.key = key;
67         }
68
69         T getKey() {
70             return this.key;
71         }
72
73         Class<? extends I> getType() {
74             return this.type;
75         }
76     }
77 }