com.darwinsys.todo.model.Context Maven / Gradle / Ivy
package com.darwinsys.todo.model;
import java.io.Serializable;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
/** The Context in which a Todo item is to be done */
@Entity
public class Context implements Comparable, Serializable {
private static final long serialVersionUID = 1208574258185845564L;
long id;
String name;
public Context() {
// empty
}
public Context(String name) {
this.name = name;
}
@Id @GeneratedValue(strategy=GenerationType.AUTO)
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Override
public String toString() {
return name;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + (int) (id ^ (id >>> 32));
result = prime * result + ((name == null) ? 0 : name.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Context other = (Context) obj;
if (id != other.id)
return false;
if (name == null) {
if (other.name != null)
return false;
} else if (!name.equals(other.name))
return false;
return true;
}
@Override
public int compareTo(Context o) {
if (this.id < o.id) {
return -1;
}
if (this.id > o.id) {
return +1;
}
return 0;
}
}