blob: 34a3a3cf15ec880c3b25f0a2a9289a90dac688d5 [file] [log] [blame]
xuzhang585f9052015-07-22 11:20:13 +08001/*
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.app.vtnrsc;
17
18import static com.google.common.base.Preconditions.checkNotNull;
19
20import java.util.Objects;
21
22/**
xuzhang91b2ff42015-08-11 11:05:19 +080023 * Immutable representation of a subnet identifier.
xuzhang585f9052015-07-22 11:20:13 +080024 */
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 /**
xuzhang91b2ff42015-08-11 11:05:19 +080036 * Creates a Subnet identifier.
xuzhang585f9052015-07-22 11:20:13 +080037 *
xuzhang91b2ff42015-08-11 11:05:19 +080038 * @param subnetId the subnet identifier
39 * @return the subnet identifier
xuzhang585f9052015-07-22 11:20:13 +080040 */
41 public static SubnetId subnetId(String subnetId) {
42 return new SubnetId(subnetId);
43 }
44
xuzhang91b2ff42015-08-11 11:05:19 +080045 /**
46 * Returns the subnet identifier.
47 *
48 * @return the subnet identifier
49 */
50 public String subnetId() {
51 return subnetId;
52 }
53
xuzhang585f9052015-07-22 11:20:13 +080054 @Override
55 public int hashCode() {
56 return Objects.hash(subnetId);
57 }
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 }
xuzhang585f9052015-07-22 11:20:13 +080076}