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:
java.lang.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 java.lang.Object implements java.lang.Comparable<E>
Class used to represent connectable path elements for use withAbstractPathConnector
. 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:
AbstractPathConnector
-
-
Constructor Summary
Constructors Constructor Description ConnectableElement()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract boolean
canConnectTo(E nextElement)
Return true if this instance's end point can be connected to the argument's start point.void
connectTo(E nextElement)
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.E
exportPath()
Export the path that this element belongs to, returning the root segment.abstract E
getConnectionSearchKey()
Get a new instance used as a search key to help locate other elements with start points matching this instance's end point.E
getNext()
Get the next connected element in the path, if any.E
getPrevious()
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
hasPrevious()
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
markExported()
Set the export flag for this instance to true.protected void
setNext(E next)
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.
-
-
-
Field Detail
-
next
private E extends AbstractPathConnector.ConnectableElement<E> next
Next connected element.
-
previous
private E extends AbstractPathConnector.ConnectableElement<E> previous
Previous connected element.
-
exported
private boolean exported
Flag set to true when this element has exported its value to a path.
-
-
Method Detail
-
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
public E getNext()
Get the next connected element in the path, if any.- Returns:
- the next connected segment in the path; may be null
-
setNext
protected void setNext(E next)
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
public E getPrevious()
Get the previous connected element in the path, if any.- Returns:
- the previous connected element in the path; may be null
-
setPrevious
protected void setPrevious(E previous)
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
public void connectTo(E nextElement)
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
public E 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
public 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.- Parameters:
other
- element to compare end points with- Returns:
- true if this instance has an end point equivalent to that of the argument
-
canConnectTo
public abstract boolean canConnectTo(E nextElement)
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
public abstract double getRelativeAngle(E other)
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
public abstract E 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
public 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. 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
protected abstract E getSelf()
Return the current instance as the generic type.- Returns:
- the current instance as the generic type.
-
-