Package de.xima.fc.utils.range
Class Endpoint<C extends Comparable>
java.lang.Object
de.xima.fc.utils.range.Endpoint<C>
- Type Parameters:
C
- Type of the items of the ranges.
- All Implemented Interfaces:
EndpointAccessor<Void,
,C> EndpointDescriptor
,EndpointType
,Serializable
,Comparable<Endpoint<C>>
public class Endpoint<C extends Comparable>
extends Object
implements EndpointDescriptor, EndpointAccessor<Void,C>, Comparable<Endpoint<C>>, Serializable
POJO class describing an end point of a range, either a lower or upper end point. Contains the point and its meta
data.
- Since:
- 6.5.0
- Author:
- XIMA MEDIA GmbH
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final com.google.common.collect.BoundType
static final Comparator<Endpoint<Comparable>>
Canonical comparator for two end points.protected final EndpointDirection
static final Endpoint<?>
Immutable singleton instance of the end point representing negative infinity.protected final C
static final Endpoint<?>
Immutable singleton instance of the end point representing positive infinity. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
Endpoint
(C point, com.google.common.collect.BoundType boundType, EndpointDirection direction) protected
Endpoint
(T item, EndpointAccessor<T, C> endpoint) -
Method Summary
Modifier and TypeMethodDescriptionstatic <C extends Comparable>
Endpoint<C>closed
(C point, EndpointDirection direction) static <C extends Comparable>
intint
static <C extends Comparable>
Comparator<Endpoint<C>>static <C extends Comparable>
Comparator<Endpoint<C>>createComparator
(EndpointTypeComparator comparator) boolean
static <C extends Comparable>
Endpoint<C>finite
(C point, com.google.common.collect.BoundType boundType, EndpointDirection direction) com.google.common.collect.BoundType
com.google.common.collect.BoundType
getBoundType
(Void item) getDirection
(Void item) getPoint()
boolean
hasBound()
boolean
int
hashCode()
static <C extends Comparable>
Endpoint<C>infinite
(EndpointDirection direction) static <C extends Comparable>
Endpoint<C>lower
(C point, com.google.common.collect.BoundType boundType) static <C extends Comparable>
Endpoint<C>lowerClosed
(C point) static <C extends Comparable>
Endpoint<C>lowerOpen
(C point) static <C extends Comparable>
Endpoint<C>static <C extends Comparable>
Endpoint<C>of
(C point, EndpointDescriptor descriptor) static <T,
C extends Comparable>
Endpoint<C>of
(T item, EndpointAccessor<T, C> accessor) static <C extends Comparable>
Endpoint<C>open
(C point, EndpointDirection direction) static <C extends Comparable>
Endpoint<C>toString()
static <C extends Comparable>
Endpoint<C>upper
(C point, com.google.common.collect.BoundType boundType) static <C extends Comparable>
Endpoint<C>upperClosed
(C point) static <C extends Comparable>
Endpoint<C>upperOpen
(C point) Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface de.xima.fc.utils.range.EndpointAccessor
compareByEndpoint, compareByEndpoint, createByEndpointComparator, createByEndpointComparator, mapping, toDescriptor, toEndpoint
Methods inherited from interface de.xima.fc.utils.range.EndpointDescriptor
isLowerPoint, isUpperPoint, toAcessor, toEndpoint
-
Field Details
-
CANONICAL_COMPARATOR
Canonical comparator for two end points. -
NEGATIVE_INFINITY
Immutable singleton instance of the end point representing negative infinity. -
POSITIVE_INFINITY
Immutable singleton instance of the end point representing positive infinity. -
boundType
protected final com.google.common.collect.BoundType boundType -
direction
-
point
-
-
Constructor Details
-
Endpoint
protected Endpoint(C point, com.google.common.collect.BoundType boundType, EndpointDirection direction) -
Endpoint
-
-
Method Details
-
compareTo
- Specified by:
compareTo
in interfaceComparable<C extends Comparable>
-
equals
-
hashCode
public int hashCode() -
getBoundType
public com.google.common.collect.BoundType getBoundType()- Specified by:
getBoundType
in interfaceEndpointDescriptor
- Specified by:
getBoundType
in interfaceEndpointType
- Returns:
- Whether the interval end is open or closed.
-
getBoundType
- Specified by:
getBoundType
in interfaceEndpointAccessor<Void,
C extends Comparable> - Parameters:
item
- An item with an endpoint to check.- Returns:
- Whether the endpoint describes by the given item is closed or open.
-
getDirection
- Specified by:
getDirection
in interfaceEndpointDescriptor
- Specified by:
getDirection
in interfaceEndpointType
- Returns:
- Whether the interval end is a lower or upper end.
-
getDirection
- Specified by:
getDirection
in interfaceEndpointAccessor<Void,
C extends Comparable> - Parameters:
item
- An item with an endpoint to check.- Returns:
- Whether the end point described by the given item is a lower or upper end point.
-
getPoint
- Returns:
- The point object hold by this end point.
- Throws:
IllegalStateException
- WhenhasBound()
returnsfalse
.
-
getPoint
- Specified by:
getPoint
in interfaceEndpointAccessor<Void,
C extends Comparable> - Parameters:
item
- An item with an endpoint to process.- Returns:
- The endpoint described by the given item.
-
hasBound
public boolean hasBound()- Specified by:
hasBound
in interfaceEndpointDescriptor
- Returns:
- Whether this end point has a bound with an associated point object, or is unbounded (negative or positive infinity).
-
hasBound
- Specified by:
hasBound
in interfaceEndpointAccessor<Void,
C extends Comparable> - Parameters:
item
- An item with an endpoint to check.- Returns:
- Whether the range defined by the item has a bound (or describes positive or negative infinity).
-
toString
-
closed
- Type Parameters:
C
- Type of the end point object.- Parameters:
point
- End point object.direction
- Whether to create a lower or upper end point.- Returns:
- A closed end point for the given parameters.
-
compare
Compares first bygetPoint()
, ifhasBound()
, then by theEndpointType
. Uses theEndpointTypeComparators.UNORDERED
for comparing end point types.- Type Parameters:
C
- Type of the end point object.- Parameters:
lhs
- First end point to compare.rhs
- Second end point to compare.- Returns:
- Result of the comparison.
-
createComparator
- Type Parameters:
C
- Type of the end point object.- Returns:
- A comparator for end points. Compares first by
getPoint()
, ifhasBound()
, then by theEndpointType
. Uses theEndpointTypeComparators.CANONICAL
for comparing end point types.
-
createComparator
public static <C extends Comparable> Comparator<Endpoint<C>> createComparator(EndpointTypeComparator comparator) - Type Parameters:
C
- Type of the end point object.- Parameters:
comparator
- Comparator for comparing end point types.- Returns:
- A comparator for end points. Compares first by
getPoint()
, ifhasBound()
, then by the given end point comparator.
-
finite
public static <C extends Comparable> Endpoint<C> finite(C point, com.google.common.collect.BoundType boundType, EndpointDirection direction) - Type Parameters:
C
- Type of the end point object.- Parameters:
point
- End point object.boundType
- Whether to create an open or closed end point.direction
- Whether to create a lower or upper end point.- Returns:
- A finite end point for the given parameters.
-
infinite
- Type Parameters:
C
- Type of the end point object.- Parameters:
direction
- Whether to create a lower or upper end point.- Returns:
- A infinite end point with the given parameters.
-
lower
public static <C extends Comparable> Endpoint<C> lower(C point, com.google.common.collect.BoundType boundType) - Type Parameters:
C
- Type of the end point object.- Parameters:
point
- End point object.boundType
- Whether to create an open or closed end point.- Returns:
- A lower end point for the given parameters.
-
lowerClosed
- Type Parameters:
C
- Type of the end point object.- Parameters:
point
- End point object.- Returns:
- A lower closed end point for the given parameters.
-
lowerOpen
- Type Parameters:
C
- Type of the end point object.- Parameters:
point
- End point object.- Returns:
- A lower open end point for the given parameters.
-
negativeInfinity
- Type Parameters:
C
- Type of the end point object.- Returns:
- An end point describing positive infinity.
-
of
- Type Parameters:
C
- Type of the end point object.- Parameters:
point
- End point object.descriptor
- Meta data about the end point to create-- Returns:
- An end point for the given parameters.
-
of
- Type Parameters:
T
- Type of the objects holding an end point.C
- Type of the end point object.- Parameters:
item
- Object that holds an end point.accessor
- Accessor for accessing the end point on the given object.- Returns:
- An end point for the given parameters.
-
open
- Type Parameters:
C
- Type of the end point object.- Parameters:
point
- End point object.direction
- Whether to create a lower or upper end point.- Returns:
- An open end point for the given parameters.
-
positiveInfinity
- Type Parameters:
C
- Type of the end point object.- Returns:
- An end point describing positive infinity.
-
upper
public static <C extends Comparable> Endpoint<C> upper(C point, com.google.common.collect.BoundType boundType) - Type Parameters:
C
- Type of the end point object.- Parameters:
point
- End point object.boundType
- Whether to create an open or closed end poit.- Returns:
- An upper end point for the given parameters.
-
upperClosed
- Type Parameters:
C
- Type of the end point object.- Parameters:
point
- End point object.- Returns:
- An upper closed end point for the given parameters.
-
upperOpen
- Type Parameters:
C
- Type of the end point object.- Parameters:
point
- End point object.- Returns:
- An upper open end point for the given parameters.
-