Srikanth Vavilapalli | 56db94f | 2015-01-22 22:30:17 -0800 | [diff] [blame] | 1 | /* |
| 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 | */ |
| 16 | package org.onosproject.net.group; |
| 17 | |
| 18 | import static com.google.common.base.Preconditions.checkNotNull; |
| 19 | |
| 20 | import java.util.List; |
| 21 | |
Srikanth Vavilapalli | 56db94f | 2015-01-22 22:30:17 -0800 | [diff] [blame] | 22 | import com.google.common.collect.ImmutableList; |
| 23 | |
Srikanth Vavilapalli | 0599d51 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 24 | /** |
| 25 | * Immutable collection of group bucket. |
| 26 | */ |
Srikanth Vavilapalli | 56db94f | 2015-01-22 22:30:17 -0800 | [diff] [blame] | 27 | public 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 Vavilapalli | 0599d51 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 40 | * Returns immutable list of group buckets. |
Srikanth Vavilapalli | 56db94f | 2015-01-22 22:30:17 -0800 | [diff] [blame] | 41 | * |
| 42 | * @return list of group bucket |
| 43 | */ |
| 44 | public List<GroupBucket> buckets() { |
| 45 | return buckets; |
| 46 | } |
| 47 | |
Srikanth Vavilapalli | 45c27c8 | 2015-01-30 12:57:56 -0800 | [diff] [blame^] | 48 | @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 Vavilapalli | 56db94f | 2015-01-22 22:30:17 -0800 | [diff] [blame] | 69 | } |