blob: f8b65e7dc4af95f4d9dbda1333516c3cf31d968d [file] [log] [blame]
Madan Jampaniab7e7cd2016-01-14 14:02:32 -08001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
Madan Jampaniab7e7cd2016-01-14 14:02:32 -08003 *
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.cluster;
17
Jian Lib6d998e2016-02-29 11:41:18 -080018import org.onlab.util.Identifier;
Madan Jampaniab7e7cd2016-01-14 14:02:32 -080019
Jian Lib6d998e2016-02-29 11:41:18 -080020import static com.google.common.base.Preconditions.checkArgument;
Madan Jampaniab7e7cd2016-01-14 14:02:32 -080021
22/**
23 * {@link Partition} identifier.
24 */
Jian Lib6d998e2016-02-29 11:41:18 -080025public class PartitionId extends Identifier<Integer> implements Comparable<PartitionId> {
Madan Jampaniab7e7cd2016-01-14 14:02:32 -080026
27 /**
28 * Creates a partition identifier from an integer.
29 *
30 * @param id input integer
31 */
32 public PartitionId(int id) {
Jian Lib6d998e2016-02-29 11:41:18 -080033 super(id);
Madan Jampaniab7e7cd2016-01-14 14:02:32 -080034 checkArgument(id >= 0, "partition id must be non-negative");
Madan Jampaniab7e7cd2016-01-14 14:02:32 -080035 }
36
37 /**
38 * Creates a partition identifier from an integer.
39 *
40 * @param id input integer
Jian Lidfba7392016-01-22 16:46:58 -080041 * @return partition identification
Madan Jampaniab7e7cd2016-01-14 14:02:32 -080042 */
43 public static PartitionId from(int id) {
44 return new PartitionId(id);
45 }
46
47 /**
48 * Returns the partition identifier as an integer.
49 * @return number
50 */
51 public int asInt() {
Jian Lib6d998e2016-02-29 11:41:18 -080052 return id();
Madan Jampaniab7e7cd2016-01-14 14:02:32 -080053 }
54
55 @Override
56 public int compareTo(PartitionId that) {
Jian Lib6d998e2016-02-29 11:41:18 -080057 return Integer.compare(this.identifier, that.identifier);
Madan Jampaniab7e7cd2016-01-14 14:02:32 -080058 }
59}