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