blob: 79778f76928fab24e47d0502d4816125dc5b58eb [file] [log] [blame]
Bharat saraswalf53b29a2016-09-27 15:35:15 +05301/*
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
17package org.onosproject.yms.app.ysr;
18
19import com.google.common.collect.ImmutableList;
20import org.onosproject.yms.ysr.YangModuleIdentifier;
21import org.onosproject.yms.ysr.YangModuleInformation;
22
23import java.util.ArrayList;
24import java.util.List;
25import java.util.Objects;
26
27import static com.google.common.base.MoreObjects.toStringHelper;
28
29/**
30 * Representation of default YANG module information.
31 */
32class DefaultYangModuleInformation implements YangModuleInformation {
33
34 private final YangModuleIdentifier moduleIdentifier;
35 private final String nameSpace;
36 private final List<String> features;
37 private final List<YangModuleIdentifier> subModuleIdentifiers;
38
39 /**
40 * Creates an instance of YANG module information.
41 *
42 * @param moduleIdentifier module identifier
43 * @param nameSpace name space of module
44 */
45 DefaultYangModuleInformation(YangModuleIdentifier moduleIdentifier,
46 String nameSpace) {
47 this.moduleIdentifier = moduleIdentifier;
48 this.nameSpace = nameSpace;
49 subModuleIdentifiers = new ArrayList<>();
50 features = new ArrayList<>();
51 }
52
53 @Override
54 public YangModuleIdentifier moduleIdentifier() {
55 return moduleIdentifier;
56 }
57
58 @Override
59 public String namespace() {
60 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}