blob: a862a79b647a25503e4095f3b9e809bc5cb11d93 [file] [log] [blame]
sangho5db8e052016-01-29 16:08:23 +09001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2016-present Open Networking Laboratory
sangho5db8e052016-01-29 16:08:23 +09003 *
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 */
sangho93447f12016-02-24 00:33:22 +090016package org.onosproject.openstackinterface;
sangho5db8e052016-01-29 16:08:23 +090017
18import java.util.Collection;
19import java.util.Collections;
20import java.util.Objects;
21
22/**
23 * Represents Openstack Security Group information.
24 */
25public final class OpenstackSecurityGroup {
26
27 private String description;
28 private String id;
29 private String name;
30 private Collection<OpenstackSecurityGroupRule> rules;
31 private String tenantId;
32
33 private OpenstackSecurityGroup(String description, String id, String name,
34 Collection<OpenstackSecurityGroupRule> rules,
35 String tenantId) {
36 this.description = description;
37 this.id = id;
38 this.name = name;
39 this.tenantId = tenantId;
40 this.rules = rules;
41 }
42
43 /**
44 * Returns the description of the security group.
45 *
46 * @return description
47 */
48 public String description() {
49 return this.description;
50 }
51
52 /**
53 * Returns ID of the security group.
54 *
55 * @return ID
56 */
57 public String id() {
58 return this.id;
59 }
60
61 /**
62 * Returns the name of the security group.
63 *
64 * @return name
65 */
66 public String name() {
67 return this.name;
68 }
69
70 /**
71 * Returns the list of the security group rules.
72 *
73 * @return Collection of OpenstackSecurityGroupRule objects
74 */
75 public Collection<OpenstackSecurityGroupRule> rules() {
76 return Collections.unmodifiableCollection(rules);
77 }
78
79 /**
80 * Returns the Tenant ID.
81 *
82 * @return tenant ID
83 */
84 public String tenantId() {
85 return this.tenantId;
86 }
87
88 @Override
89 public String toString() {
90 StringBuilder sbuilder = new StringBuilder("Security Group :")
91 .append(description + ",")
92 .append(id + ",")
93 .append(name + ",");
94 rules.forEach(rule -> sbuilder.append(rule.toString()));
95 sbuilder.append(tenantId);
96
97 return sbuilder.toString();
98 }
99
100 @Override
101 public boolean equals(Object o) {
102 if (this == o) {
103 return true;
104 }
105 if (o instanceof OpenstackSecurityGroup) {
106 OpenstackSecurityGroup that = (OpenstackSecurityGroup) o;
107
108 return this.description.equals(that.description) &&
109 this.tenantId.equals(that.tenantId) &&
110 this.id.equals(that.id) &&
111 this.name.equals(that.name) &&
112 this.rules.containsAll(that.rules);
113 }
114
sangho0c2a3da2016-02-16 13:39:07 +0900115 return false;
sangho5db8e052016-01-29 16:08:23 +0900116 }
117
118 @Override
119 public int hashCode() {
120 return Objects.hash(description, tenantId, id, name, rules);
121 }
122
123 /**
124 * Returns the SecurityGroupRule builder object.
125 *
126 * @return builder object
127 */
128 public static Builder builder() {
129 return new Builder();
130 }
131
132 /**
133 * Represents the builder of the SecurityGroupRule.
134 *
135 */
136 public static final class Builder {
137 private String description;
138 private String id;
139 private String name;
140 private Collection<OpenstackSecurityGroupRule> rules;
141 private String tenantId;
142
143 /**
144 * Sets the description of the security group.
145 *
146 * @param description description
147 * @return builder object
148 */
149 public Builder description(String description) {
150 this.description = description;
151 return this;
152 }
153
154 /**
155 * Sets the ID of the security group.
156 *
157 * @param id ID
158 * @return builder object
159 */
160 public Builder id(String id) {
161 this.id = id;
162 return this;
163 }
164
165 /**
166 * Sets the name of the security group.
167 *
168 * @param name name
169 * @return builder object
170 */
171 public Builder name(String name) {
172 this.name = name;
173 return this;
174 }
175
176 /**
177 * Sets Security Group rules.
178 *
179 * @param rules security group rules
180 * @return builder object
181 */
182 public Builder rules(Collection<OpenstackSecurityGroupRule> rules) {
183 this.rules = rules;
184 return this;
185 }
186
187 /**
188 * Sets the tenant ID of the security group.
189 *
190 * @param tenantId tenant ID
191 * @return builder object
192 */
193 public Builder tenantId(String tenantId) {
194 this.tenantId = tenantId;
195 return this;
196 }
197
198 /**
199 * Creates the OpenstackSecurityGroup object.
200 *
201 * @return OpenstackSecurityGroup object
202 */
203 public OpenstackSecurityGroup build() {
204 return new OpenstackSecurityGroup(description, id, name, rules, tenantId);
205 }
206 }
207}