blob: 196c17d4b0bb71d55700eade269416082b4db3f9 [file] [log] [blame]
Thomas Vachuska7b438af2015-07-07 09:52:07 -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.incubator.net.virtual;
17
18import com.google.common.annotations.Beta;
19
20import java.util.Objects;
21
22import static com.google.common.base.Preconditions.checkArgument;
23
24/**
25 * Representation of network tenant.
26 */
27@Beta
28public final class TenantId {
29
30 /**
31 * Represents no tenant, or an unspecified tenant.
32 */
33 public static final TenantId NONE = new TenantId();
34
35
36 private final String id;
37
38 // Public construction is prohibited
39 private TenantId(String id) {
40 checkArgument(id != null && id.length() > 0, "Tenant ID cannot be null or empty");
41 this.id = id;
42 }
43
44
45 // Default constructor for serialization
46 protected TenantId() {
47 this.id = "";
48 }
49
50 /**
51 * Creates a tenant id using the supplied backing id.
52 *
53 * @param id network id
54 * @return network identifier
55 */
56 public static TenantId tenantId(String id) {
57 return new TenantId(id);
58 }
59
60 @Override
61 public int hashCode() {
HIGUCHI Yutaca9cc8e2015-10-29 23:26:51 -070062 return id.hashCode();
Thomas Vachuska7b438af2015-07-07 09:52:07 -070063 }
64
65 @Override
66 public boolean equals(Object obj) {
67 if (this == obj) {
68 return true;
69 }
70 if (obj instanceof TenantId) {
71 final TenantId that = (TenantId) obj;
72 return this.getClass() == that.getClass() &&
73 Objects.equals(this.id, that.id);
74 }
75 return false;
76 }
77
78 @Override
79 public String toString() {
80 return id;
81 }
82
83}