fr.quatrevieux.araknemu.data.value.Position   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 32
dl 0
loc 53
ccs 15
cts 15
cp 1
rs 10
c 0
b 0
f 0
wmc 9

9 Methods

Rating   Name   Duplication   Size   Complexity  
A newCell(int) 0 2 1
A equals(Position) 0 2 1
A map() 0 3 1
A cell() 0 3 1
A toString() 0 3 1
A isNull() 0 3 1
A hashCode() 0 5 1
A Position(int,int) 0 3 1
A equals(Object) 0 5 1
1
/*
2
 * This file is part of Araknemu.
3
 *
4
 * Araknemu is free software: you can redistribute it and/or modify
5
 * it under the terms of the GNU Lesser General Public License as published by
6
 * the Free Software Foundation, either version 3 of the License, or
7
 * (at your option) any later version.
8
 *
9
 * Araknemu is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 * GNU Lesser General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU Lesser General Public License
15
 * along with Araknemu.  If not, see <https://www.gnu.org/licenses/>.
16
 *
17
 * Copyright (c) 2017-2019 Vincent Quatrevieux
18
 */
19
20
package fr.quatrevieux.araknemu.data.value;
21
22
import org.checkerframework.checker.index.qual.NonNegative;
23
import org.checkerframework.checker.nullness.qual.Nullable;
24
import org.checkerframework.checker.signedness.qual.Signed;
25
import org.checkerframework.dataflow.qual.Pure;
26
27
/**
28
 * Position object into the world
29
 */
30
public final class Position {
31
    private final @NonNegative int map;
32
    private final @NonNegative int cell;
33
34 1
    public Position(@NonNegative int map, @NonNegative int cell) {
35 1
        this.map = map;
36 1
        this.cell = cell;
37 1
    }
38
39
    @Pure
40
    public @NonNegative int map() {
41 1
        return map;
42
    }
43
44
    @Pure
45
    public @NonNegative int cell() {
46 1
        return cell;
47
    }
48
49
    @Pure
50
    public boolean isNull() {
51 1
        return map == 0 && cell == 0;
52
    }
53
54
    /**
55
     * Change the cell position
56
     */
57
    public Position newCell(@NonNegative int cell) {
58 1
        return new Position(map, cell);
59
    }
60
61
    @Override
62
    public boolean equals(@Nullable Object o) {
63 1
        return
64
            this == o
65 1
            || (o instanceof Position && equals((Position) o))
66
        ;
67
    }
68
69
    public boolean equals(@Nullable Position other) {
70 1
        return other != null && other.cell == cell && other.map == map;
71
    }
72
73
    @Override
74
    public int hashCode() {
75 1
        @Signed int result = map;
76 1
        result = 31 * result + cell;
77 1
        return result;
78
    }
79
80
    @Override
81
    public String toString() {
82 1
        return "(" + map + ", " + cell + ")";
83
    }
84
}
85