fr.arakne.utils.maps.MapCell   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 60
ccs 1
cts 1
cp 1
rs 10
wmc 1

4 Methods

Rating   Name   Duplication   Size   Complexity  
A coordinate() 0 3 1
id() 0 2 ?
walkable() 0 2 ?
map() 0 2 ?
1
/*
2
 * This file is part of ArakneUtils.
3
 *
4
 * ArakneUtils 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
 * ArakneUtils 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 ArakneUtils.  If not, see <https://www.gnu.org/licenses/>.
16
 *
17
 * Copyright (c) 2017-2020 Vincent Quatrevieux
18
 */
19
20
package fr.arakne.utils.maps;
21
22
import org.checkerframework.checker.index.qual.NonNegative;
23
import org.checkerframework.checker.nullness.qual.NonNull;
24
import org.checkerframework.dataflow.qual.Pure;
25
26
/**
27
 * Base type for a dofus map cell
28
 * Usage :
29
 * <pre>{@code
30
 * // Note: the template parameter should be the used domain interface or class
31
 * interface MyMapCell extends MapCell<MapCell> {
32
 *     public void myCustomOperation();
33
 * }
34
 * }</pre>
35
 *
36
 * @param <C> Should be the cell class it-self
37
 */
38
public interface MapCell<C extends @NonNull MapCell> {
39
    /**
40
     * Get the cell id
41
     *
42
     * @return The cell id. Starts at 0
43
     */
44
    @Pure
45
    public @NonNegative int id();
46
47
    /**
48
     * Check if the cell is walkable
49
     *
50
     * @return true if walkable
51
     */
52
    @Pure
53
    public boolean walkable();
54
55
    /**
56
     * Get the container map
57
     *
58
     * @return The parent DofusMap
59
     */
60
    @Pure
61
    public DofusMap<C> map();
62
63
    /**
64
     * Get the coordinate of the current cell
65
     * This is equivalent to {@code new CoordinateCell<>(cell)}
66
     *
67
     * Note: this method will always recreate a new {@link CoordinateCell} instance
68
     *
69
     * <pre>{@code
70
     * // Compute distance between two cells
71
     * int distance = current.coordinate().distance(target.coordinate());
72
     * }</pre>
73
     *
74
     * You can optimise {@link CoordinateCell} creation by storing them into the cell instance,
75
     * optionally wrapped into a {@link java.lang.ref.WeakReference} :
76
     *
77
     * <pre>{@code
78
     * class MyCell extends MapCell<MyCell> {
79
     *     // ...
80
     *
81
     *     private CoordinateCell<MyCell> coordinate;
82
     *
83
     *     public CoordinateCell<MyCell> coordinate() {
84
     *         if (coordinate == null) {
85
     *             coordinate = new CoordinateCell<>(this);
86
     *         }
87
     *
88
     *         return coordinate;
89
     *     }
90
     * }
91
     * }</pre>
92
     *
93
     * @return The cell coordinate
94
     */
95
    @SuppressWarnings("unchecked")
96
    public default CoordinateCell<C> coordinate() {
97 1
        return new CoordinateCell<>((C) this);
98
    }
99
}
100