C - Should be the cell class it-selfpublic interface MapCell<C extends MapCell>
// Note: the template parameter should be the used domain interface or class
interface MyMapCell extends MapCell<MapCell> {
public void myCustomOperation();
}
| Modifier and Type | Method and Description |
|---|---|
default CoordinateCell<C> |
coordinate()
Get the coordinate of the current cell
This is equivalent to
new CoordinateCell<>(cell)
Note: this method will always recreate a new CoordinateCell instance
// Compute distance between two cells
int distance = current.coordinate().distance(target.coordinate());
You can optimise CoordinateCell creation by storing them into the cell instance,
optionally wrapped into a WeakReference :
{@code
class MyCell extends MapCell |
@NonNegative int |
id()
Get the cell id
|
DofusMap<C> |
map()
Get the container map
|
boolean |
walkable()
Check if the cell is walkable
|
@Pure @NonNegative int id()
@Pure boolean walkable()
default CoordinateCell<C> coordinate()
new CoordinateCell<>(cell)
Note: this method will always recreate a new CoordinateCell instance
// Compute distance between two cells
int distance = current.coordinate().distance(target.coordinate());
You can optimise CoordinateCell creation by storing them into the cell instance,
optionally wrapped into a WeakReference :
class MyCell extends MapCell<MyCell> {
// ...
private CoordinateCell<MyCell> coordinate;
public CoordinateCell<MyCell> coordinate() {
if (coordinate == null) {
coordinate = new CoordinateCell<>(this);
}
return coordinate;
}
}
Copyright © 2022. All rights reserved.