[Major] Refactored equals/hashcode methods

This commit is contained in:
Robert von Burg 2023-04-06 15:32:54 +02:00
parent 6d7fc09621
commit 0bf8582531
Signed by: eitch
GPG Key ID: 75DB9C85C74331F7
26 changed files with 355 additions and 24 deletions

View File

@ -133,25 +133,10 @@ public abstract class AbstractStrolchElement implements StrolchElement {
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((this.id == null) ? 0 : this.id.hashCode());
return result;
}
public abstract boolean equals(Object obj);
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null || getClass() != obj.getClass())
return false;
AbstractStrolchElement other = (AbstractStrolchElement) obj;
if (this.id == null) {
return other.id == null;
} else
return this.id.equals(other.id);
}
public abstract int hashCode();
@Override
public abstract String toString();

View File

@ -290,9 +290,10 @@ public abstract class GroupedParameterizedElement extends AbstractStrolchElement
}
@Override
public boolean equals(Object obj) {
return super.equals(obj);
}
public abstract boolean equals(Object obj);
@Override
public abstract int hashCode();
@Override
public void setReadOnly() {

View File

@ -18,6 +18,7 @@ package li.strolch.model;
import java.text.MessageFormat;
import java.time.*;
import java.util.Date;
import java.util.Objects;
import li.strolch.exception.StrolchPolicyException;
import li.strolch.model.Locator.LocatorBuilder;
@ -302,6 +303,11 @@ public class Order extends AbstractStrolchRootElement implements StrolchRootElem
return this.type.equals(o.type) && this.id.equals(o.id);
}
@Override
public int hashCode() {
return Objects.hash(type, id);
}
@Override
public String toString() {

View File

@ -15,6 +15,8 @@
*/
package li.strolch.model;
import java.util.Objects;
import li.strolch.model.Locator.LocatorBuilder;
import li.strolch.model.visitor.StrolchElementVisitor;
@ -44,6 +46,21 @@ public class ParameterBag extends ParameterizedElement {
super(id, name, type);
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null || getClass() != obj.getClass())
return false;
ParameterBag r = (ParameterBag) obj;
return this.type.equals(r.type) && this.id.equals(r.id);
}
@Override
public int hashCode() {
return Objects.hash(type, id);
}
@Override
public ParameterBag getClone() {
ParameterBag clone = new ParameterBag();

View File

@ -1204,9 +1204,10 @@ public abstract class ParameterizedElement extends AbstractStrolchElement {
}
@Override
public boolean equals(Object obj) {
return super.equals(obj);
}
public abstract boolean equals(Object obj);
@Override
public abstract int hashCode();
@Override
public void setReadOnly() {

View File

@ -390,6 +390,11 @@ public class Resource extends AbstractStrolchRootElement implements StrolchRootE
return this.type.equals(r.type) && this.id.equals(r.id);
}
@Override
public int hashCode() {
return Objects.hash(type, id);
}
@Override
public String toString() {

View File

@ -366,6 +366,21 @@ public class Action extends GroupedParameterizedElement implements IActivityElem
locatorBuilder.append(this.id);
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null || getClass() != obj.getClass())
return false;
Action a = (Action) obj;
return this.parent == a.parent && this.type.equals(a.type) && this.id.equals(a.id);
}
@Override
public int hashCode() {
return Objects.hash(parent, type, id);
}
@Override
public String toString() {
return "Action [id=" + this.id + ", name=" + this.name + ", type=" + this.type + ", resourceId="

View File

@ -776,6 +776,11 @@ public class Activity extends AbstractStrolchRootElement
return this.parent == a.parent && this.type.equals(a.type) && this.id.equals(a.id);
}
@Override
public int hashCode() {
return Objects.hash(type, id);
}
@Override
public String toString() {
final StringBuilder builder = new StringBuilder();

View File

@ -15,7 +15,10 @@
*/
package li.strolch.model.parameter;
import java.util.Objects;
import li.strolch.model.StrolchValueType;
import li.strolch.model.timedstate.FloatTimedState;
import li.strolch.model.visitor.StrolchElementVisitor;
import li.strolch.utils.dbc.DBC;
import li.strolch.utils.helper.StringHelper;
@ -108,6 +111,21 @@ public class BooleanParameter extends AbstractParameter<Boolean> {
return this.value.equals(otherValue);
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null || getClass() != obj.getClass())
return false;
BooleanParameter o = (BooleanParameter) obj;
return this.parent == o.parent && this.id.equals(o.id);
}
@Override
public int hashCode() {
return Objects.hash(parent, id);
}
public void flip() {
assertNotReadonly();
this.value = !this.value;

View File

@ -21,6 +21,7 @@ import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.Date;
import java.util.Objects;
import li.strolch.model.StrolchValueType;
import li.strolch.model.visitor.StrolchElementVisitor;
@ -159,6 +160,21 @@ public class DateParameter extends AbstractParameter<Date> {
return this.value.equals(otherValue);
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null || getClass() != obj.getClass())
return false;
DateParameter o = (DateParameter) obj;
return this.parent == o.parent && this.id.equals(o.id);
}
@Override
public int hashCode() {
return Objects.hash(parent, id);
}
public void setValueFromLocalDateTime(LocalDateTime localDateTime) {
this.value = localDateTime.atZone(ZoneId.systemDefault());
}

