2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.policy.controlloop;
23 import lombok.NoArgsConstructor;
24 import lombok.ToString;
25 import org.apache.commons.lang3.builder.EqualsBuilder;
26 import org.apache.commons.lang3.builder.HashCodeBuilder;
29 * An ONSET event that determines equality with other ONSET events
30 * with only non-time dependent values.
34 @ToString(callSuper = true)
35 public class CanonicalOnset extends Onset {
36 private static final long serialVersionUID = 284865663873284818L;
38 public CanonicalOnset(VirtualControlLoopEvent event) {
43 public boolean equals(Object other) {
44 // see hashcode method notes
45 return EqualsBuilder.reflectionEquals(
46 this, other, "requestId", "closedLoopAlarmStart", "closedLoopAlarmEnd");
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.
61 HashCodeBuilder.reflectionHashCode(
62 this, "requestId", "closedLoopAlarmStart", "closedLoopAlarmEnd");