blob: f2213a8975d24a794adc4452d8ff687d9a4d20bc [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 com.google.common.collect.ImmutableList;
sonu guptaeff184b2016-11-24 12:43:49 +053020import org.onosproject.yangutils.datamodel.YangNamespace;
Bharat saraswalf53b29a2016-09-27 15:35:15 +053021import org.onosproject.yms.ysr.YangModuleIdentifier;
22import org.onosproject.yms.ysr.YangModuleInformation;
23
24import java.util.ArrayList;
25import java.util.List;
26import java.util.Objects;
27
28import static com.google.common.base.MoreObjects.toStringHelper;
29
30/**
31 * Representation of default YANG module information.
32 */
33class DefaultYangModuleInformation implements YangModuleInformation {
34
35 private final YangModuleIdentifier moduleIdentifier;
sonu guptaeff184b2016-11-24 12:43:49 +053036 private final YangNamespace nameSpace;
Bharat saraswalf53b29a2016-09-27 15:35:15 +053037 private final List<String> features;
38 private final List<YangModuleIdentifier> subModuleIdentifiers;
39
40 /**
41 * Creates an instance of YANG module information.
42 *
43 * @param moduleIdentifier module identifier
44 * @param nameSpace name space of module
45 */
46 DefaultYangModuleInformation(YangModuleIdentifier moduleIdentifier,
sonu guptaeff184b2016-11-24 12:43:49 +053047 YangNamespace nameSpace) {
Bharat saraswalf53b29a2016-09-27 15:35:15 +053048 this.moduleIdentifier = moduleIdentifier;
49 this.nameSpace = nameSpace;
50 subModuleIdentifiers = new ArrayList<>();
51 features = new ArrayList<>();
52 }
53
54 @Override
55 public YangModuleIdentifier moduleIdentifier() {
56 return moduleIdentifier;
57 }
58
sonu guptaeff184b2016-11-24 12:43:49 +053059 public YangNamespace namespace() {
Bharat saraswalf53b29a2016-09-27 15:35:15 +053060 return nameSpace;
61 }
62
63 @Override
64 public List<String> featureList() {
65 return ImmutableList.copyOf(features);
66 }
67
68 @Override
69 public List<YangModuleIdentifier> subModuleIdentifiers() {
70 return ImmutableList.copyOf(subModuleIdentifiers);
71 }
72
73 /**
74 * Adds to YANG sub module identifier list.
75 *
76 * @param subModuleIdentifier YANG sub module identifier
77 */
78 void addSubModuleIdentifiers(YangModuleIdentifier subModuleIdentifier) {
79 subModuleIdentifiers.add(subModuleIdentifier);
80 }
81
82 @Override
83 public int hashCode() {
84 return Objects.hash(moduleIdentifier, subModuleIdentifiers, nameSpace, features);
85 }
86
87 @Override
88 public boolean equals(Object obj) {
89 if (this == obj) {
90 return true;
91 }
92 if (obj instanceof DefaultYangModuleInformation) {
93 DefaultYangModuleInformation that = (DefaultYangModuleInformation) obj;
94 return Objects.equals(moduleIdentifier, that.moduleIdentifier) &&
95 Objects.equals(nameSpace, that.nameSpace) &&
96 Objects.equals(features, that.features) &&
97 Objects.equals(subModuleIdentifiers, that.subModuleIdentifiers);
98 }
99 return false;
100 }
101
102 @Override
103 public String toString() {
104 return toStringHelper(this)
105 .add("yangModuleIdentifier", moduleIdentifier)
106 .add("nameSpace", nameSpace)
107 .add("features", features)
108 .add("yangModuleIdentifiers", subModuleIdentifiers)
109 .toString();
110 }
111}