blob: 5cb991b3947eb119fec23b281e15d5377b75d64f [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.YangModuleInformation;
21import org.onosproject.yms.ysr.YangModuleLibrary;
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 library.
31 */
sonu guptaeff184b2016-11-24 12:43:49 +053032public class DefaultYangModuleLibrary implements YangModuleLibrary {
Bharat saraswalf53b29a2016-09-27 15:35:15 +053033
34 private final String moduleSetId;
35 private final List<YangModuleInformation> moduleInformation;
36
37 /**
38 * Creates an instance of YANG module library.
39 *
40 * @param moduleSetId module id
41 */
sonu guptaeff184b2016-11-24 12:43:49 +053042 public DefaultYangModuleLibrary(String moduleSetId) {
Bharat saraswalf53b29a2016-09-27 15:35:15 +053043 this.moduleSetId = moduleSetId;
44 moduleInformation = new ArrayList<>();
45 }
46
47 @Override
48 public String moduleSetId() {
49 return moduleSetId;
50 }
51
52 @Override
53 public List<YangModuleInformation> yangModuleList() {
54 return ImmutableList.copyOf(moduleInformation);
55 }
56
57 /**
58 * Adds module information.
59 *
60 * @param information module information
61 */
62 void addModuleInformation(YangModuleInformation information) {
63 moduleInformation.add(information);
64 }
65
66 @Override
67 public int hashCode() {
68 return Objects.hash(moduleInformation, moduleSetId);
69 }
70
71 @Override
72 public boolean equals(Object obj) {
73 if (this == obj) {
74 return true;
75 }
76 if (obj instanceof DefaultYangModuleLibrary) {
77 DefaultYangModuleLibrary that = (DefaultYangModuleLibrary) obj;
78 return Objects.equals(moduleInformation, that.moduleInformation) &&
79 Objects.equals(moduleSetId, that.moduleSetId);
80 }
81 return false;
82 }
83
84 @Override
85 public String toString() {
86 return toStringHelper(this)
87 .add("moduleInformation", moduleInformation)
88 .add("moduleId", moduleSetId)
89 .toString();
90 }
91}