easytests.core.models.empty.AbstractModelEmpty   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
c 1
b 0
f 0
loc 39
rs 10
wmc 11

7 Methods

Rating   Name   Duplication   Size   Complexity  
hashCode 0 3 ?
equals 0 13 ?
A hashCode() 0 3 2
A getId() 0 6 2
A equals(Object) 0 13 4
A AbstractModelEmpty(Integer) 0 5 2
A AbstractModelEmpty() 0 ? 1
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
A "NullPointerException" could be thrown; "object" is nullable here.
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