blob: 6339e38d0251c75ef45cf8749104cb371663c964 [file] [log] [blame]
Brian Stanke2b4f32d2016-02-03 14:22:10 -05001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2016-present Open Networking Laboratory
Brian Stanke2b4f32d2016-02-03 14:22:10 -05003 *
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 */
16
Claudine Chiu31ad5272016-02-17 20:56:24 +000017package org.onosproject.net.key;
Brian Stanke2b4f32d2016-02-03 14:22:10 -050018
Thomas Vachuska48448082016-02-19 22:14:54 -080019import org.onlab.util.Identifier;
Brian Stanke2b4f32d2016-02-03 14:22:10 -050020
Jordan Halterman0d89ea32017-06-13 10:42:36 -070021import static com.google.common.base.Preconditions.checkArgument;
22
Brian Stanke2b4f32d2016-02-03 14:22:10 -050023/**
Thomas Vachuska48448082016-02-19 22:14:54 -080024 * Device key identifier backed by a string value.
Brian Stanke2b4f32d2016-02-03 14:22:10 -050025 */
Thomas Vachuska48448082016-02-19 22:14:54 -080026public final class DeviceKeyId extends Identifier<String> {
Brian Stanke2b4f32d2016-02-03 14:22:10 -050027
Jordan Halterman0d89ea32017-06-13 10:42:36 -070028 private static final int ID_MAX_LENGTH = 1024;
29
Brian Stanke2b4f32d2016-02-03 14:22:10 -050030 /**
31 * Constructor for serialization.
32 */
33 private DeviceKeyId() {
Thomas Vachuska48448082016-02-19 22:14:54 -080034 super();
Brian Stanke2b4f32d2016-02-03 14:22:10 -050035 }
36
37 /**
38 * Constructs the ID corresponding to a given string value.
39 *
40 * @param value the underlying value of this ID
41 */
42 private DeviceKeyId(String value) {
Thomas Vachuska48448082016-02-19 22:14:54 -080043 super(value);
Brian Stanke2b4f32d2016-02-03 14:22:10 -050044 }
45
46 /**
Thomas Vachuska48448082016-02-19 22:14:54 -080047 * Creates a new device key identifier.
Brian Stanke2b4f32d2016-02-03 14:22:10 -050048 *
Thomas Vachuska48448082016-02-19 22:14:54 -080049 * @param id backing identifier value
Brian Stanke2b4f32d2016-02-03 14:22:10 -050050 * @return device key identifier
51 */
Thomas Vachuska48448082016-02-19 22:14:54 -080052 public static DeviceKeyId deviceKeyId(String id) {
Jordan Halterman0d89ea32017-06-13 10:42:36 -070053 if (id != null) {
54 checkArgument(id.length() <= ID_MAX_LENGTH, "id exceeds maximum length " + ID_MAX_LENGTH);
55 }
Brian Stanke2b4f32d2016-02-03 14:22:10 -050056 return new DeviceKeyId(id);
57 }
58
Brian Stanke2b4f32d2016-02-03 14:22:10 -050059}