blob: ee56ba9d304cfc5d69e3f751a90ac8486db181e7 [file] [log] [blame]
Sho SHIMIZUb2b2d982015-09-11 15:35:06 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2015-present Open Networking Foundation
Sho SHIMIZUb2b2d982015-09-11 15:35:06 -07003 *
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 */
16package org.onosproject.vtnrsc;
17
18import java.util.Objects;
19
20import static com.google.common.base.MoreObjects.toStringHelper;
21import static com.google.common.base.Preconditions.checkNotNull;
22
23/**
24 * Immutable representation of a security group.
25 */
26public final class SecurityGroup {
27 private final String securityGroup;
28
29 /**
30 * Returns the securityGroup.
31 *
32 * @return securityGroup
33 */
34 public String securityGroup() {
35 return securityGroup;
36 }
37 // Public construction is prohibited
38 private SecurityGroup(String securityGroup) {
39 checkNotNull(securityGroup, "SecurityGroup cannot be null");
40 this.securityGroup = securityGroup;
41 }
42
43 /**
44 * Creates a securityGroup using the supplied securityGroup.
45 *
46 * @param securityGroup security group
47 * @return securityGroup
48 */
49 public static SecurityGroup securityGroup(String securityGroup) {
50 return new SecurityGroup(securityGroup);
51 }
52
53 @Override
54 public int hashCode() {
HIGUCHI Yutaca9cc8e2015-10-29 23:26:51 -070055 return securityGroup.hashCode();
Sho SHIMIZUb2b2d982015-09-11 15:35:06 -070056 }
57
58 @Override
59 public boolean equals(Object obj) {
60 if (this == obj) {
61 return true;
62 }
63 if (obj instanceof SecurityGroup) {
64 final SecurityGroup that = (SecurityGroup) obj;
65 return this.getClass() == that.getClass()
66 && Objects.equals(this.securityGroup, that.securityGroup);
67 }
68 return false;
69 }
70
71 @Override
72 public String toString() {
73 return toStringHelper(this).add("securityGroup", securityGroup)
74 .toString();
75 }
76
77}