blob: c7ea7ef1347c4963e54433c76c0436c8da7bffeb [file] [log] [blame]
Sithara Punnassery9306e6b2017-02-06 15:38:19 -08001/*
2 * Copyright 2016-present Open Networking Laboratory
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package org.onosproject.config.model;
17import java.util.Objects;
18
19import static com.google.common.base.MoreObjects.toStringHelper;
20import static com.google.common.base.Preconditions.checkNotNull;
21import static org.onosproject.config.model.ModelConstants.INCOMPLETE_SCHEMA_INFO;
22
23/**
24 * Representation of an entity which identifies a schema node in the schema /
25 * data tree.
26 */
27public class SchemaId implements Comparable<SchemaId>, Cloneable {
28
29 private String name;
30 private String nameSpace;
31
32 private SchemaId() {
33 }
34
35 public SchemaId(String name, String nameSpace) {
36 checkNotNull(name, INCOMPLETE_SCHEMA_INFO);
37 checkNotNull(nameSpace, INCOMPLETE_SCHEMA_INFO);
38 this.name = name;
39 this.nameSpace = nameSpace;
40 }
41
42 /**
43 * Returns node schema name. This is mandatory to identify node according
44 * to schema.
45 *
46 * @return node name
47 */
48 public String name() {
49 return name;
50 }
51
52 /**
53 * Returns node's namespace. This is mandatory serializers must translate
54 * any implicit namespace to explicit namespace.
55 *
56 * @return node's namespace
57 */
58 public String namespace() {
59 return nameSpace;
60 }
61
62 /**
63 * Creates and returns a deep copy of this object.
64 *
65 * @return cloned copy
66 * @throws CloneNotSupportedException if the object's class does not
67 * support the {@code Cloneable} interface
68 */
69 public SchemaId clone() throws CloneNotSupportedException {
70 return (SchemaId) super.clone();
71 }
72
73 @Override
74 public int hashCode() {
75 return Objects.hash(name, nameSpace);
76 }
77
78 @Override
79 public boolean equals(Object obj) {
80 if (obj == null) {
81 return false;
82 }
83 SchemaId that = (SchemaId) obj;
84 return Objects.equals(name, that.name) &&
85 Objects.equals(nameSpace, that.nameSpace);
86 }
87
88 @Override
89 public int compareTo(SchemaId o) {
90 checkNotNull(o);
91 if (name.equals(o.name)) {
92 if (nameSpace.equals(o.nameSpace)) {
93 return 0;
94 }
95 }
96 return -1;
97 }
98
99 @Override
100 public String toString() {
101 return toStringHelper(getClass())
102 .add("name", name)
103 .add("nameSpace", nameSpace)
104 .toString();
105 }
106}