📄 coordinate.java
字号:
package jmetest.monkeymahjongg.game;
import java.io.Serializable;
import java.util.Map;
import java.util.HashMap;
/**
* Integer coordinate specifying the "logical" position of a tile.
*
* @author Gronau
*/
public class Coordinate implements Serializable {
private final static long serialVersionUID = 1;
private static transient Map<Integer, Map<Integer, Map<Integer, Coordinate>>> map;
private final int x;
private final int y;
private final int z;
private Coordinate(int x, int y, int z) {
this.x = x;
this.y = y;
this.z = z;
}
public int getX() {
return x;
}
public int getY() {
return y;
}
public int getZ() {
return z;
}
public Coordinate add(int dx, int dy, int dz) {
return at(x+dx, y+dy, z+dz);
}
public static Coordinate at(int x, int y, int z) {
if (map == null) {
map = new HashMap<Integer, Map<Integer, Map<Integer, Coordinate>>>();
}
Map<Integer, Map<Integer, Coordinate>> mapX = map.get(x);
if (mapX == null) {
mapX = new HashMap<Integer, Map<Integer, Coordinate>>();
map.put(x, mapX);
}
Map<Integer, Coordinate> mapY = mapX.get(y);
if (mapY == null) {
mapY = new HashMap<Integer, Coordinate>();
mapX.put(y, mapY);
}
if (mapY.containsKey(z)) {
return mapY.get(z);
} else {
Coordinate c = new Coordinate(x,y,z);
mapY.put(z, c);
return c;
}
}
@Override
public String toString() {
return String.format("[%d,%d,%d]", x, y, z);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -