blob: 1b8fadbe8d75afb04235ef1a8eaac0d371e06b6e [file] [log] [blame]
Thomas Vachuska7b438af2015-07-07 09:52:07 -07001/*
Thomas Vachuska52f2cd12018-11-08 21:20:04 -08002 * Copyright 2018-present Open Networking Foundation
Thomas Vachuska7b438af2015-07-07 09:52:07 -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 */
Thomas Vachuska52f2cd12018-11-08 21:20:04 -080016package org.onosproject.net;
Thomas Vachuska7b438af2015-07-07 09:52:07 -070017
Jian Lib6d998e2016-02-29 11:41:18 -080018import org.onlab.util.Identifier;
Thomas Vachuska7b438af2015-07-07 09:52:07 -070019
20import static com.google.common.base.Preconditions.checkArgument;
21
22/**
23 * Representation of network tenant.
24 */
Jian Lib6d998e2016-02-29 11:41:18 -080025public final class TenantId extends Identifier<String> {
Thomas Vachuska7b438af2015-07-07 09:52:07 -070026
27 /**
28 * Represents no tenant, or an unspecified tenant.
29 */
30 public static final TenantId NONE = new TenantId();
31
Thomas Vachuska7b438af2015-07-07 09:52:07 -070032 // Public construction is prohibited
33 private TenantId(String id) {
Jian Lib6d998e2016-02-29 11:41:18 -080034 super(id);
Thomas Vachuska7b438af2015-07-07 09:52:07 -070035 checkArgument(id != null && id.length() > 0, "Tenant ID cannot be null or empty");
Thomas Vachuska7b438af2015-07-07 09:52:07 -070036 }
37
Thomas Vachuska7b438af2015-07-07 09:52:07 -070038 // Default constructor for serialization
39 protected TenantId() {
Jian Lib6d998e2016-02-29 11:41:18 -080040 super("");
Thomas Vachuska7b438af2015-07-07 09:52:07 -070041 }
42
43 /**
44 * Creates a tenant id using the supplied backing id.
45 *
46 * @param id network id
47 * @return network identifier
48 */
49 public static TenantId tenantId(String id) {
50 return new TenantId(id);
51 }
Thomas Vachuska7b438af2015-07-07 09:52:07 -070052}