[New] Updated implementations of equals()/hashCode() for state variables

This commit is contained in:
Robert von Burg 2022-10-19 10:53:57 +02:00
parent 0ccb3aaa83
commit 0cd54539bf
Signed by: eitch
GPG Key ID: 75DB9C85C74331F7
9 changed files with 128 additions and 246 deletions

View File

@ -16,6 +16,7 @@
package li.strolch.model.timevalue.impl;
import java.io.Serializable;
import java.util.Objects;
import li.strolch.model.StrolchValueType;
import li.strolch.model.timevalue.ITimeValue;
@ -86,38 +87,23 @@ public class BooleanValue implements IValue<Boolean>, Serializable {
return new BooleanValue(this.value);
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((this.value == null) ? 0 : this.value.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
BooleanValue other = (BooleanValue) obj;
if (this.value == null) {
if (other.value != null) {
return false;
}
} else if (!this.value.equals(other.value)) {
return false;
}
return true;
}
@Override
public int compareTo(IValue<Boolean> o) {
return Boolean.compare(this.value, o.getValue());
}
@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
BooleanValue that = (BooleanValue) o;
return Objects.equals(value, that.value);
}
@Override
public int hashCode() {
return Objects.hash(value);
}
}

View File

@ -123,36 +123,6 @@ public class FloatListValue implements IValue<List<Double>>, Serializable {
return new FloatListValue(this.value);
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((this.value == null) ? 0 : this.value.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
FloatListValue other = (FloatListValue) obj;
if (this.value == null) {
if (other.value != null) {
return false;
}
} else if (!this.value.equals(other.value)) {
return false;
}
return true;
}
@Override
public int compareTo(IValue<List<Double>> o) {
List<Double> otherValues = o.getValue();
@ -160,4 +130,19 @@ public class FloatListValue implements IValue<List<Double>>, Serializable {
return 0;
return Integer.compare(this.value.size(), otherValues.size());
}
@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
FloatListValue that = (FloatListValue) o;
return Objects.equals(value, that.value);
}
@Override
public int hashCode() {
return Objects.hash(value);
}
}

View File

@ -16,6 +16,7 @@
package li.strolch.model.timevalue.impl;
import java.io.Serializable;
import java.util.Objects;
import li.strolch.model.StrolchValueType;
import li.strolch.model.timevalue.ITimeValue;
@ -95,38 +96,23 @@ public class FloatValue implements IValue<Double>, Serializable {
return new FloatValue(this.value);
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((this.value == null) ? 0 : this.value.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
FloatValue other = (FloatValue) obj;
if (this.value == null) {
if (other.value != null) {
return false;
}
} else if (!this.value.equals(other.value)) {
return false;
}
return true;
}
@Override
public int compareTo(IValue<Double> o) {
return Double.compare(this.value, o.getValue());
}
@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
FloatValue that = (FloatValue) o;
return Objects.equals(value, that.value);
}
@Override
public int hashCode() {
return Objects.hash(value);
}
}

View File

@ -18,10 +18,7 @@ package li.strolch.model.timevalue.impl;
import static li.strolch.model.parameter.ListParameter.VALUE_SEPARATOR2;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.*;
import li.strolch.model.StrolchValueType;
import li.strolch.model.timevalue.ITimeValue;
@ -126,36 +123,6 @@ public class IntegerListValue implements IValue<List<Integer>>, Serializable {
return new IntegerListValue(this.value);
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((this.value == null) ? 0 : this.value.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
IntegerListValue other = (IntegerListValue) obj;
if (this.value == null) {
if (other.value != null) {
return false;
}
} else if (!this.value.equals(other.value)) {
return false;
}
return true;
}
@Override
public int compareTo(IValue<List<Integer>> o) {
List<Integer> otherValues = o.getValue();
@ -163,4 +130,19 @@ public class IntegerListValue implements IValue<List<Integer>>, Serializable {
return 0;
return Integer.compare(this.value.size(), otherValues.size());
}
@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
IntegerListValue that = (IntegerListValue) o;
return Objects.equals(value, that.value);
}
@Override
public int hashCode() {
return Objects.hash(value);
}
}

View File

