Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -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.grouphandler; |
| 17 | |
| 18 | import java.util.List; |
| 19 | |
| 20 | import org.onosproject.net.group.GroupKey; |
| 21 | |
| 22 | /** |
| 23 | * Representation of policy based group identifiers. |
| 24 | * Opaque to group handler applications and only the outermost |
| 25 | * policy group identifier in a chain is visible to the applications. |
| 26 | */ |
| 27 | public class PolicyGroupIdentifier implements GroupKey { |
| 28 | private String id; |
| 29 | private List<PolicyGroupParams> inputParams; |
| 30 | private List<GroupBucketIdentifier> bucketIds; |
| 31 | |
| 32 | /** |
| 33 | * Constructor. |
| 34 | * |
| 35 | * @param id unique identifier associated with the policy group |
| 36 | * @param input policy group params associated with this group |
| 37 | * @param bucketIds buckets associated with this group |
| 38 | */ |
| 39 | protected PolicyGroupIdentifier(String id, |
| 40 | List<PolicyGroupParams> input, |
| 41 | List<GroupBucketIdentifier> bucketIds) { |
| 42 | this.id = id; |
| 43 | this.inputParams = input; |
| 44 | this.bucketIds = bucketIds; |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | * Returns the bucket identifier list associated with the policy |
| 49 | * group identifier. |
| 50 | * |
| 51 | * @return list of bucket identifier |
| 52 | */ |
| 53 | protected List<GroupBucketIdentifier> bucketIds() { |
| 54 | return this.bucketIds; |
| 55 | } |
| 56 | |
| 57 | @Override |
| 58 | public int hashCode() { |
| 59 | int result = 17; |
| 60 | int combinedHash = 0; |
| 61 | for (PolicyGroupParams input:inputParams) { |
| 62 | combinedHash = combinedHash + input.hashCode(); |
| 63 | } |
| 64 | for (GroupBucketIdentifier bucketId:bucketIds) { |
| 65 | combinedHash = combinedHash + bucketId.hashCode(); |
| 66 | } |
| 67 | result = 31 * result + combinedHash; |
| 68 | |
| 69 | return result; |
| 70 | } |
| 71 | |
| 72 | @Override |
| 73 | public boolean equals(Object obj) { |
| 74 | if (this == obj) { |
| 75 | return true; |
| 76 | } |
| 77 | |
| 78 | if (obj instanceof PolicyGroupIdentifier) { |
| 79 | PolicyGroupIdentifier that = (PolicyGroupIdentifier) obj; |
| 80 | boolean result = this.id.equals(that.id); |
| 81 | result = result && |
| 82 | this.inputParams.containsAll(that.inputParams) && |
| 83 | that.inputParams.containsAll(this.inputParams); |
| 84 | result = result && |
| 85 | this.bucketIds.containsAll(that.bucketIds) && |
| 86 | that.bucketIds.containsAll(this.bucketIds); |
| 87 | return result; |
| 88 | } |
| 89 | |
| 90 | return false; |
| 91 | } |
| 92 | } |