Package me.ahoo.cosid.sharding
Record Class ShardingRange<C extends Comparable<? super C>>
java.lang.Object
java.lang.Record
me.ahoo.cosid.sharding.ShardingRange<C>
- Type Parameters:
C- the type of the values- Record Components:
lower- the lower endpoint,nullfor nonelowerType- whether the lower endpoint belongs to the rangeupper- the upper endpoint,nullfor noneupperType- whether the upper endpoint belongs to the range
public record ShardingRange<C extends Comparable<? super C>>(C extends Comparable<? super C> lower, BoundType lowerType, C extends Comparable<? super C> upper, BoundType upperType)
extends Record
A range of sharding values, the query a
RangeSharding answers. It replaces the Guava Range of 4.x, so
that cosid-sharding depends on cosid-core alone (D7); the factory methods keep Guava's names.
A missing endpoint (null) means the range is unbounded on that side; its bound type is then
BoundType.OPEN. A range is never inverted: the lower bound is at most the upper bound, and (a, a)
is rejected, as in Guava. [a, a) and (a, a] are the empty ranges.
-
Constructor Summary
ConstructorsConstructorDescriptionShardingRange(C lower, BoundType lowerType, C upper, BoundType upperType) Checks the bounds. -
Method Summary
Modifier and TypeMethodDescriptionstatic <C extends Comparable<? super C>>
ShardingRange<C> all()Every value.static <C extends Comparable<? super C>>
ShardingRange<C> atLeast(C lower) [lower..+∞).static <C extends Comparable<? super C>>
ShardingRange<C> atMost(C upper) (-∞..upper].static <C extends Comparable<? super C>>
ShardingRange<C> closed(C lower, C upper) [lower..upper].static <C extends Comparable<? super C>>
ShardingRange<C> closedOpen(C lower, C upper) [lower..upper).booleanWhether the value lies in the range.final booleanIndicates whether some other object is "equal to" this one.static <C extends Comparable<? super C>>
ShardingRange<C> greaterThan(C lower) (lower..+∞).final inthashCode()Returns a hash code value for this object.booleanWhether the range has a lower endpoint.booleanWhether the range has an upper endpoint.booleanisConnected(ShardingRange<C> other) Whether some range, possibly empty, is enclosed by both ranges, as Guava'sRange.isConnected:[1..2)and[2..3]are connected,[1..2)and(2..3]are not.booleanisEmpty()Whether the range holds no value:[a..a)or(a..a].static <C extends Comparable<? super C>>
ShardingRange<C> lessThan(C upper) (-∞..upper).lower()Returns the value of thelowerrecord component.Whether the lower endpoint belongs to the range.The lower endpoint.Returns the value of thelowerTyperecord component.static <C extends Comparable<? super C>>
ShardingRange<C> open(C lower, C upper) (lower..upper).static <C extends Comparable<? super C>>
ShardingRange<C> openClosed(C lower, C upper) (lower..upper].static <C extends Comparable<? super C>>
ShardingRange<C> singleton(C value) [value..value].toString()Returns a string representation of this record class.upper()Returns the value of theupperrecord component.Whether the upper endpoint belongs to the range.The upper endpoint.Returns the value of theupperTyperecord component.
-
Constructor Details
-
ShardingRange
Checks the bounds.
-
-
Method Details
-
all
Every value.- Type Parameters:
C- the type of the values- Returns:
(-∞..+∞)
-
closed
[lower..upper].- Type Parameters:
C- the type of the values- Parameters:
lower- the lower endpoint, includedupper- the upper endpoint, included- Returns:
- the range
-
open
(lower..upper).- Type Parameters:
C- the type of the values- Parameters:
lower- the lower endpoint, excludedupper- the upper endpoint, excluded- Returns:
- the range
-
closedOpen
[lower..upper).- Type Parameters:
C- the type of the values- Parameters:
lower- the lower endpoint, includedupper- the upper endpoint, excluded- Returns:
- the range
-
openClosed
(lower..upper].- Type Parameters:
C- the type of the values- Parameters:
lower- the lower endpoint, excludedupper- the upper endpoint, included- Returns:
- the range
-
atLeast
[lower..+∞).- Type Parameters:
C- the type of the values- Parameters:
lower- the lower endpoint, included- Returns:
- the range
-
greaterThan
(lower..+∞).- Type Parameters:
C- the type of the values- Parameters:
lower- the lower endpoint, excluded- Returns:
- the range
-
atMost
(-∞..upper].- Type Parameters:
C- the type of the values- Parameters:
upper- the upper endpoint, included- Returns:
- the range
-
lessThan
(-∞..upper).- Type Parameters:
C- the type of the values- Parameters:
upper- the upper endpoint, excluded- Returns:
- the range
-
singleton
[value..value].- Type Parameters:
C- the type of the values- Parameters:
value- the only value- Returns:
- the range
-
hasLowerBound
public boolean hasLowerBound()Whether the range has a lower endpoint.- Returns:
- true when bounded below
-
hasUpperBound
public boolean hasUpperBound()Whether the range has an upper endpoint.- Returns:
- true when bounded above
-
lowerEndpoint
The lower endpoint.- Returns:
- the lower endpoint
- Throws:
IllegalStateException- when the range is unbounded below
-
upperEndpoint
The upper endpoint.- Returns:
- the upper endpoint
- Throws:
IllegalStateException- when the range is unbounded above
-
lowerBoundType
Whether the lower endpoint belongs to the range.- Returns:
- the lower bound type
- Throws:
IllegalStateException- when the range is unbounded below
-
upperBoundType
Whether the upper endpoint belongs to the range.- Returns:
- the upper bound type
- Throws:
IllegalStateException- when the range is unbounded above
-
isEmpty
public boolean isEmpty()Whether the range holds no value:[a..a)or(a..a].- Returns:
- true when empty
-
contains
Whether the value lies in the range.- Parameters:
value- the value- Returns:
- true when the range contains it
-
isConnected
Whether some range, possibly empty, is enclosed by both ranges, as Guava'sRange.isConnected:[1..2)and[2..3]are connected,[1..2)and(2..3]are not.- Parameters:
other- the other range- Returns:
- true when connected
-
toString
Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components. -
hashCode
public final int hashCode()Returns a hash code value for this object. The value is derived from the hash code of each of the record components. -
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared withObjects::equals(Object,Object). -
lower
Returns the value of thelowerrecord component.- Returns:
- the value of the
lowerrecord component
-
lowerType
Returns the value of thelowerTyperecord component.- Returns:
- the value of the
lowerTyperecord component
-
upper
Returns the value of theupperrecord component.- Returns:
- the value of the
upperrecord component
-
upperType
Returns the value of theupperTyperecord component.- Returns:
- the value of the
upperTyperecord component
-