public final class TokenRange extends Object implements Comparable<TokenRange>
unwrap().| Modifier and Type | Method and Description | 
|---|---|
int | 
compareTo(TokenRange other)  | 
boolean | 
contains(Token token)
Checks whether this range contains a given token. 
 | 
boolean | 
equals(Object other)  | 
Token | 
getEnd()
Return the end of the range. 
 | 
Token | 
getStart()
Return the start of the range. 
 | 
int | 
hashCode()  | 
boolean | 
intersects(TokenRange that)
Returns whether this range intersects another one. 
 | 
List<TokenRange> | 
intersectWith(TokenRange that)
Computes the intersection of this range with another one. 
 | 
boolean | 
isEmpty()
Returns whether this range is empty. 
 | 
boolean | 
isWrappedAround()
Returns whether this range wraps around the end of the ring. 
 | 
TokenRange | 
mergeWith(TokenRange that)
Merges this range with another one. 
 | 
List<TokenRange> | 
splitEvenly(int numberOfSplits)
Splits this range into a number of smaller ranges of equal "size" (referring to the number of tokens, not the actual amount of data). 
 | 
String | 
toString()  | 
List<TokenRange> | 
unwrap()
Splits this range into a list of two non-wrapping ranges. 
 | 
public Token getStart()
public Token getEnd()
public List<TokenRange> splitEvenly(int numberOfSplits)
numberOfSplits - the number of splits to create.IllegalArgumentException - if the range is empty or if numberOfSplits < 1.public boolean isEmpty()
public boolean isWrappedAround()
public List<TokenRange> unwrap()
]1,10] unwraps to itself;]10,1] unwraps to ]10,min_token] and ]min_token,1].
 
 List<Row> rows = new ArrayList<Row>();
 for (TokenRange subRange : range.unwrap()) {
     ResultSet rs = session.execute("SELECT * FROM mytable WHERE token(pk) > ? and token(pk) <= ?",
                                    subRange.getStart(), subRange.getEnd());
     rows.addAll(rs.all());
 }
 public boolean intersects(TokenRange that)
]3,5] intersects ]1,4], ]4,5]...]3,5] does not intersect ]1,2], ]2,3], ]5,7]...that - the other range.public List<TokenRange> intersectWith(TokenRange that)
intersects(TokenRange) beforehand.that - the other range.IllegalArgumentException - if the ranges do not intersect.public boolean contains(Token token)
token - the token to check for.range.start < token <= range.end.public TokenRange mergeWith(TokenRange that)
]3,5] with ]4,7] produces ]3,7];]3,5] with ]4,5] produces ]3,5];]3,5] with ]5,8] produces ]3,8];]3,5] with ]6,8] fails.that - the other range.IllegalArgumentException - if the ranges neither intersect nor are adjacent.public int compareTo(TokenRange other)
compareTo in interface Comparable<TokenRange>