blob: 7e5111464982413747e8378f14e5a27ae2f6dc25 [file] [log] [blame]
Sho SHIMIZUe3cc0b92014-11-20 16:18:29 -08001/*
2 * Copyright 2014 Open Networking Laboratory
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.onlab.onos.core;
17
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() {
40 return 0;
41 }
42
43 @Override
44 public int hashCode() {
45 return Objects.hash(id);
46 }
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}