Class InsertionPoint<C extends Comparable<C>>
- Type Parameters:
C
- the domain type
- All Implemented Interfaces:
Comparable<InsertionPoint<C>>
BinarySearch
. An insertion point in a sequence of elements
(normally of indexes) is either an exact element, or in between two adjacent elements
in a discrete domain, or before or after all elements of the discrete domain.
If representing an exact point, exact()
, floor()
and ceiling()
all
return the element.
If it's between two elements, exact()
will return empty, and floor()
and ceiling()
will return the two adjacent elements respectively.
If it's below all possible elements, isBelowAll()
will return true and floor()
will throw. The ceiling()
method will return the min element of the domain (if present).
If it's above all possible elements, isAboveAll()
will return true and ceiling()
will throw. The floor()
method will return the max element of the domain (if present).
Over a discrete domain with N discrete elements, there are 2 * N + 1
distinct insertion
points, including all the elements, the points between each two adjacent elements, the point before
all elements and the point after all elements.
- Since:
- 8.0
-
Method Summary
Modifier and TypeMethodDescriptionstatic InsertionPoint
<Double> after
(double floor) Returns an insertion point immediately afterfloor
.static InsertionPoint
<Integer> after
(int floor) Returns an insertion point immediately after the givenfloor
and before the next integer (ifceiling
isn'tInteger.MAX_VALUE
).static InsertionPoint
<Long> after
(long floor) Returns an insertion point immediately after the givenfloor
and before the next integer (ifceiling
isn'tLong.MAX_VALUE
).static <C extends Comparable<C>>
InsertionPoint<C> after
(C floor, com.google.common.collect.DiscreteDomain<C> domain) Returns an insertion point immediately after the givenfloor
and before the next element in the given discretedomain
(if a next element exists).static <C extends Comparable<C>>
InsertionPoint<C> at
(C element) Returns an insertion point exactly atelement
such thatexact()
,floor
andceiling
all return the same element.static InsertionPoint
<Double> before
(double ceiling) Returns an insertion point immediately beforeceiling
.static InsertionPoint
<Integer> before
(int ceiling) Returns an insertion point immediately before the givenceiling
and after the previous integer (ifceiling
isn'tInteger.MIN_VALUE
).static InsertionPoint
<Long> before
(long ceiling) Returns an insertion point immediately before the givenceiling
and after the previous integer (ifceiling
isn'tLong.MIN_VALUE
).static <C extends Comparable<C>>
InsertionPoint<C> before
(C ceiling, com.google.common.collect.DiscreteDomain<C> domain) Returns an insertion point immediately before the givenceiling
and after the previous element in the given discretedomain
(if a previous element exists).static InsertionPoint
<Double> between
(double floor, double ceiling) Returns an insertion point in the open range of(floor, ceiling)
.ceiling()
Returns the ceiling element such that this insertion point is immediately<=
the ceiling.int
compareTo
(InsertionPoint<C> that) boolean
exact()
If this represents an exact point (not between two adjacent values), returns the element at the point; else returns empty.floor()
Returns the floor element such that this insertion point is immediately>=
the floor.int
hashCode()
boolean
Returns true if this is a point above the max possible element in the domain.boolean
Returns true if this is a point below the min possible element in the domain.toString()
Returns a human-readable string representation of this insertion point.
-
Method Details
-
at
Returns an insertion point exactly atelement
such thatexact()
,floor
andceiling
all return the same element. -
before
Returns an insertion point immediately before the givenceiling
and after the previous integer (ifceiling
isn'tInteger.MIN_VALUE
). -
before
Returns an insertion point immediately before the givenceiling
and after the previous integer (ifceiling
isn'tLong.MIN_VALUE
). -
before
Returns an insertion point immediately beforeceiling
. -
before
public static <C extends Comparable<C>> InsertionPoint<C> before(C ceiling, com.google.common.collect.DiscreteDomain<C> domain) Returns an insertion point immediately before the givenceiling
and after the previous element in the given discretedomain
(if a previous element exists). -
after
Returns an insertion point immediately after the givenfloor
and before the next integer (ifceiling
isn'tInteger.MAX_VALUE
). -
after
Returns an insertion point immediately after the givenfloor
and before the next integer (ifceiling
isn'tLong.MAX_VALUE
). -
after
Returns an insertion point immediately afterfloor
. -
after
public static <C extends Comparable<C>> InsertionPoint<C> after(C floor, com.google.common.collect.DiscreteDomain<C> domain) Returns an insertion point immediately after the givenfloor
and before the next element in the given discretedomain
(if a next element exists). -
between
Returns an insertion point in the open range of(floor, ceiling)
. -
exact
If this represents an exact point (not between two adjacent values), returns the element at the point; else returns empty. -
floor
Returns the floor element such that this insertion point is immediately>=
the floor.- Throws:
NoSuchElementException
- if this represents a point below all possible values in the discrete domain. Users can useisBelowAll()
to guard this condition.
-
ceiling
Returns the ceiling element such that this insertion point is immediately<=
the ceiling.- Throws:
NoSuchElementException
- if this represents a point above all possible values in the discrete domain. Users can useisAboveAll()
to guard this condition.
-
isAboveAll
public boolean isAboveAll()Returns true if this is a point above the max possible element in the domain. -
isBelowAll
public boolean isBelowAll()Returns true if this is a point below the min possible element in the domain. -
compareTo
- Specified by:
compareTo
in interfaceComparable<C extends Comparable<C>>
-
hashCode
public int hashCode() -
equals
-
toString
Returns a human-readable string representation of this insertion point.
-