Class AbstractPathConnector.ConnectableElement<E extends AbstractPathConnector.ConnectableElement<E>>
java.lang.Object
org.apache.commons.geometry.euclidean.internal.AbstractPathConnector.ConnectableElement<E>
- Type Parameters:
E
- Element type
- All Implemented Interfaces:
Comparable<E>
- Direct Known Subclasses:
AbstractGreatArcConnector.ConnectableGreatArc
,AbstractLinePathConnector.ConnectableLineSubset
- Enclosing class:
AbstractPathConnector<E extends AbstractPathConnector.ConnectableElement<E>>
public abstract static class AbstractPathConnector.ConnectableElement<E extends AbstractPathConnector.ConnectableElement<E>>
extends Object
implements Comparable<E>
Class used to represent connectable path elements for use with
AbstractPathConnector
.
Subclasses must fulfill the following requirements in order for path connection operations
to work correctly:
- Implement
Comparable.compareTo(Object)
such that elements are sorted by their start point locations. Other criteria may be used as well but elements with start points in close proximity must be grouped together. - Implement
getConnectionSearchKey()
such that it returns an instance that will be placed next to elements with start points close to the current instance's end point when sorted withComparable.compareTo(Object)
. - Implement
shouldContinueConnectionSearch(AbstractPathConnector.ConnectableElement, boolean)
such that it returns false when the search for possible connections through a sorted list of elements may terminate.
- See Also:
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract boolean
canConnectTo
(E nextElement) Return true if this instance's end point can be connected to the argument's start point.void
Connect this instance's end point to the given element's start point.abstract boolean
endPointsEq
(E other) Return true if the end point of this instance should be considered equivalent to the end point of the argument.Export the path that this element belongs to, returning the root segment.abstract E
Get a new instance used as a search key to help locate other elements with start points matching this instance's end point.getNext()
Get the next connected element in the path, if any.Get the previous connected element in the path, if any.abstract double
getRelativeAngle
(E other) Return the relative angle between this element and the argument.protected abstract E
getSelf()
Return the current instance as the generic type.abstract boolean
hasEnd()
Return true if this instance has an end point that can be connected to another element's start point.boolean
hasNext()
Return true if the instance is connected to another element's start point.boolean
Return true if another element is connected to this instance's start point.abstract boolean
hasStart()
Return true if this instance has a start point that can be connected to another element's end point.protected boolean
Set the export flag for this instance to true.protected void
Set the next connected element for this path.protected void
setPrevious
(E previous) Set the previous connected element for this path.abstract boolean
shouldContinueConnectionSearch
(E candidate, boolean ascending) Return true if the search for possible connections should continue through the sorted set of possible path elements given the current candidate element and search direction.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.lang.Comparable
compareTo
-
Field Details
-
next
Next connected element. -
previous
Previous connected element. -
exported
private boolean exportedFlag set to true when this element has exported its value to a path.
-
-
Constructor Details
-
ConnectableElement
public ConnectableElement()
-
-
Method Details
-
hasNext
public boolean hasNext()Return true if the instance is connected to another element's start point.- Returns:
- true if the instance has a next element
-
getNext
Get the next connected element in the path, if any.- Returns:
- the next connected segment in the path; may be null
-
setNext
Set the next connected element for this path. This is intended for internal use only. Callers should use theconnectTo(AbstractPathConnector.ConnectableElement)
method instead.- Parameters:
next
- next path element
-
hasPrevious
public boolean hasPrevious()Return true if another element is connected to this instance's start point.- Returns:
- true if the instance has a previous element
-
getPrevious
Get the previous connected element in the path, if any.- Returns:
- the previous connected element in the path; may be null
-
setPrevious
Set the previous connected element for this path. This is intended for internal use only. Callers should use theconnectTo(AbstractPathConnector.ConnectableElement)
method instead.- Parameters:
previous
- previous path element
-
connectTo
Connect this instance's end point to the given element's start point. No validation is performed in this method. ThecanConnectTo(AbstractPathConnector.ConnectableElement)
method must have been called previously.- Parameters:
nextElement
- the next element in the path
-
exportPath
Export the path that this element belongs to, returning the root segment. This method traverses all connected element, sets their exported flags to true, and returns the root element of the path (or this element in the case of a loop). Each path can only be exported once. Later calls to this method on this instance or any of its connected elements will return null.- Returns:
- the root of the path or null if the path that this element belongs to has already been exported
-
markExported
protected boolean markExported()Set the export flag for this instance to true. Returns true if the flag was changed and false otherwise.- Returns:
- true if the flag was changed and false if it was already set to true
-
hasStart
public abstract boolean hasStart()Return true if this instance has a start point that can be connected to another element's end point.- Returns:
- true if this instance has a start point that can be connected to another element's end point
-
hasEnd
public abstract boolean hasEnd()Return true if this instance has an end point that can be connected to another element's start point.- Returns:
- true if this instance has an end point that can be connected to another element's start point
-
endPointsEq
Return true if the end point of this instance should be considered equivalent to the end point of the argument.- Parameters:
other
- element to compare end points with- Returns:
- true if this instance has an end point equivalent to that of the argument
-
canConnectTo
Return true if this instance's end point can be connected to the argument's start point.- Parameters:
nextElement
- candidate for the next element in the path; this value is guaranteed to not be null and to contain a start point- Returns:
- true if this instance's end point can be connected to the argument's start point
-
getRelativeAngle
Return the relative angle between this element and the argument.- Parameters:
other
- element to compute the angle with- Returns:
- the relative angle between this element and the argument
-
getConnectionSearchKey
Get a new instance used as a search key to help locate other elements with start points matching this instance's end point. The only restriction on the returned instance is that it be compatible with the implementation class'Comparable.compareTo(Object)
method.- Returns:
- a new instance used to help locate other path elements with start points equivalent to this instance's end point
-
shouldContinueConnectionSearch
Return true if the search for possible connections should continue through the sorted set of possible path elements given the current candidate element and search direction. The search operation stops for the given direction when this method returns false.- Parameters:
candidate
- last tested candidate connection elementascending
- true if the search is proceeding in an ascending direction; false otherwise- Returns:
- true if the connection search should continue
-
getSelf
Return the current instance as the generic type.- Returns:
- the current instance as the generic type.
-