Sithara Punnassery | 9306e6b | 2017-02-06 15:38:19 -0800 | [diff] [blame] | 1 | /* |
| 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 | */ |
| 16 | package org.onosproject.config.model; |
| 17 | import java.util.Objects; |
| 18 | |
| 19 | import static com.google.common.base.MoreObjects.toStringHelper; |
| 20 | import static com.google.common.base.Preconditions.checkNotNull; |
| 21 | import 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 | */ |
| 27 | public 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 | } |