Skip to content

Commit 43440d8

Browse files
committed
Make equals hashcode niceer
1 parent ebf6be8 commit 43440d8

File tree

1 file changed

+8
-13
lines changed
  • spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/special/types

1 file changed

+8
-13
lines changed

spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/special/types/LazyDaoObject.java

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@
1616
package software.xdev.spring.data.eclipse.store.integration.isolated.tests.special.types;
1717

1818
import java.util.Objects;
19+
import java.util.Optional;
1920

2021
import org.eclipse.serializer.reference.Lazy;
22+
import org.eclipse.serializer.reference.Referencing;
2123

2224

2325
public class LazyDaoObject extends ComplexObject<Lazy<String>>
@@ -30,16 +32,11 @@ public LazyDaoObject(final Integer id, final Lazy<String> value)
3032
@Override
3133
public int hashCode()
3234
{
33-
int result = 17;
34-
if(this.getId() != null)
35-
{
36-
result = 31 * result + this.getId().hashCode();
37-
}
38-
if(this.getValue() != null)
39-
{
40-
result = 31 * result + this.getValue().hashCode();
41-
}
42-
return result;
35+
return Objects.hash(
36+
this.getId(),
37+
Optional.ofNullable(this.getValue())
38+
.map(Referencing::get)
39+
.orElse(null));
4340
}
4441

4542
@Override
@@ -56,8 +53,6 @@ public boolean equals(final Object o)
5653
final ComplexObject<Lazy<String>> that = (ComplexObject<Lazy<String>>)o;
5754
return Objects.equals(this.getId(), that.getId())
5855
&& (this.getValue() == null && that.getValue() == null)
59-
|| Objects.equals(
60-
this.getValue().get(),
61-
that.getValue().get());
56+
|| Objects.equals(this.getValue().get(), that.getValue().get());
6257
}
6358
}

0 commit comments

Comments
 (0)