diff --git a/core/src/main/java/com/jdbernard/wdiwtlt/db/models/Model.java b/core/src/main/java/com/jdbernard/wdiwtlt/db/models/Model.java index 018f4ae..f8b873a 100644 --- a/core/src/main/java/com/jdbernard/wdiwtlt/db/models/Model.java +++ b/core/src/main/java/com/jdbernard/wdiwtlt/db/models/Model.java @@ -3,13 +3,21 @@ package com.jdbernard.wdiwtlt.db.models; import javax.persistence.Entity; @Entity -public class Model { +public class Model implements Comparable { public Integer id; public boolean equals(Object thatObj) { if (thatObj == null) return false; - if (!(thatObj instanceof Model)) return false; + if (this.getClass() != thatObj.getClass()) return false; Model that = (Model) thatObj; - return this.id == that.id; } + return this.id.equals(that.id); } + + public int compareTo(Model that) { + if (this.id == null) return -1; + if (this.getClass() != that.getClass()) { + return this.getClass().getSimpleName().compareTo( + that.getClass().getSimpleName()); } + + return this.id.compareTo(that.id); } }