Skip to content

Commit

Permalink
Add convenience/utility method KeyRange.isPrefixRange().
Browse files Browse the repository at this point in the history
  • Loading branch information
archiecobbs committed Jun 29, 2018
1 parent 741c5f8 commit 02d695e
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions permazen-kv/src/main/java/io/permazen/kv/KeyRange.java
Expand Up @@ -193,6 +193,24 @@ public boolean isSingleKey() {
return true;
}

/**
* Determine whether this instance contains all keys having some common prefix.
*
* <p>
* If so, {@link #getMin} returns the prefix.
*
* @return true if this instance contains all keys having some common prefix, otherwise false
*/
public boolean isPrefixRange() {
final byte[] keyAfterPrefix;
try {
keyAfterPrefix = ByteUtil.getKeyAfterPrefix(this.min);
} catch (IllegalArgumentException e) {
return this.max == null; // this.min is either empty or contains all 0xff bytes
}
return Arrays.equals(this.max, keyAfterPrefix);
}

/**
* Determine whether this instance contains zero keys (implying {@link #getMin}{@code == }{@link #getMax}).
*
Expand Down

0 comments on commit 02d695e

Please sign in to comment.