private Map<Position, String> buildPositionTable(final String layout) { final Map<Position, String> positionTable = new HashMap<>(); final List<String> tokens = split(layout, WHITESPACE_SPLIT_MATCHER); final int tokenSize = tokens.get(0).length(); final int xUnit = tokenSize + 1; for (String token : tokens) { assert token.length() == tokenSize : String.format("token [%s] length mismatch:\n%s", token, layout); } int y = 1; for (final String line : split(layout, NEW_LINE_SPLIT_MATCHER)) { // the way I illustrated keys above, each qwerty row is indented one space in from the last int slant = calcSlant(y); for (final String token : split(line, WHITESPACE_SPLIT_MATCHER)) { int index = line.indexOf(token) - slant; int x = index / xUnit; final int remainder = index % xUnit; assert remainder == 0 : String.format("unexpected x offset [%d] for %s in:\n%s", x, token, layout); positionTable.put(Position.of(x, y), token); } y++; } return positionTable; }
private Map<Position, String> buildPositionTable(final String layout) { final Map<Position, String> positionTable = new HashMap<>(); final List<String> tokens = split(layout, WHITESPACE_SPLIT_MATCHER); final int tokenSize = tokens.get(0).length(); final int xUnit = tokenSize + 1; for (String token : tokens) { assert token.length() == tokenSize : String.format("token [%s] length mismatch:\n%s", token, layout); } int y = 1; for (final String line : split(layout, NEW_LINE_SPLIT_MATCHER)) { // the way I illustrated keys above, each qwerty row is indented one space in from the last int slant = calcSlant(y); for (final String token : split(line, WHITESPACE_SPLIT_MATCHER)) { int index = line.indexOf(token) - slant; int x = index / xUnit; final int remainder = index % xUnit; assert remainder == 0 : String.format("unexpected x offset [%d] for %s in:\n%s", x, token, layout); positionTable.put(Position.of(x, y), token); } y++; } return positionTable; }
/** * returns the six adjacent coordinates on a standard keyboard, where each row is slanted to the * right from the last. adjacencies are clockwise, starting with key to the left, then two keys * above, then right key, then two keys below. (that is, only near-diagonal keys are adjacent, * so g's coordinate is adjacent to those of t,y,b,v, but not those of r,u,n,c.) */ @Override protected List<Position> getAdjacentCoords(final Position position) { return Arrays.asList( Position.of(position.getX() - 1, position.getY()), Position.of(position.getX(), position.getY() - 1), Position.of(position.getX() + 1, position.getY() - 1), Position.of(position.getX() + 1, position.getY()), Position.of(position.getX(), position.getY() + 1), Position.of(position.getX() - 1, position.getY() + 1)); }
/** * returns the nine clockwise adjacent coordinates on a keypad, where each row is vert aligned. */ @Override protected List<Position> getAdjacentCoords(final Position position) { return Arrays.asList( Position.of(position.getX() - 1, position.getY()), Position.of(position.getX() - 1, position.getY() - 1), Position.of(position.getX(), position.getY() - 1), Position.of(position.getX() + 1, position.getY() - 1), Position.of(position.getX() + 1, position.getY()), Position.of(position.getX() + 1, position.getY() + 1), Position.of(position.getX(), position.getY() + 1), Position.of(position.getX() - 1, position.getY() + 1)); } }
/** * returns the six adjacent coordinates on a standard keyboard, where each row is slanted to the * right from the last. adjacencies are clockwise, starting with key to the left, then two keys * above, then right key, then two keys below. (that is, only near-diagonal keys are adjacent, * so g's coordinate is adjacent to those of t,y,b,v, but not those of r,u,n,c.) */ @Override protected List<Position> getAdjacentCoords(final Position position) { return Arrays.asList( Position.of(position.getX() - 1, position.getY()), Position.of(position.getX(), position.getY() - 1), Position.of(position.getX() + 1, position.getY() - 1), Position.of(position.getX() + 1, position.getY()), Position.of(position.getX(), position.getY() + 1), Position.of(position.getX() - 1, position.getY() + 1)); }
/** * returns the nine clockwise adjacent coordinates on a keypad, where each row is vert aligned. */ @Override protected List<Position> getAdjacentCoords(final Position position) { return Arrays.asList( Position.of(position.getX() - 1, position.getY()), Position.of(position.getX() - 1, position.getY() - 1), Position.of(position.getX(), position.getY() - 1), Position.of(position.getX() + 1, position.getY() - 1), Position.of(position.getX() + 1, position.getY()), Position.of(position.getX() + 1, position.getY() + 1), Position.of(position.getX(), position.getY() + 1), Position.of(position.getX() - 1, position.getY() + 1)); } }