blob: fdc6deac14f0c53688bd3de5f1d4de3d0fe6ff46 [file] [log] [blame]
Srikanth Vavilapalli37a461b2015-04-07 15:12:32 -07001/*
Brian O'Connor0947d7e2017-08-03 21:12:30 -07002 * Copyright 2015-present Open Networking Foundation
Srikanth Vavilapalli37a461b2015-04-07 15:12:32 -07003 *
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.segmentrouting.grouphandler;
17
18import java.util.List;
19
20/**
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 */
25public class PolicyGroupIdentifier {
26 private String id;
27 private List<PolicyGroupParams> inputParams;
28 private List<GroupBucketIdentifier> bucketIds;
29
30 /**
Charles Chanb7f75ac2016-01-11 18:28:54 -080031 * Constructs policy group identifier.
Srikanth Vavilapalli37a461b2015-04-07 15:12:32 -070032 *
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}