blob: 3f95559c59fa438420d52d81dc0ea62d3fd05104 [file] [log] [blame]
Sho SHIMIZUe3cc0b92014-11-20 16:18:29 -08001/*
Ray Milkey34c95902015-04-15 09:47:53 -07002 * Copyright 2014-2015 Open Networking Laboratory
Sho SHIMIZUe3cc0b92014-11-20 16:18:29 -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 */
Brian O'Connorabafb502014-12-02 22:26:20 -080016package org.onosproject.core;
Sho SHIMIZUe3cc0b92014-11-20 16:18:29 -080017
18import com.google.common.base.MoreObjects;
19
20import java.util.Objects;
21
22/**
23 * Default implementation of {@link GroupId}.
24 */
Jian Lib6d998e2016-02-29 11:41:18 -080025// TODO: require refactor to extend from Identifier base class
Sho SHIMIZUe3cc0b92014-11-20 16:18:29 -080026public class DefaultGroupId implements GroupId {
27
28 private final int id;
29
30 public DefaultGroupId(int id) {
31 this.id = id;
32 }
33
34 // Constructor for serialization
35 private DefaultGroupId() {
36 this.id = 0;
37 }
38
39 @Override
40 public int id() {
Srikanth Vavilapalli45c27c82015-01-30 12:57:56 -080041 return this.id;
Sho SHIMIZUe3cc0b92014-11-20 16:18:29 -080042 }
43
44 @Override
45 public int hashCode() {
HIGUCHI Yutaca9cc8e2015-10-29 23:26:51 -070046 return id;
Sho SHIMIZUe3cc0b92014-11-20 16:18:29 -080047 }
48
49 @Override
50 public boolean equals(Object obj) {
51 if (this == obj) {
52 return true;
53 }
54 if (!(obj instanceof DefaultGroupId)) {
55 return false;
56 }
57 final DefaultGroupId other = (DefaultGroupId) obj;
58 return Objects.equals(this.id, other.id);
59 }
60
61 @Override
62 public String toString() {
63 return MoreObjects.toStringHelper(this)
Saurav Das0fd79d92016-03-07 10:58:36 -080064 .add("id", "0x" + Integer.toHexString(id))
Sho SHIMIZUe3cc0b92014-11-20 16:18:29 -080065 .toString();
66 }
67}