@Override public Set<Connection<E>> getConnections() { return delegate.getConnections(); }
@Override public Set<Connection<E>> getConnections() { return delegate.getConnections(); }
@Override public Set<Connection<E>> getConnections() { return Collections.unmodifiableSet(delegate.getConnections()); }
@Override public Set<Connection<E>> getConnections() { return Collections.unmodifiableSet(delegate.getConnections()); }
@Override public Set<Connection<E>> getConnections() { return Collections.unmodifiableSet(delegate.getConnections()); }
@Override public Set<Connection<E>> getConnections() { return Collections.unmodifiableSet(delegate.getConnections()); }
/** * Basic equals method. * @param g1 A graph. * @param other The object to compare for equality with g1. * @return <code>true</code> if the provided graphs are equal, * <code>false</code> otherwise. */ public static boolean equal(Graph<?> g1, @Nullable Object other) { if (!(other instanceof Graph<?>)) { return false; } final Graph<?> g2 = (Graph<?>) other; return Objects.equal(g1.getConnections(), g2.getConnections()); }
/** * Basic equals method. * @param g1 A graph. * @param other The object to compare for equality with g1. * @return <code>true</code> if the provided graphs are equal, * <code>false</code> otherwise. */ public static boolean equal(Graph<?> g1, @Nullable Object other) { if (!(other instanceof Graph<?>)) { return false; } final Graph<?> g2 = (Graph<?>) other; return Objects.equal(g1.getConnections(), g2.getConnections()); }
@Override public void merge(Graph<E> other) { for (final Connection<E> connection : other.getConnections()) { addConnection(connection); } }
@Override public void merge(Graph<E> other) { for (final Connection<E> connection : other.getConnections()) { addConnection(connection); } }
@Override public void merge(Graph<E> other) { addConnections(other.getConnections()); }
@Override public void merge(Graph<E> other) { addConnections(other.getConnections()); }
/** * Creates an immutable copy of the specified {@link Graph}. This method * recognizes when the supplied graph is an instance of {@link ImmutableGraph} * , and will avoid making a copy in this case. * @param graph A graph. * @param <E> The type of connection data. * @return An immutable copy of the graph. */ @SuppressWarnings("unchecked") public static <E extends ConnectionData> ImmutableGraph<E> copyOf( Graph<? extends E> graph) { if (graph instanceof ImmutableGraph) { return (ImmutableGraph<E>) graph; } return new ImmutableGraph<>(graph.getConnections()); }
/** * Creates an immutable copy of the specified {@link Graph}. This method * recognizes when the supplied graph is an instance of {@link ImmutableGraph} * , and will avoid making a copy in this case. * @param graph A graph. * @param <E> The type of connection data. * @return An immutable copy of the graph. */ @SuppressWarnings("unchecked") public static <E extends ConnectionData> ImmutableGraph<E> copyOf( Graph<? extends E> graph) { if (graph instanceof ImmutableGraph) { return (ImmutableGraph<E>) graph; } return new ImmutableGraph<>(graph.getConnections()); }
private Table<Point, Point, Connection<?>> filterConnections() { // filter connections to avoid double work for bidirectional roads final Table<Point, Point, Connection<?>> filteredConnections = HashBasedTable .create(); for (final Connection<?> e : graph.getConnections()) { if (!filteredConnections.contains(e.to(), e.from())) { filteredConnections.put(e.from(), e.to(), e); } } return filteredConnections; }
/** * Tests whether self cycles are indeed filtered out. * @throws IOException Should not happen. */ @SuppressWarnings("static-method") @Test public void testSelfCycleFilter() throws IOException { final StringReader sr = new StringReader( "n0[p=\"5,5\"]\nn1[p=\"4,4\"]\nn0 -> n0\nn0 -> n1"); final Graph<?> g = DotGraphIO.getLengthGraphIO(Filters.selfCycleFilter()) .read(sr); assertEquals(1, g.getConnections().size()); }
@Test public void connectionOrder() { Point N, NE, E, SE, S, SW, W, NW; N = new Point(0, 5); NE = new Point(5, 5); E = new Point(5, 0); SE = new Point(5, -5); S = new Point(0, -5); SW = new Point(-5, -5); W = new Point(-5, 0); NW = new Point(-5, 5); Graphs.addPath(graph, N, NE, E, SE, S, SW, W, NW); final List<Point> points = Arrays.asList(N, NE, E, SE, S, SW, W, NW); final List<Connection<LengthData>> connections = newArrayList(graph .getConnections()); for (int i = 1; i < points.size(); i++) { assertSame(connections.get(i - 1).from(), points.get(i - 1)); assertSame(connections.get(i - 1).to(), points.get(i)); } }
@Test public void removeNode() { final Point N = new Point(0, 5); final Point E = new Point(5, 0); final Point S = new Point(0, -5); final Point W = new Point(-5, 0); Graphs.addBiPath(graph, N, E, S, W, N); final Graph<LengthData> unmod = Graphs.unmodifiableGraph(graph); assertEquals(graph, unmod); assertEquals(4, graph.getNodes().size()); assertEquals(8, graph.getConnections().size()); graph.removeNode(N); assertEquals(graph, unmod); assertEquals(3, graph.getNodes().size()); assertEquals(4, graph.getConnections().size()); }
/** * Tests reading a dot file in legacy format. * @throws IOException In case of IO problems. */ @SuppressWarnings("static-method") @Test public void testLegacy() throws IOException { final Graph<LengthData> ldGraph = DotGraphIO.getLengthGraphIO().read( new StringReader(Joiner.on("\n").join(LEGACY_FORMAT))); final Graph<MultiAttributeData> maGraph = DotGraphIO.getMultiAttributeGraphIO() .read(new StringReader(Joiner.on("\n").join(LEGACY_FORMAT))); testLegacyFormat(ldGraph); testLegacyFormat(maGraph); final Point n0 = new Point(3296724.2131123254, 2.5725043247255992E7); final Point n19663 = new Point(3296782.7337179, 2.5724994399343655E7); for (final Connection<MultiAttributeData> conn : maGraph.getConnections()) { if (conn.from().equals(n0) && conn.to().equals(n19663)) { assertFalse(conn.data().get().getMaxSpeed().isPresent()); } else { assertEquals(50000d, conn.data().get().getMaxSpeed().get() .doubleValue(), 0); } } }
@Test public void unmodifiable() { final Point N = new Point(0, 5); final Point E = new Point(5, 0); final Point S = new Point(0, -5); final Point W = new Point(-5, 0); Graphs.addBiPath(graph, N, E, S, W, N); final Graph<LengthData> g = Graphs.unmodifiableGraph(graph); g.hashCode(); assertEquals(graph, g); assertEquals(g, graph); assertFalse(g.equals(new Object())); assertFalse(g.isEmpty()); for (final Point p : g.getNodes()) { assertArrayEquals(graph.getIncomingConnections(p).toArray(), g .getIncomingConnections(p).toArray()); } for (final Connection<LengthData> c : g.getConnections()) { assertEquals(graph.connectionLength(c.from(), c.to()), g.connectionLength(c.from(), c.to()), DELTA); } }