Remove the redundant createIfAbsent method within the AStarPathfindingAlgorithm.

This commit is contained in:
Ryley Kimmel
2015-02-25 23:51:14 -05:00
parent 750b200d90
commit f0b6208d95
@@ -71,7 +71,7 @@ final class AStarPathfindingAlgorithm extends PathfindingAlgorithm {
Position adjacent = new Position(nextX, nextY); Position adjacent = new Position(nextX, nextY);
if (traversable(adjacent)) { if (traversable(adjacent)) {
Node node = createIfAbsent(adjacent, nodes); Node node = nodes.computeIfAbsent(adjacent, Node::new);
compare(active, node, open, sorted, heuristic); compare(active, node, open, sorted, heuristic);
} }
} }
@@ -118,24 +118,6 @@ final class AStarPathfindingAlgorithm extends PathfindingAlgorithm {
} }
} }
/**
* Creates a {@link Node} and inserts it into the specified {@link Map} if one does not already exist, then returns
* that node.
*
* @param position The {@link Position}.
* @param nodes The map of positions to nodes.
* @return The node.
*/
private Node createIfAbsent(Position position, Map<Position, Node> nodes) {
Node existing = nodes.get(position);
if (existing == null) {
existing = new Node(position);
nodes.put(position, existing);
}
return existing;
}
/** /**
* Gets the cheapest open {@link Node} from the {@link Queue}. * Gets the cheapest open {@link Node} from the {@link Queue}.
* *