blob: 94295b20566af67ec92cf731e03fe5cbd1a2d509 [file] [log] [blame]
Bharat saraswalf53b29a2016-09-27 15:35:15 +05301/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
Bharat saraswalf53b29a2016-09-27 15:35:15 +05303 *
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
17package org.onosproject.yms.app.ysr;
18
19import org.onosproject.yms.ysr.YangModuleIdentifier;
20
21import java.util.Comparator;
22import java.util.Objects;
23
24import static com.google.common.base.MoreObjects.toStringHelper;
25
26/**
27 * Representation of default YANG module identifier.
28 */
sonu guptaeff184b2016-11-24 12:43:49 +053029public class DefaultYangModuleIdentifier implements YangModuleIdentifier,
Bharat saraswalf53b29a2016-09-27 15:35:15 +053030 Comparator<YangModuleIdentifier> {
31
32 private final String moduleName;
33 private final String revision;
34
35 /**
36 * Creates an instance of YANG module identifier.
37 *
38 * @param moduleName module's name
39 * @param revision module's revision
40 */
41 DefaultYangModuleIdentifier(String moduleName, String revision) {
42 this.moduleName = moduleName;
43 this.revision = revision;
44 }
45
46 @Override
47 public String moduleName() {
48 return moduleName;
49 }
50
51 @Override
52 public String revision() {
53 return revision;
54 }
55
56 @Override
57 public int hashCode() {
58 return Objects.hash(moduleName, revision);
59 }
60
61 @Override
62 public int compare(YangModuleIdentifier id1, YangModuleIdentifier id2) {
63 int compare = id1.moduleName().compareTo(id2.moduleName());
64 if (compare != 0) {
65 return compare;
66 }
67 return id1.revision().compareTo(id2.revision());
68 }
69
70 @Override
71 public boolean equals(Object obj) {
72 if (this == obj) {
73 return true;
74 }
75 if (obj instanceof DefaultYangModuleIdentifier) {
76 DefaultYangModuleIdentifier that = (DefaultYangModuleIdentifier) obj;
77 return Objects.equals(moduleName, that.moduleName) &&
78 Objects.equals(revision, that.revision);
79 }
80 return false;
81 }
82
83 @Override
84 public String toString() {
85 return toStringHelper(this)
86 .add("moduleName", moduleName)
87 .add("revision", revision)
88 .toString();
89 }
90}