use of com.google.cloud.bigtable.data.v2.models.Range.ByteStringRange in project java-bigtable by googleapis.
the class RowSetUtil method getBound.
/**
* Get the bounding range of a {@link RowSet}.
*/
public static ByteStringRange getBound(RowSet rowSet) {
// Find min & max keys
ByteString minKey = null;
ByteString maxKey = null;
for (ByteString key : rowSet.getRowKeysList()) {
if (minKey == null || ByteStringComparator.INSTANCE.compare(minKey, key) > 0) {
minKey = key;
}
if (maxKey == null || ByteStringComparator.INSTANCE.compare(maxKey, key) < 0) {
maxKey = key;
}
}
// Convert min & max keys in start & end points for a range
StartPoint minStartPoint = null;
EndPoint maxEndPoint = null;
if (minKey != null) {
minStartPoint = new StartPoint(minKey, true);
}
if (maxKey != null) {
maxEndPoint = new EndPoint(maxKey, true);
}
// Expand the range using the RowSet ranges
for (RowRange rowRange : rowSet.getRowRangesList()) {
StartPoint currentStartPoint = StartPoint.extract(rowRange);
if (minStartPoint == null || minStartPoint.compareTo(currentStartPoint) > 0) {
minStartPoint = currentStartPoint;
}
EndPoint currentEndpoint = EndPoint.extract(rowRange);
if (maxEndPoint == null || maxEndPoint.compareTo(currentEndpoint) < 0) {
maxEndPoint = currentEndpoint;
}
}
// Build a range using the endpoints
ByteStringRange boundingRange = ByteStringRange.unbounded();
if (minStartPoint != null) {
if (minStartPoint.isClosed) {
boundingRange.startClosed(minStartPoint.value);
} else {
boundingRange.startOpen(minStartPoint.value);
}
}
if (maxEndPoint != null) {
if (maxEndPoint.isClosed) {
boundingRange.endClosed(maxEndPoint.value);
} else {
boundingRange.endOpen(maxEndPoint.value);
}
}
return boundingRange;
}
use of com.google.cloud.bigtable.data.v2.models.Range.ByteStringRange in project java-bigtable by googleapis.
the class RowSetUtilTest method singleClosedOpenRangeBoundTest.
@Test
public void singleClosedOpenRangeBoundTest() {
RowSet rowSet = RowSet.newBuilder().addRowRanges(RowRange.newBuilder().setStartKeyClosed(ByteString.copyFromUtf8("a")).setEndKeyOpen(ByteString.copyFromUtf8("b"))).build();
ByteStringRange actual = RowSetUtil.getBound(rowSet);
assertThat(actual).isEqualTo(ByteStringRange.unbounded().startClosed("a").endOpen("b"));
}
use of com.google.cloud.bigtable.data.v2.models.Range.ByteStringRange in project java-bigtable by googleapis.
the class RowSetUtilTest method multiKeyBoundTest.
@Test
public void multiKeyBoundTest() {
RowSet rowSet = RowSet.newBuilder().addRowKeys(ByteString.copyFromUtf8("a")).addRowKeys(ByteString.copyFromUtf8("d")).build();
ByteStringRange actual = RowSetUtil.getBound(rowSet);
assertThat(actual).isEqualTo(ByteStringRange.unbounded().startClosed("a").endClosed("d"));
}
use of com.google.cloud.bigtable.data.v2.models.Range.ByteStringRange in project java-bigtable by googleapis.
the class RowSetUtilTest method singleOpenOpenRangeBoundTest.
@Test
public void singleOpenOpenRangeBoundTest() {
RowSet rowSet = RowSet.newBuilder().addRowRanges(RowRange.newBuilder().setStartKeyOpen(ByteString.copyFromUtf8("a")).setEndKeyOpen(ByteString.copyFromUtf8("b"))).build();
ByteStringRange actual = RowSetUtil.getBound(rowSet);
assertThat(actual).isEqualTo(ByteStringRange.unbounded().startOpen("a").endOpen("b"));
}
use of com.google.cloud.bigtable.data.v2.models.Range.ByteStringRange in project java-bigtable by googleapis.
the class RangeTest method byteStringEqualsTest.
@Test
public void byteStringEqualsTest() {
ByteStringRange r1 = ByteStringRange.create("a", "c");
ByteStringRange r2 = ByteStringRange.create("a", "c");
ByteStringRange r3 = ByteStringRange.create("q", "z");
assertThat(r1).isEqualTo(r2);
assertThat(r2).isEqualTo(r1);
assertThat(r1).isNotEqualTo(r3);
}
Aggregations