Class Range<T extends Comparable<T>>

java.lang.Object
org.springframework.data.domain.Range<T>

public final class Range<T extends Comparable<T>> extends Object
Simple value object to work with ranges and boundaries.
Since:
1.10
Author:
Oliver Gierke, Mark Paluch
  • Method Details

    • unbounded

      public static <T extends Comparable<T>> Range<T> unbounded()
      Returns an unbounded Range.
      Returns:
      Since:
      2.0
    • closed

      public static <T extends Comparable<T>> Range<T> closed(T from, T to)
      Creates a new Range with inclusive bounds for both values.
      Type Parameters:
      T -
      Parameters:
      from - must not be null.
      to - must not be null.
      Returns:
      Since:
      2.2
    • open

      public static <T extends Comparable<T>> Range<T> open(T from, T to)
      Creates a new Range with exclusive bounds for both values.
      Type Parameters:
      T -
      Parameters:
      from - must not be null.
      to - must not be null.
      Returns:
      Since:
      2.2
    • leftOpen

      public static <T extends Comparable<T>> Range<T> leftOpen(T from, T to)
      Creates a new left-open Range, i.e. left exclusive, right inclusive.
      Type Parameters:
      T -
      Parameters:
      from - must not be null.
      to - must not be null.
      Returns:
      Since:
      2.2
    • rightOpen

      public static <T extends Comparable<T>> Range<T> rightOpen(T from, T to)
      Creates a new right-open Range, i.e. left inclusive, right exclusive.
      Type Parameters:
      T -
      Parameters:
      from - must not be null.
      to - must not be null.
      Returns:
      Since:
      2.2
    • leftUnbounded

      public static <T extends Comparable<T>> Range<T> leftUnbounded(Range.Bound<T> to)
      Creates a left-unbounded Range (the left bound set to Range.Bound.unbounded()) with the given right bound.
      Type Parameters:
      T -
      Parameters:
      to - the right Range.Bound, must not be null.
      Returns:
      Since:
      2.2
    • rightUnbounded

      public static <T extends Comparable<T>> Range<T> rightUnbounded(Range.Bound<T> from)
      Creates a right-unbounded Range (the right bound set to Range.Bound.unbounded()) with the given left bound.
      Type Parameters:
      T -
      Parameters:
      from - the left Range.Bound, must not be null.
      Returns:
      Since:
      2.2
    • from

      public static <T extends Comparable<T>> Range.RangeBuilder<T> from(Range.Bound<T> lower)
      Create a Range.RangeBuilder given the lower Range.Bound.
      Parameters:
      lower - must not be null.
      Returns:
      Since:
      2.0
    • of

      public static <T extends Comparable<T>> Range<T> of(Range.Bound<T> lowerBound, Range.Bound<T> upperBound)
      Creates a new Range with the given lower and upper bound. Prefer from(Bound) for a more builder style API.
      Parameters:
      lowerBound - must not be null.
      upperBound - must not be null.
      Since:
      2.0
      See Also:
    • just

      public static <T extends Comparable<T>> Range<T> just(T value)
      Creates a new Range with the given value as sole member.
      Type Parameters:
      T -
      Parameters:
      value - must not be null.
      Returns:
      See Also:
    • contains

      public boolean contains(T value)
      Returns whether the Range contains the given value.
      Parameters:
      value - must not be null.
      Returns:
    • toString

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

      public Range.Bound<T> getLowerBound()
    • getUpperBound

      public Range.Bound<T> getUpperBound()
    • equals

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

      public int hashCode()
      Overrides:
      hashCode in class Object