Skip to content

Commit fe67544

Browse files
committed
Added ToOne.equals and .hashCode
1 parent 8d71d44 commit fe67544

File tree

1 file changed

+15
-2
lines changed
  • objectbox-java/src/main/java/io/objectbox/relation

1 file changed

+15
-2
lines changed

objectbox-java/src/main/java/io/objectbox/relation/ToOne.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,10 @@ public class ToOne<TARGET> implements Serializable {
5555
* @param relationInfo Meta info as generated in the Entity_ (entity name plus underscore) classes.
5656
*/
5757
public ToOne(Object sourceEntity, RelationInfo relationInfo) {
58-
if(sourceEntity == null ) {
58+
if (sourceEntity == null) {
5959
throw new IllegalArgumentException("No source entity given (null)");
6060
}
61-
if(relationInfo == null) {
61+
if (relationInfo == null) {
6262
throw new IllegalArgumentException("No relation info given (null)");
6363
}
6464
this.entity = sourceEntity;
@@ -274,4 +274,17 @@ public void internalPutTarget(Cursor<TARGET> targetCursor) {
274274
Object getEntity() {
275275
return entity;
276276
}
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+
}
277290
}

0 commit comments

Comments
 (0)