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 Details

    • CANONICAL_COMPARATOR

      public static final Comparator<Endpoint<Comparable>> CANONICAL_COMPARATOR
      Canonical comparator for two end points.
    • NEGATIVE_INFINITY

      public static final Endpoint<?> NEGATIVE_INFINITY
      Immutable singleton instance of the end point representing negative infinity.
    • POSITIVE_INFINITY

      public static final Endpoint<?> POSITIVE_INFINITY
      Immutable singleton instance of the end point representing positive infinity.
    • boundType

      protected final com.google.common.collect.BoundType boundType
    • direction

      protected final EndpointDirection direction
    • point

      protected final C extends Comparable point
  • Constructor Details

    • Endpoint

      protected Endpoint(C point, com.google.common.collect.BoundType boundType, EndpointDirection direction)
    • Endpoint

      protected Endpoint(T item, EndpointAccessor<T,C> endpoint)
  • Method Details

    • compareTo

      public int compareTo(Endpoint<C> rhs)
      Specified by:
      compareTo in interface Comparable<C extends Comparable>
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • getBoundType

      public com.google.common.collect.BoundType getBoundType()
      Specified by:
      getBoundType in interface EndpointDescriptor
      Specified by:
      getBoundType in interface EndpointType
      Returns:
      Whether the interval end is open or closed.
    • getBoundType

      public com.google.common.collect.BoundType getBoundType(Void item)
      Specified by:
      getBoundType in interface EndpointAccessor<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

      public EndpointDirection getDirection()
      Specified by:
      getDirection in interface EndpointDescriptor
      Specified by:
      getDirection in interface EndpointType
      Returns:
      Whether the interval end is a lower or upper end.
    • getDirection

      public EndpointDirection getDirection(Void item)
      Specified by:
      getDirection in interface EndpointAccessor<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

      public C getPoint()
      Returns:
      The point object hold by this end point.
      Throws:
      IllegalStateException - When hasBound() returns false.
    • getPoint

      public C getPoint(Void item)
      Specified by:
      getPoint in interface EndpointAccessor<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 interface EndpointDescriptor
      Returns:
      Whether this end point has a bound with an associated point object, or is unbounded (negative or positive infinity).
    • hasBound

      public boolean hasBound(Void item)
      Specified by:
      hasBound in interface EndpointAccessor<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

      public String toString()
      Overrides:
      toString in class Object
    • closed

      public static <C extends Comparable> Endpoint<C> closed(C point, EndpointDirection direction)
      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

      public static <C extends Comparable> int compare(Endpoint<C> lhs, Endpoint<C> rhs)
      Compares first by getPoint(), if hasBound(), then by the EndpointType. Uses the EndpointTypeComparators.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

      public static <C extends Comparable> Comparator<Endpoint<C>> createComparator()
      Type Parameters:
      C - Type of the end point object.
      Returns:
      A comparator for end points. Compares first by getPoint(), if hasBound(), then by the EndpointType. Uses the EndpointTypeComparators.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(), if hasBound(), 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

      public static <C extends Comparable> Endpoint<C> infinite(EndpointDirection direction)
      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

      public static <C extends Comparable> Endpoint<C> lowerClosed(C point)
      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

      public static <C extends Comparable> Endpoint<C> lowerOpen(C point)
      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

      public static <C extends Comparable> Endpoint<C> negativeInfinity()
      Type Parameters:
      C - Type of the end point object.
      Returns:
      An end point describing positive infinity.
    • of

      public static <C extends Comparable> Endpoint<C> of(C point, EndpointDescriptor descriptor)
      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

      public static <T, C extends Comparable> Endpoint<C> of(T item, EndpointAccessor<T,C> accessor)
      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

      public static <C extends Comparable> Endpoint<C> open(C point, EndpointDirection direction)
      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

      public static <C extends Comparable> Endpoint<C> 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

      public static <C extends Comparable> Endpoint<C> upperClosed(C point)
      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

      public static <C extends Comparable> Endpoint<C> upperOpen(C point)
      Type Parameters:
      C - Type of the end point object.
      Parameters:
      point - End point object.
      Returns:
      An upper open end point for the given parameters.