Use HashMap.computIfAbsent() in getNode()