blob: 5833f6694349622cfc209d1ccce1ab29ddf983c3 [file] [log] [blame]
pierventre30368ab2021-02-24 23:23:22 +01001/*
2 * Copyright 2021-present Open Networking Foundation
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.segmentrouting.policy.api;
17
18import org.onlab.util.Identifier;
19
20import static com.google.common.base.Preconditions.checkArgument;
21import static com.google.common.base.Preconditions.checkNotNull;
22
23/**
24 * Representation of a traffic match id.
25 */
26public final class TrafficMatchId extends Identifier<Integer> {
27
28 protected TrafficMatchId(int value) {
29 super(value);
30 }
31
32 /**
33 * Converts an int into a traffic match id.
34 *
35 * @param value the value of the id
36 * @return the traffic match id
37 */
38 public static TrafficMatchId trafficMatchId(int value) {
39 return new TrafficMatchId(value);
40 }
41
42 /**
43 * Returns the id of the traffic match given the value.
44 *
45 * @param name traffic match id value
46 * @return traffic match id
47 */
48 public static TrafficMatchId of(String name) {
49 checkNotNull(name);
50 checkArgument(!name.isEmpty(), "Name cannot be empty");
51 return new TrafficMatchId(Integer.parseInt(name));
52 }
53
54 @Override
55 public String toString() {
56 return String.valueOf(this.identifier);
57 }
58
59}