Added Time agnostic Onset and Abated classes
[policy/models.git] / models-interactions / model-impl / events / src / main / java / org / onap / policy / controlloop / CanonicalAbated.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP
4  * ================================================================================
5  * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.policy.controlloop;
22
23 import lombok.NoArgsConstructor;
24 import lombok.ToString;
25 import org.apache.commons.lang3.builder.EqualsBuilder;
26 import org.apache.commons.lang3.builder.HashCodeBuilder;
27
28 /**
29  * An ABATED event that determines equality with other ABATED
30  * with only non-time dependent values.
31  */
32
33 @NoArgsConstructor
34 @ToString(callSuper = true)
35 public class CanonicalAbated extends Abated {
36     private static final long serialVersionUID = 284865663873284818L;
37
38     public CanonicalAbated(VirtualControlLoopEvent event) {
39         super(event);
40     }
41
42     @Override
43     public boolean equals(Object other) {
44         // see hashcode method notes
45         return EqualsBuilder.reflectionEquals(
46             this, other, "requestId", "closedLoopAlarmStart", "closedLoopAlarmEnd");
47     }
48
49     @Override
50     public int hashCode() {
51         // The reflection based implementation has been chosen
52         // for maintenance reasons, even though may incur in some
53         // performance overhead.   The other possibility is to use
54         // Objects.hash(..) but will require to spell out all fields
55         // to be considered, which are many more than the exceptions,
56         // in addition this class would need to be updated as new fields
57         // are added.   Other option to consider in the future is to
58         // restructure the class hierarchy.   Note that could not use
59         // lombok annotations to exclude fields from superclasses.
60         return
61             HashCodeBuilder.reflectionHashCode(
62                 this, "requestId", "closedLoopAlarmStart", "closedLoopAlarmEnd");
63     }
64
65 }