Model base class: implement Comparable<Model>
This commit is contained in:
parent
ecf83e8589
commit
ad693e608e
@ -3,13 +3,21 @@ package com.jdbernard.wdiwtlt.db.models;
|
||||
import javax.persistence.Entity;
|
||||
|
||||
@Entity
|
||||
public class Model {
|
||||
public class Model implements Comparable<Model> {
|
||||
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); }
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user