Srikanth Vavilapalli | 56db94f | 2015-01-22 22:30:17 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Foundation |
Srikanth Vavilapalli | 56db94f | 2015-01-22 22:30:17 -0800 | [diff] [blame] | 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 | */ |
| 16 | package org.onosproject.net.group; |
| 17 | |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 18 | import static com.google.common.base.MoreObjects.toStringHelper; |
Srikanth Vavilapalli | 56db94f | 2015-01-22 22:30:17 -0800 | [diff] [blame] | 19 | import static com.google.common.base.Preconditions.checkNotNull; |
| 20 | |
| 21 | import java.util.List; |
| 22 | |
Srikanth Vavilapalli | 56db94f | 2015-01-22 22:30:17 -0800 | [diff] [blame] | 23 | import com.google.common.collect.ImmutableList; |
| 24 | |
Srikanth Vavilapalli | 0599d51 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 25 | /** |
| 26 | * Immutable collection of group bucket. |
| 27 | */ |
Srikanth Vavilapalli | 56db94f | 2015-01-22 22:30:17 -0800 | [diff] [blame] | 28 | public 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 Vavilapalli | 0599d51 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 41 | * Returns immutable list of group buckets. |
Srikanth Vavilapalli | 56db94f | 2015-01-22 22:30:17 -0800 | [diff] [blame] | 42 | * |
| 43 | * @return list of group bucket |
| 44 | */ |
| 45 | public List<GroupBucket> buckets() { |
| 46 | return buckets; |
| 47 | } |
| 48 | |
Srikanth Vavilapalli | 45c27c8 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 49 | @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 Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 70 | @Override |
| 71 | public String toString() { |
| 72 | return toStringHelper(this) |
Srikanth Vavilapalli | 10e75cd | 2015-04-13 16:21:24 -0700 | [diff] [blame] | 73 | .add("buckets", buckets.toString()) |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 74 | .toString(); |
| 75 | } |
Srikanth Vavilapalli | 56db94f | 2015-01-22 22:30:17 -0800 | [diff] [blame] | 76 | } |