@ -16,6 +16,7 @@
package li.strolch.model.timevalue.impl;
import java.io.Serializable;
import java.util.Objects;
import li.strolch.model.StrolchValueType;
import li.strolch.model.timevalue.ITimeValue;
@ -86,38 +87,23 @@ public class IntegerValue implements IValue<Integer>, Serializable {
return new IntegerValue(this.value);
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((this.value == null) ? 0 : this.value.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
IntegerValue other = (IntegerValue) obj;
if (this.value == null) {
if (other.value != null) {
return false;
}
} else if (!this.value.equals(other.value)) {
return false;
}
return true;
}
@Override
public int compareTo(IValue<Integer> o) {
return Integer.compare(this.value, o.getValue());
}
@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
IntegerValue that = (IntegerValue) o;
return Objects.equals(value, that.value);
}
@Override
public int hashCode() {
return Objects.hash(value);
}
}

View File

@ -16,6 +16,7 @@
package li.strolch.model.timevalue.impl;
import java.io.Serializable;
import java.util.Objects;
import li.strolch.model.StrolchValueType;
import li.strolch.model.timevalue.ITimeValue;
@ -86,38 +87,23 @@ public class LongValue implements IValue<Long>, Serializable {
return new LongValue(this.value);
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((this.value == null) ? 0 : this.value.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
LongValue other = (LongValue) obj;
if (this.value == null) {
if (other.value != null) {
return false;
}
} else if (!this.value.equals(other.value)) {
return false;
}
return true;
}
@Override
public int compareTo(IValue<Long> o) {
return Long.compare(this.value, o.getValue());
}
@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
LongValue longValue = (LongValue) o;
return Objects.equals(value, longValue.value);
}
@Override
public int hashCode() {
return Objects.hash(value);
}
}

View File

@ -16,10 +16,7 @@
package li.strolch.model.timevalue.impl;
import java.io.Serializable;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import java.util.*;
import li.strolch.exception.StrolchException;
import li.strolch.model.StrolchValueType;
@ -149,4 +146,19 @@ public class StringSetValue implements IValue<Set<AString>>, Serializable {
return 0;
return Integer.compare(this.aStrings.size(), otherValues.size());
}
@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
StringSetValue that = (StringSetValue) o;
return Objects.equals(aStrings, that.aStrings);
}
@Override
public int hashCode() {
return Objects.hash(aStrings);
}
}

View File

@ -16,6 +16,7 @@
package li.strolch.model.timevalue.impl;
import java.io.Serializable;
import java.util.Objects;
import li.strolch.model.timevalue.ITimeValue;
import li.strolch.model.timevalue.IValue;
@ -89,37 +90,17 @@ public class TimeValue<T extends IValue> implements ITimeValue<T>, Serializable
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + Long.hashCode(this.time);
result = prime * result + ((this.value == null) ? 0 : this.value.hashCode());
return result;
public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
TimeValue<?> timeValue = (TimeValue<?>) o;
return time == timeValue.time && Objects.equals(value, timeValue.value);
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
@SuppressWarnings("unchecked")
TimeValue<T> other = (TimeValue<T>) obj;
if (this.time != other.time) {
return false;
}
if (this.value == null) {
if (other.value != null) {
return false;
}
} else if (!this.value.equals(other.value)) {
return false;
}
return true;
public int hashCode() {
return Objects.hash(time, value);
}
}

View File

@ -18,6 +18,7 @@ package li.strolch.model.timevalue.impl;
import static li.strolch.utils.helper.StringHelper.trimOrEmpty;
import java.io.Serializable;
import java.util.Objects;
import li.strolch.model.timevalue.IValue;
import li.strolch.model.timevalue.IValueChange;
@ -86,41 +87,18 @@ public class ValueChange<T extends IValue> implements IValueChange<T>, Serializa
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
public boolean equals(Object o) {
if (this == o)
return true;
}
if (obj == null) {
if (o == null || getClass() != o.getClass())
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
ValueChange<?> other = (ValueChange<?>) obj;
if (this.time == null) {
if (other.time != null) {
return false;
}
} else if (!this.time.equals(other.time)) {
return false;
}
if (this.value == null) {
if (other.value != null) {
return false;
}
} else if (!this.value.equals(other.value)) {
return false;
}
return true;
ValueChange<?> that = (ValueChange<?>) o;
return Objects.equals(time, that.time) && Objects.equals(value, that.value);
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((this.time == null) ? 0 : this.time.hashCode());
result = prime * result + ((this.value == null) ? 0 : this.value.hashCode());
return result;
return Objects.hash(time, value);
}
@SuppressWarnings("nls")