T
- the type of all nodes in the Graph
public interface Graph<T>
null
and must
provide meaningful Object.equals(java.lang.Object)
and Object.hashCode()
implementations.Modifier and Type | Method and Description |
---|---|
int |
connectivity()
Gets the maximum number of direct neighbors for any
Graph node. |
boolean |
contains(T node)
Determines whether the
Graph contains the specified node. |
T |
findNearestNode(PointD location)
|
double |
getDistance(T source,
T target)
Gets the distance between two specified
Graph nodes. |
java.util.Collection<T> |
getNeighbors(T node)
Gets all direct neighbors of the specified
Graph node. |
default java.util.Collection<T> |
getNeighbors(T node,
int steps)
Gets all neighbors of the specified
Graph node within the specified step distance. |
PointD |
getWorldLocation(T node)
Gets the world location of the specified
Graph node. |
PointD[] |
getWorldRegion(T node)
Gets the world region covered by the specified
Graph node. |
int |
nodeCount()
|
java.util.Collection<T> |
nodes()
Gets all nodes in the
Graph . |
int connectivity()
Graph
node.
Always greater than zero. Direct neighbors of a given Graph
node
are those that are directly connected, without any intermediate nodes.Graph
nodejava.util.Collection<T> nodes()
Graph
.
Always contains nodeCount()
elements. The element order depends
on the concrete implementation of Graph
.Collection
of all nodes in the Graph
T findNearestNode(PointD location)
Graph
node nearest to the specified PointD
world location.
Always returns a valid node, even if the distance between its getWorldLocation(T)
result and location
is very large. The returned node is not necessarily the one
whose getWorldRegion(T)
result contains location
.location
- the PointD
location, in world coordinates, to examineGraph
node whose getWorldLocation(T)
result
is nearest to the specified location
java.lang.NullPointerException
- if location
is null
double getDistance(T source, T target)
Graph
nodes.
Uses an arbitrary distance measurement, as documented by the implementation.
However, the result must always conform to the following invariants:
GraphAgent.getStepCost(T, T)
for the same two nodes.java.util.Collection<T> getNeighbors(T node)
Graph
node.
Returns an empty Collection
if node
or all its direct neighbors are
not part of the Graph
. The returned Collection
is the complete set
of target nodes for which GraphAgent.canMakeStep(T, T)
could possibly succeed,
given the specified node
as the source node.node
- the Graph
node whose direct neighbors to collectCollection
of all Graph
nodes that are directly
connected with node
, numbering from zero to connectivity()
java.lang.NullPointerException
- if node
is null
default java.util.Collection<T> getNeighbors(T node, int steps)
Graph
node within the specified step distance.
Returns an empty Collection
if node
or all its direct neighbors are
not part of the Graph
. Otherwise, returns a Collection
containing all
direct neighbors, direct neighbors of those neighbors, etc. repeated for steps
.
The default implementation uses two lists for gathering direct neighbors to inspect,
and returns a HashSet
with all valid neighbors found within steps
. This
requires the node type T to offer a useful Object.hashCode()
function.
Specific Graph
implementations may be able to use more efficient algorithms.
node
- the Graph
node whose neighbors within steps
to collectsteps
- the distance around node
, in movement steps,
in which other nodes are considered neighbors of node
Collection
of all Graph
nodes whose step distance from
node
is greater than zero, but equal to or less than steps
java.lang.IllegalArgumentException
- if steps
is equal to or less than zerojava.lang.NullPointerException
- if node
is null
PointD getWorldLocation(T node)
Graph
node.
Uses an arbitrary “world” coordinate system, as documented by the implementation.
The world location always resides within the result of getWorldRegion(T)
for
the same node
. The result of getDistance(T, T)
for any two nodes is usually
the Euclidean distance between their world locations, but this is not required.PointD[] getWorldRegion(T node)
Graph
node.
Uses an arbitrary “world” coordinate system, as documented by the implementation.
The returned polygon is implicitly assumed to be closed, with an edge connecting its
last and first vertex. The polygon should be simple and enclose a positive area that
contains the result of getWorldLocation(T)
for node
.