private boolean calculate(final Set<Territory> startSet, final Territory end) { final Set<Territory> nextSet = new HashSet<Territory>(); for (final Territory t : startSet) { final Set<Territory> neighbors = m_map.getNeighbors(t, m_condition); for (final Territory neighbor : neighbors) { if (!m_previous.containsKey(neighbor)) { m_previous.put(neighbor, t); if (neighbor.equals(end)) { return true; } nextSet.add(neighbor); } } } if (nextSet.isEmpty()) { return false; } return calculate(nextSet, end); }