GeezerVison is showing github.com — Added ToOne.equals and .hashCode · restmad/objectbox-java@fe67544
File tree
Expand file treeCollapse file tree
Open diff view settings
objectbox-java/src/main/java/io/objectbox/relation
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: objectbox-java/src/main/java/io/objectbox/relation/ToOne.java +15-2Lines changed: 15 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -55,10 +55,10 @@ public class ToOne<TARGET> implements Serializable { |
55 | 55 | * @param relationInfo Meta info as generated in the Entity_ (entity name plus underscore) classes. |
56 | 56 | */ |
57 | 57 | public ToOne(Object sourceEntity, RelationInfo relationInfo) { |
58 | | - if(sourceEntity == null ) { |
| 58 | + if (sourceEntity == null) { |
59 | 59 | throw new IllegalArgumentException("No source entity given (null)"); |
60 | 60 | } |
61 | | - if(relationInfo == null) { |
| 61 | + if (relationInfo == null) { |
62 | 62 | throw new IllegalArgumentException("No relation info given (null)"); |
63 | 63 | } |
64 | 64 | this.entity = sourceEntity; |
@@ -274,4 +274,17 @@ public void internalPutTarget(Cursor<TARGET> targetCursor) { |
274 | 274 | Object getEntity() { |
275 | 275 | return entity; |
276 | 276 | } |
| 277 | + |
| 278 | + @Override |
| 279 | + public boolean equals(Object obj) { |
| 280 | + if (!(obj instanceof ToOne)) return false; |
| 281 | + ToOne other = (ToOne) obj; |
| 282 | + return relationInfo == other.relationInfo && getTargetId() == other.getTargetId(); |
| 283 | + } |
| 284 | + |
| 285 | + @Override |
| 286 | + public int hashCode() { |
| 287 | + long targetId = getTargetId(); |
| 288 | + return (int) (targetId ^ targetId >>> 32); |
| 289 | + } |
277 | 290 | } |