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