Package io.permazen.kv
Class KeyRange
java.lang.Object
io.permazen.kv.KeyRange
Represents a contiguous range of
byte[]
keys, when keys are sorted in unsigned lexical order.
Instances are defined by an inclusive lower bound and an exclusive upper bound.
The upper bound may be specified as null to represent no maximum.
Instances are immutable: the minimum and maximum byte[]
arrays are copied during
construction and when accessed by getMin()
and getMax()
.
-
Field Summary
Modifier and TypeFieldDescriptionstatic final KeyRange
TheKeyRange
containing the full range (i.e., all keys).protected final ByteData
Upper bound (exclusive), or null for no maximum.protected final ByteData
Lower bound (inclusive), never null;static final Comparator<KeyRange>
static final Comparator<KeyRange>
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic int
Compare twobyte[]
keys using unsigned lexical ordering, while also accepting null values that represent "positive infinity".int
Determine if this range is left of, contains, or is right of the given key.boolean
Determine if this key range fully contains the specified key range.boolean
Determine if this key range contains the specified key.static KeyRange
Create an empty key range at the specified key.boolean
static KeyRange
Construct an instance containing all keys with the given prefix.getMax()
Get range maximum (exclusive), or null if there is no upper bound.getMin()
Get range minimum (inclusive).int
hashCode()
boolean
isEmpty()
boolean
isFull()
Determine whether this instance contains the full range covering all keys.boolean
Determine whether this instance contains all keys having some common prefix.boolean
Determine whether this instance contains exactly one key.boolean
Determine if this key range overlaps the specified key range, i.e., there exists at least onebyte[]
key that both ranges have in common.prefixedBy
(ByteData prefix) Create a new instance whose minimum and maximum keys are the same as this instance's but with the given byte sequence prepended.toString()
-
Field Details
-
FULL
TheKeyRange
containing the full range (i.e., all keys). -
SORT_BY_MIN
-
SORT_BY_MAX
-
min
Lower bound (inclusive), never null; -
max
Upper bound (exclusive), or null for no maximum.
-
-
Constructor Details
-
KeyRange
Constructor.- Parameters:
min
- minimum key (inclusive); must not be nullmax
- maximum key (exclusive), or null for no maximum- Throws:
IllegalArgumentException
- ifmin
is nullIllegalArgumentException
- ifmin > max
-
KeyRange
Construct key range containing a single key.- Parameters:
key
- the key contained in the range- Throws:
IllegalArgumentException
- ifkey
is null
-
-
Method Details
-
forPrefix
Construct an instance containing all keys with the given prefix.- Parameters:
prefix
- prefix of all keys in the range- Returns:
- range of keys prefixed by
prefix
- Throws:
IllegalArgumentException
- ifprefix
is null
-
getMin
Get range minimum (inclusive).- Returns:
- inclusivie minimum, never null
-
getMax
Get range maximum (exclusive), or null if there is no upper bound.- Returns:
- exclusivie maximum, or null for none
-
overlaps
Determine if this key range overlaps the specified key range, i.e., there exists at least onebyte[]
key that both ranges have in common.- Parameters:
range
- other instance- Returns:
- true if this instance overlaps
range
- Throws:
IllegalArgumentException
- ifrange
is null
-
contains
Determine if this key range fully contains the specified key range.- Parameters:
range
- other instance- Returns:
- true if this instance contains
range
- Throws:
IllegalArgumentException
- ifrange
is null
-
contains
Determine if this key range contains the specified key.- Parameters:
key
- key to test- Returns:
- true if this range contains
key
- Throws:
IllegalArgumentException
- ifkey
is null
-
isFull
public boolean isFull()Determine whether this instance contains the full range covering all keys.- Returns:
- true if this instance contains all keys
-
isSingleKey
public boolean isSingleKey()Determine whether this instance contains exactly one key.If so,
getMin()
returns the key.- Returns:
- true if this instance contains exactly one key, otherwise false
-
isPrefixRange
public boolean isPrefixRange()Determine whether this instance contains all keys having some common prefix.If so,
getMin()
returns the prefix.- Returns:
- true if this instance contains all keys having some common prefix, otherwise false
-
isEmpty
public boolean isEmpty()- Returns:
- true if this instance contains no keys
-
prefixedBy
Create a new instance whose minimum and maximum keys are the same as this instance's but with the given byte sequence prepended.- Parameters:
prefix
- key range prefix- Returns:
- this range prefixed by
prefix
- Throws:
IllegalArgumentException
- ifprefix
is null
-
compareTo
Determine if this range is left of, contains, or is right of the given key.- Parameters:
key
- key for comparison- Returns:
- -1 if this range is left of
key
, 0 if this range containskey
, or 1 if this range is right ofkey
, - Throws:
IllegalArgumentException
- ifkey
is null
-
compare
Compare twobyte[]
keys using unsigned lexical ordering, while also accepting null values that represent "positive infinity".- Parameters:
key1
- first key, or null for "positive infinity"key2
- second key, or null for "positive infinity"- Returns:
- -1 if
key1 < key2
, 1 ifkey1 > key2
, or zero ifkey1 = key2
-
empty
Create an empty key range at the specified key.- Parameters:
key
- the minimum and maximum key- Returns:
- the empty key range
[key,key)
- Throws:
IllegalArgumentException
- ifkey
is null
-
equals
-
hashCode
public int hashCode() -
toString
-