/** * builds an adjacency graph as a dictionary: {character: [adjacent_characters]}. * adjacent characters occur in a clockwise order. * for example: * on qwerty layout, 'g' maps to ['fF', 'tT', 'yY', 'hH', 'bB', 'vV'] * on keypad layout, '7' maps to [None, None, None, '=', '8', '5', '4', None] * */ public Map<Character, List<String>> build() { final Map<Position, String> positionTable = buildPositionTable(layout); final Map<Character, List<String>> adjacencyGraph = new HashMap<>(); for (Map.Entry<Position, String> entry : positionTable.entrySet()) { for (final char key : entry.getValue().toCharArray()) { final List<String> adjacencies = new ArrayList<>(); final Position position = entry.getKey(); for (final Position coord : getAdjacentCoords(position)) { adjacencies.add(positionTable.get(coord)); } adjacencyGraph.put(key, adjacencies); } } return adjacencyGraph; }
/** * builds an adjacency graph as a dictionary: {character: [adjacent_characters]}. * adjacent characters occur in a clockwise order. * for example: * on qwerty layout, 'g' maps to ['fF', 'tT', 'yY', 'hH', 'bB', 'vV'] * on keypad layout, '7' maps to [None, None, None, '=', '8', '5', '4', None] * */ public Map<Character, List<String>> build() { final Map<Position, String> positionTable = buildPositionTable(layout); final Map<Character, List<String>> adjacencyGraph = new HashMap<>(); for (Map.Entry<Position, String> entry : positionTable.entrySet()) { for (final char key : entry.getValue().toCharArray()) { final List<String> adjacencies = new ArrayList<>(); final Position position = entry.getKey(); for (final Position coord : getAdjacentCoords(position)) { adjacencies.add(positionTable.get(coord)); } adjacencyGraph.put(key, adjacencies); } } return adjacencyGraph; }