blob: 243e52161c7cb83161d65c74041d92f2fc2a64a0 [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 */
25public class DefaultGroupId implements GroupId {
26
27 private final int id;
28
29 public DefaultGroupId(int id) {
30 this.id = id;
31 }
32
33 // Constructor for serialization
34 private DefaultGroupId() {
35 this.id = 0;
36 }
37
38 @Override
39 public int id() {
Srikanth Vavilapalli45c27c82015-01-30 12:57:56 -080040 return this.id;
Sho SHIMIZUe3cc0b92014-11-20 16:18:29 -080041 }
42
43 @Override
44 public int hashCode() {
HIGUCHI Yutaca9cc8e2015-10-29 23:26:51 -070045 return id;
Sho SHIMIZUe3cc0b92014-11-20 16:18:29 -080046 }
47
48 @Override
49 public boolean equals(Object obj) {
50 if (this == obj) {
51 return true;
52 }
53 if (!(obj instanceof DefaultGroupId)) {
54 return false;
55 }
56 final DefaultGroupId other = (DefaultGroupId) obj;
57 return Objects.equals(this.id, other.id);
58 }
59
60 @Override
61 public String toString() {
62 return MoreObjects.toStringHelper(this)
63 .add("id", id)
64 .toString();
65 }
66}