### Question:
BorderingDistanceMetric implements SpatialDistanceMetric { @Override public double distance(Geometry g1, Geometry g2) { if (adjacencyList.isEmpty()) { throw new UnsupportedOperationException(); } int srcId = getContainingGeometry(g1); int destId = getContainingGeometry(g2); if (srcId < 0) { throw new IllegalArgumentException("No containing geometry for source geometry"); } if (destId < 0) { throw new IllegalArgumentException("No containing geometry for destination geometry"); } if (srcId == destId) { return 0; } TIntSet seen = new TIntHashSet(); TIntLinkedList queue = new TIntLinkedList(); for (int id: adjacencyList.get(srcId).toArray()) { if (id == destId) { return 1; } queue.add(id); seen.add(id); } for (int level = 2; level <= maxSteps; level++) { int nodes = queue.size(); for (int i = 0; i < nodes; i++) { int id = queue.removeAt(0); if (!adjacencyList.containsKey(id)) { continue; } for (int id2 : adjacencyList.get(id).toArray()) { if (id2 == destId) { return level; } if (!seen.contains(id2)) { queue.add(id2); seen.add(id2); } } } } return Double.POSITIVE_INFINITY; } BorderingDistanceMetric(SpatialDataDao dao, String layer); @Override void setValidConcepts(TIntSet concepts); @Override void enableCache(boolean enable); @Override String getName(); @Override double distance(Geometry g1, Geometry g2); @Override float[][] distance(List<Geometry> rowGeometries, List<Geometry> colGeometries); @Override float[][] distance(List<Geometry> geometries); @Override List<Neighbor> getNeighbors(Geometry g, int maxNeighbors); @Override List<Neighbor> getNeighbors(Geometry g, int maxNeighbors, double maxDistance); void setBufferWidth(double bufferWidth); void setMaxSteps(int maxSteps); void setForceContains(boolean forceContains);  }### Answer:
@Test public void testSimple() throws DaoException { assertEquals(0, metric.distance(g("Minnesota"), g("Minnesota")), 0.01); assertEquals(1, metric.distance(g("Wisconsin"), g("Minnesota")), 0.01); assertEquals(1, metric.distance(g("North Dakota"), g("Minnesota")), 0.01); assertEquals(1, metric.distance(g("South Dakota"), g("Minnesota")), 0.01); assertEquals(1, metric.distance(g("Iowa"), g("Minnesota")), 0.01); assertEquals(2, metric.distance(g("Illinois"), g("Minnesota")), 0.01); assertEquals(4, metric.distance(g("Texas"), g("Minnesota")), 0.01); assertEquals(0, metric.distance(g("Minnesota").getCentroid(), g("Minnesota")), 0.01); assertEquals(0, metric.distance(g("Minnesota"), g("Minnesota").getCentroid()), 0.01); assertEquals(4, metric.distance(g("Minnesota").getCentroid(), g("Texas").getCentroid()), 0.01); }