malinink /
easy-tests
| 1 | package easytests.core.models.empty; |
||
| 2 | |||
| 3 | import easytests.core.models.ModelInterface; |
||
| 4 | import easytests.core.models.exceptions.CallMethodOnEmptyModelException; |
||
| 5 | import easytests.core.models.exceptions.CreateEmptyModelWithNullIdException; |
||
| 6 | |||
| 7 | |||
| 8 | /** |
||
| 9 | * @author malinink |
||
| 10 | */ |
||
| 11 | public abstract class AbstractModelEmpty implements ModelInterface { |
||
| 12 | private Integer id; |
||
| 13 | |||
| 14 | public AbstractModelEmpty() { |
||
| 15 | } |
||
| 16 | |||
| 17 | public AbstractModelEmpty(Integer id) { |
||
| 18 | if (id == null) { |
||
| 19 | throw new CreateEmptyModelWithNullIdException(); |
||
| 20 | } |
||
| 21 | this.id = id; |
||
| 22 | } |
||
| 23 | |||
| 24 | @Override |
||
| 25 | public Integer getId() { |
||
| 26 | if (this.id == null) { |
||
| 27 | throw new CallMethodOnEmptyModelException(); |
||
| 28 | } |
||
| 29 | return this.id; |
||
| 30 | } |
||
| 31 | |||
| 32 | @Override |
||
| 33 | public boolean equals(Object object) { |
||
| 34 | if (this == object) { |
||
| 35 | return true; |
||
| 36 | } |
||
| 37 | if (getClass() != object.getClass()) { |
||
|
0 ignored issues
–
show
Security
Bug
introduced
by
Loading history...
|
|||
| 38 | return false; |
||
| 39 | } |
||
| 40 | final AbstractModelEmpty other = (AbstractModelEmpty) object; |
||
| 41 | if (this.id == other.id) { |
||
| 42 | return true; |
||
| 43 | } |
||
| 44 | return false; |
||
| 45 | } |
||
| 46 | |||
| 47 | @Override |
||
| 48 | public int hashCode() { |
||
| 49 | return this.id == null ? -1 : this.id; |
||
| 50 | } |
||
| 51 | } |
||
| 52 |