Deprecate all MD-SAL APIs
[controller.git] / opendaylight / md-sal / sal-dom-api / src / main / java / org / opendaylight / controller / md / sal / dom / api / DOMDataTreeIdentifier.java
1 /*
2  * Copyright (c) 2015 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.controller.md.sal.dom.api;
9
10 import static java.util.Objects.requireNonNull;
11
12 import com.google.common.base.MoreObjects;
13 import java.io.Serializable;
14 import java.util.Iterator;
15 import org.eclipse.jdt.annotation.NonNull;
16 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
17 import org.opendaylight.yangtools.concepts.Immutable;
18 import org.opendaylight.yangtools.concepts.Path;
19 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
20 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
21
22 /**
23  * A unique identifier for a particular subtree. It is composed of the logical
24  * data store type and the instance identifier of the root node.
25  *
26  * @deprecated Use {@link org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier} instead.
27  */
28 @Deprecated
29 public final class DOMDataTreeIdentifier implements Immutable,
30         Path<DOMDataTreeIdentifier>, Serializable, Comparable<DOMDataTreeIdentifier> {
31     private static final long serialVersionUID = 1L;
32     private final @NonNull YangInstanceIdentifier rootIdentifier;
33     private final @NonNull LogicalDatastoreType datastoreType;
34
35     public DOMDataTreeIdentifier(final LogicalDatastoreType datastoreType,
36             final YangInstanceIdentifier rootIdentifier) {
37         this.datastoreType = requireNonNull(datastoreType);
38         this.rootIdentifier = requireNonNull(rootIdentifier);
39     }
40
41     /**
42      * Return a counterpart to an MD-SAL data tree identifier.
43      *
44      * @return Controller data tree identifier.
45      */
46     public static DOMDataTreeIdentifier fromMdsal(final org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier mdsal) {
47         return new DOMDataTreeIdentifier(LogicalDatastoreType.fromMdsal(mdsal.getDatastoreType()),
48             mdsal.getRootIdentifier());
49     }
50
51     /**
52      * Return MD-SAL counterpart of this object.
53      *
54      * @return MD-SAL data tree identifier.
55      */
56     public org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier toMdsal() {
57         return new org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier(datastoreType.toMdsal(), rootIdentifier);
58     }
59
60     /**
61      * Return the logical data store type.
62      *
63      * @return Logical data store type. Guaranteed to be non-null.
64      */
65     public @NonNull LogicalDatastoreType getDatastoreType() {
66         return datastoreType;
67     }
68
69     /**
70      * Return the {@link YangInstanceIdentifier} of the root node.
71      *
72      * @return Instance identifier corresponding to the root node.
73      */
74     public @NonNull YangInstanceIdentifier getRootIdentifier() {
75         return rootIdentifier;
76     }
77
78     @Override
79     public boolean contains(final DOMDataTreeIdentifier other) {
80         return datastoreType == other.datastoreType && rootIdentifier.contains(other.rootIdentifier);
81     }
82
83     @Override
84     public int hashCode() {
85         final int prime = 31;
86         int result = 1;
87         result = prime * result + datastoreType.hashCode();
88         result = prime * result + rootIdentifier.hashCode();
89         return result;
90     }
91
92     @Override
93     public boolean equals(final Object obj) {
94         if (this == obj) {
95             return true;
96         }
97         if (!(obj instanceof DOMDataTreeIdentifier)) {
98             return false;
99         }
100         DOMDataTreeIdentifier other = (DOMDataTreeIdentifier) obj;
101         if (datastoreType != other.datastoreType) {
102             return false;
103         }
104         return rootIdentifier.equals(other.rootIdentifier);
105     }
106
107     @Override
108     public int compareTo(final DOMDataTreeIdentifier obj) {
109         int cmp = datastoreType.compareTo(obj.datastoreType);
110         if (cmp != 0) {
111             return cmp;
112         }
113
114         final Iterator<PathArgument> mi = rootIdentifier.getPathArguments().iterator();
115         final Iterator<PathArgument> oi = obj.rootIdentifier.getPathArguments().iterator();
116
117         while (mi.hasNext()) {
118             if (!oi.hasNext()) {
119                 return 1;
120             }
121
122             final PathArgument ma = mi.next();
123             final PathArgument oa = oi.next();
124             cmp = ma.compareTo(oa);
125             if (cmp != 0) {
126                 return cmp;
127             }
128         }
129
130         return oi.hasNext() ? -1 : 0;
131     }
132
133     @Override
134     public String toString() {
135         return MoreObjects.toStringHelper(this).add("datastore", datastoreType).add("root", rootIdentifier).toString();
136     }
137 }