blob: 5ca8f3084e70700c1befa6caee084a7a425e968d [file] [log] [blame]
Srikanth Vavilapalli56db94f2015-01-22 22:30:17 -08001/*
2 * Copyright 2015 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.onosproject.net.group;
17
18import static com.google.common.base.Preconditions.checkNotNull;
19
20import java.util.List;
21
Srikanth Vavilapalli56db94f2015-01-22 22:30:17 -080022import com.google.common.collect.ImmutableList;
23
Srikanth Vavilapalli0599d512015-01-30 12:57:56 -080024/**
25 * Immutable collection of group bucket.
26 */
Srikanth Vavilapalli56db94f2015-01-22 22:30:17 -080027public final class GroupBuckets {
28 private final List<GroupBucket> buckets;
29
30 /**
31 * Creates a immutable list of group bucket.
32 *
33 * @param buckets list of group bucket
34 */
35 public GroupBuckets(List<GroupBucket> buckets) {
36 this.buckets = ImmutableList.copyOf(checkNotNull(buckets));
37 }
38
39 /**
Srikanth Vavilapalli0599d512015-01-30 12:57:56 -080040 * Returns immutable list of group buckets.
Srikanth Vavilapalli56db94f2015-01-22 22:30:17 -080041 *
42 * @return list of group bucket
43 */
44 public List<GroupBucket> buckets() {
45 return buckets;
46 }
47
Srikanth Vavilapalli45c27c82015-01-30 12:57:56 -080048 @Override
49 public int hashCode() {
50 int result = 17;
51 int combinedHash = 0;
52 for (GroupBucket bucket:buckets) {
53 combinedHash = combinedHash + bucket.hashCode();
54 }
55 result = 31 * result + combinedHash;
56
57 return result;
58 }
59
60 @Override
61 public boolean equals(Object obj) {
62 if (obj instanceof GroupBuckets) {
63 return (this.buckets.containsAll(((GroupBuckets) obj).buckets) &&
64 ((GroupBuckets) obj).buckets.containsAll(this.buckets));
65 }
66 return false;
67 }
68
Srikanth Vavilapalli56db94f2015-01-22 22:30:17 -080069}