static void checkConnectionLength(double minConnLength, Connection<?> conn) { checkArgument( Point.distance(conn.from(), conn.to()) >= minConnLength, "Invalid graph: the minimum connection length is %s, connection %s->%s" + " is too short.", minConnLength, conn.from(), conn.to()); checkArgument( conn.getLength() >= minConnLength, "Invalid graph: the minimum connection length is %s, connection %s->%s " + "defines length data that is too short: %s.", minConnLength, conn.from(), conn.to(), conn.getLength()); }
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; }
static double angle(Connection<?> connection) { return angle(connection.from(), connection.to()); }
@Override public boolean apply(@Nullable Connection<?> input) { final Connection<?> in = verifyNotNull(input); return !in.from().equals(in.to()); } }
@Override public boolean apply(@Nullable Connection<?> input) { final Connection<?> in = verifyNotNull(input); return !in.from().equals(in.to()); } }
/** * @return The length of this connection as specified by the data or * alternatively by the euclidean distance between the two points. */ public double getLength() { if (data().isPresent() && data().get().getLength().isPresent()) { return data().get().getLength().get(); } return Point.distance(from(), to()); }
/** * @return The length of this connection as specified by the data or * alternatively by the euclidean distance between the two points. */ public double getLength() { if (data().isPresent() && data().get().getLength().isPresent()) { return data().get().getLength().get(); } return Point.distance(from(), to()); }
@Override public void addConnection(Connection<E> c) { addConnection(c.from(), c.to(), c.data()); }
@SuppressWarnings("unchecked") ImmutableGraph(Iterable<? extends Connection<? extends E>> connections) { final ImmutableTable.Builder<Point, Point, Connection<E>> tableBuilder = ImmutableTable.builder(); for (final Connection<? extends E> conn : connections) { tableBuilder.put(conn.from(), conn.to(), (Connection<E>) conn); } data = tableBuilder.build(); }
@SuppressWarnings("unchecked") ImmutableGraph(Iterable<? extends Connection<? extends E>> connections) { final ImmutableTable.Builder<Point, Point, Connection<E>> tableBuilder = ImmutableTable.builder(); for (final Connection<? extends E> conn : connections) { tableBuilder.put(conn.from(), conn.to(), (Connection<E>) conn); } data = tableBuilder.build(); }
@Override public boolean equals(Object o) { if (o == this) { return true; } if (o instanceof Connection) { Connection<?> that = (Connection<?>) o; return (this.from.equals(that.from())) && (this.to.equals(that.to())) && (this.data.equals(that.data())); } return false; }
@Override public boolean equals(Object o) { if (o == this) { return true; } if (o instanceof Connection) { Connection<?> that = (Connection<?>) o; return (this.from.equals(that.from())) && (this.to.equals(that.to())) && (this.data.equals(that.data())); } return false; }
@Override protected void checkMoveValidity(Point objLoc, Point nextHop) { super.checkMoveValidity(objLoc, nextHop); // check if there is a vehicle driving in the opposite direction if (!objLoc.equals(nextHop)) { final Connection<?> conn = getConnection(objLoc, nextHop); if (graph.hasConnection(conn.to(), conn.from()) && registry() .hasObjectOn(Connection.create(conn.to(), conn.from()))) { throw new DeadlockException(conn); } } }
static boolean connectionEquals(Connection<?> conn, Point from, Point to) { return conn.from().equals(from) && conn.to().equals(to); } }