blob: 358153cce8000877f10b6fcbb66e824998fab784 [file] [log] [blame]
Srikanth Vavilapalli56db94f2015-01-22 22:30:17 -08001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
Srikanth Vavilapalli56db94f2015-01-22 22:30:17 -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.net.group;
17
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -080018import static com.google.common.base.MoreObjects.toStringHelper;
Srikanth Vavilapalli56db94f2015-01-22 22:30:17 -080019import static com.google.common.base.Preconditions.checkNotNull;
20
21import java.util.List;
22
Srikanth Vavilapalli56db94f2015-01-22 22:30:17 -080023import com.google.common.collect.ImmutableList;
24
Srikanth Vavilapalli0599d512015-01-30 12:57:56 -080025/**
26 * Immutable collection of group bucket.
27 */
Srikanth Vavilapalli56db94f2015-01-22 22:30:17 -080028public final class GroupBuckets {
29 private final List<GroupBucket> buckets;
30
31 /**
32 * Creates a immutable list of group bucket.
33 *
34 * @param buckets list of group bucket
35 */
36 public GroupBuckets(List<GroupBucket> buckets) {
37 this.buckets = ImmutableList.copyOf(checkNotNull(buckets));
38 }
39
40 /**
Srikanth Vavilapalli0599d512015-01-30 12:57:56 -080041 * Returns immutable list of group buckets.
Srikanth Vavilapalli56db94f2015-01-22 22:30:17 -080042 *
43 * @return list of group bucket
44 */
45 public List<GroupBucket> buckets() {
46 return buckets;
47 }
48
Srikanth Vavilapalli45c27c82015-01-30 12:57:56 -080049 @Override
50 public int hashCode() {
51 int result = 17;
52 int combinedHash = 0;
53 for (GroupBucket bucket:buckets) {
54 combinedHash = combinedHash + bucket.hashCode();
55 }
56 result = 31 * result + combinedHash;
57
58 return result;
59 }
60
61 @Override
62 public boolean equals(Object obj) {
63 if (obj instanceof GroupBuckets) {
64 return (this.buckets.containsAll(((GroupBuckets) obj).buckets) &&
65 ((GroupBuckets) obj).buckets.containsAll(this.buckets));
66 }
67 return false;
68 }
69
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -080070 @Override
71 public String toString() {
72 return toStringHelper(this)
Srikanth Vavilapalli10e75cd2015-04-13 16:21:24 -070073 .add("buckets", buckets.toString())
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -080074 .toString();
75 }
Srikanth Vavilapalli56db94f2015-01-22 22:30:17 -080076}