View File

@ -17,6 +17,7 @@ package li.strolch.model.parameter;
import java.time.Duration;
import java.time.Period;
import java.util.Objects;
import li.strolch.model.StrolchValueType;
import li.strolch.model.visitor.StrolchElementVisitor;
@ -133,6 +134,21 @@ public class DurationParameter extends AbstractParameter<PeriodDuration> {
return this.value.equals(otherValue);
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null || getClass() != obj.getClass())
return false;
DurationParameter o = (DurationParameter) obj;
return this.parent == o.parent && this.id.equals(o.id);
}
@Override
public int hashCode() {
return Objects.hash(parent, id);
}
public long toMillis() {
return this.value.toMillis();
}

View File

@ -18,6 +18,7 @@ package li.strolch.model.parameter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import li.strolch.model.StrolchValueType;
import li.strolch.model.visitor.StrolchElementVisitor;
@ -71,6 +72,21 @@ public class FloatListParameter extends AbstractListParameter<Double> {
return StrolchValueType.FLOAT_LIST;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null || getClass() != obj.getClass())
return false;
FloatListParameter o = (FloatListParameter) obj;
return this.parent == o.parent && this.id.equals(o.id);
}
@Override
public int hashCode() {
return Objects.hash(parent, id);
}
@Override
public FloatListParameter getClone() {
FloatListParameter clone = new FloatListParameter();

View File

@ -15,6 +15,8 @@
*/
package li.strolch.model.parameter;
import java.util.Objects;
import li.strolch.model.StrolchValueType;
import li.strolch.model.visitor.StrolchElementVisitor;
import li.strolch.utils.dbc.DBC;
@ -98,6 +100,21 @@ public class FloatParameter extends AbstractParameter<Double> {
return this.value == 0.0D;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null || getClass() != obj.getClass())
return false;
FloatParameter o = (FloatParameter) obj;
return this.parent == o.parent && this.id.equals(o.id);
}
@Override
public int hashCode() {
return Objects.hash(parent, id);
}
@Override
public boolean isEqualTo(Parameter<Double> otherValue) {
FloatParameter other = (FloatParameter) otherValue;

View File

@ -18,6 +18,7 @@ package li.strolch.model.parameter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import li.strolch.model.StrolchValueType;
import li.strolch.model.visitor.StrolchElementVisitor;
@ -71,6 +72,21 @@ public class IntegerListParameter extends AbstractListParameter<Integer> {
return StrolchValueType.INTEGER_LIST;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null || getClass() != obj.getClass())
return false;
IntegerListParameter o = (IntegerListParameter) obj;
return this.parent == o.parent && this.id.equals(o.id);
}
@Override
public int hashCode() {
return Objects.hash(parent, id);
}
@Override
public IntegerListParameter getClone() {
IntegerListParameter clone = new IntegerListParameter();

View File

@ -15,6 +15,8 @@
*/
package li.strolch.model.parameter;
import java.util.Objects;
import li.strolch.model.StrolchValueType;
import li.strolch.model.visitor.StrolchElementVisitor;
import li.strolch.utils.dbc.DBC;
@ -114,7 +116,17 @@ public class IntegerParameter extends AbstractParameter<Integer> {
@Override
public boolean equals(Object obj) {
return super.equals(obj);
if (this == obj)
return true;
if (obj == null || getClass() != obj.getClass())
return false;
IntegerParameter o = (IntegerParameter) obj;
return this.parent == o.parent && this.id.equals(o.id);
}
@Override
public int hashCode() {
return Objects.hash(parent, id);
}
public void add(int value) {

View File

@ -18,6 +18,7 @@ package li.strolch.model.parameter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import li.strolch.model.StrolchValueType;
import li.strolch.model.visitor.StrolchElementVisitor;
@ -71,6 +72,21 @@ public class LongListParameter extends AbstractListParameter<Long> {
return StrolchValueType.LONG_LIST;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null || getClass() != obj.getClass())
return false;
LongListParameter o = (LongListParameter) obj;
return this.parent == o.parent && this.id.equals(o.id);
}
@Override
public int hashCode() {
return Objects.hash(parent, id);
}
@Override
public LongListParameter getClone() {
LongListParameter clone = new LongListParameter();

View File

@ -15,6 +15,8 @@
*/
package li.strolch.model.parameter;
import java.util.Objects;
import li.strolch.model.StrolchValueType;
import li.strolch.model.visitor.StrolchElementVisitor;
import li.strolch.utils.dbc.DBC;
@ -102,6 +104,21 @@ public class LongParameter extends AbstractParameter<Long> {
return this.value.equals(otherValue);
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null || getClass() != obj.getClass())
return false;
LongParameter o = (LongParameter) obj;
return this.parent == o.parent && this.id.equals(o.id);
}
@Override
public int hashCode() {
return Objects.hash(parent, id);
}
public void add(long value) {
assertNotReadonly();
this.value += value;

View File

@ -18,6 +18,7 @@ package li.strolch.model.parameter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import li.strolch.model.StrolchValueType;
import li.strolch.model.visitor.StrolchElementVisitor;
@ -71,6 +72,21 @@ public class StringListParameter extends AbstractListParameter<String> {
return StrolchValueType.STRING_LIST;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null || getClass() != obj.getClass())
return false;
StringListParameter o = (StringListParameter) obj;
return this.parent == o.parent && this.id.equals(o.id);
}
@Override
public int hashCode() {
return Objects.hash(parent, id);
}
@Override
public StringListParameter getClone() {
StringListParameter clone = new StringListParameter();

View File

@ -16,6 +16,7 @@
package li.strolch.model.parameter;
import java.text.MessageFormat;
import java.util.Objects;
import li.strolch.exception.StrolchException;
import li.strolch.model.StrolchValueType;
@ -141,6 +142,21 @@ public class StringParameter extends AbstractParameter<String> {
return this.value.equals(otherValue);
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null || getClass() != obj.getClass())
return false;
StringParameter o = (StringParameter) obj;
return this.parent == o.parent && this.id.equals(o.id);
}
@Override
public int hashCode() {
return Objects.hash(parent, id);
}
@Override
public void setValueFromString(String valueAsString) {
setValue(valueAsString);

View File

@ -15,6 +15,9 @@
*/
package li.strolch.model.timedstate;
import java.util.Objects;
import li.strolch.model.Order;
import li.strolch.model.StrolchValueType;
import li.strolch.model.timevalue.impl.BooleanValue;
import li.strolch.model.visitor.StrolchElementVisitor;
@ -32,6 +35,21 @@ public class BooleanTimedState extends AbstractStrolchTimedState<BooleanValue> {
super(id, name);
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null || getClass() != obj.getClass())
return false;
BooleanTimedState o = (BooleanTimedState) obj;
return this.parent == o.parent && this.id.equals(o.id);
}
@Override
public int hashCode() {
return Objects.hash(parent, id);
}
@Override
public void setStateFromStringAt(Long time, String value) {
assertNotReadonly();

View File

@ -15,6 +15,8 @@
*/
package li.strolch.model.timedstate;
import java.util.Objects;
import li.strolch.model.StrolchValueType;
import li.strolch.model.timevalue.impl.FloatListValue;
import li.strolch.model.visitor.StrolchElementVisitor;
@ -32,6 +34,21 @@ public class FloatListTimedState extends AbstractStrolchTimedState<FloatListValu
super(id, name);
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null || getClass() != obj.getClass())
return false;
FloatListTimedState o = (FloatListTimedState) obj;
return this.parent == o.parent && this.id.equals(o.id);
}
@Override
public int hashCode() {
return Objects.hash(parent, id);
}
@Override
public void setStateFromStringAt(Long time, String value) {
assertNotReadonly();

View File

@ -15,6 +15,8 @@
*/
package li.strolch.model.timedstate;
import java.util.Objects;
import li.strolch.model.StrolchValueType;
import li.strolch.model.timevalue.impl.FloatValue;
import li.strolch.model.visitor.StrolchElementVisitor;
@ -32,6 +34,21 @@ public class FloatTimedState extends AbstractStrolchTimedState<FloatValue> {
super(id, name);
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null || getClass() != obj.getClass())
return false;
FloatTimedState o = (FloatTimedState) obj;
return this.parent == o.parent && this.id.equals(o.id);
}
@Override
public int hashCode() {
return Objects.hash(parent, id);
}
@Override
public void setStateFromStringAt(Long time, String value) {
assertNotReadonly();

View File

@ -15,6 +15,8 @@
*/
package li.strolch.model.timedstate;
import java.util.Objects;
import li.strolch.model.StrolchValueType;
import li.strolch.model.timevalue.impl.IntegerListValue;
import li.strolch.model.visitor.StrolchElementVisitor;
@ -32,6 +34,21 @@ public class IntegerListTimedState extends AbstractStrolchTimedState<IntegerList
super(id, name);
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null || getClass() != obj.getClass())
return false;
IntegerListTimedState o = (IntegerListTimedState) obj;
return this.parent == o.parent && this.id.equals(o.id);
}
@Override
public int hashCode() {
return Objects.hash(parent, id);
}
@Override
public void setStateFromStringAt(Long time, String value) {
assertNotReadonly();

View File

@ -15,6 +15,8 @@
*/
package li.strolch.model.timedstate;
import java.util.Objects;
import li.strolch.model.StrolchValueType;
import li.strolch.model.timevalue.impl.IntegerValue;
import li.strolch.model.visitor.StrolchElementVisitor;
@ -32,6 +34,21 @@ public class IntegerTimedState extends AbstractStrolchTimedState<IntegerValue> {
super(id, name);
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null || getClass() != obj.getClass())
return false;
IntegerTimedState o = (IntegerTimedState) obj;
return this.parent == o.parent && this.id.equals(o.id);
}
@Override
public int hashCode() {
return Objects.hash(parent, id);
}
@Override
public void setStateFromStringAt(Long time, String value) {
assertNotReadonly();

View File

@ -15,6 +15,8 @@
*/
package li.strolch.model.timedstate;
import java.util.Objects;
import li.strolch.model.StrolchValueType;
import li.strolch.model.timevalue.impl.LongValue;
import li.strolch.model.visitor.StrolchElementVisitor;
@ -32,6 +34,21 @@ public class LongTimedState extends AbstractStrolchTimedState<LongValue> {
super(id, name);
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null || getClass() != obj.getClass())
return false;
LongTimedState o = (LongTimedState) obj;
return this.parent == o.parent && this.id.equals(o.id);
}
@Override
public int hashCode() {
return Objects.hash(parent, id);
}
@Override
public void setStateFromStringAt(Long time, String value) {
assertNotReadonly();

View File

@ -15,6 +15,8 @@
*/
package li.strolch.model.timedstate;
import java.util.Objects;
import li.strolch.model.StrolchValueType;
import li.strolch.model.timevalue.impl.StringSetValue;
import li.strolch.model.visitor.StrolchElementVisitor;
@ -32,6 +34,21 @@ public class StringSetTimedState extends AbstractStrolchTimedState<StringSetValu
super(id, name);
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null || getClass() != obj.getClass())
return false;
StringSetTimedState o = (StringSetTimedState) obj;
return this.parent == o.parent && this.id.equals(o.id);
}
@Override
public int hashCode() {
return Objects.hash(parent, id);
}
@Override
public void setStateFromStringAt(Long time, String value) {
assertNotReadonly();