public boolean intersects( List<ByteBuffer> minClusteringValues, List<ByteBuffer> maxClusteringValues) { for (Slice slice : this) { if (slice.intersects(comparator, minClusteringValues, maxClusteringValues)) return true; } return false; }
public Builder add(Slice slice) { assert comparator.compare(slice.start(), slice.end()) <= 0; if (slices.size() > 0 && comparator.compare(slices.get(slices.size() - 1).end(), slice.start()) > 0) needsNormalizing = true; slices.add(slice); return this; }
public boolean selects(Clustering clustering) { for (int i = 0; i < slices.length; i++) { Slice slice = slices[i]; if (comparator.compare(clustering, slice.start()) < 0) return false; if (comparator.compare(clustering, slice.end()) <= 0) return true; } return false; }
private Slices forReversePaging( ClusteringComparator comparator, Clustering lastReturned, boolean inclusive) { for (int i = slices.length - 1; i >= 0; i--) { Slice slice = slices[i]; Slice newSlice = slice.forPaging(comparator, lastReturned, inclusive, true); if (newSlice == null) continue; if (slice == newSlice && i == slices.length - 1) return this; ArrayBackedSlices newSlices = new ArrayBackedSlices(comparator, Arrays.copyOfRange(slices, 0, i + 1)); newSlices.slices[i] = newSlice; return newSlices; } return Slices.NONE; }
private Slices forForwardPaging( ClusteringComparator comparator, Clustering lastReturned, boolean inclusive) { for (int i = 0; i < slices.length; i++) { Slice slice = slices[i]; Slice newSlice = slice.forPaging(comparator, lastReturned, inclusive, false); if (newSlice == null) continue; if (slice == newSlice && i == 0) return this; ArrayBackedSlices newSlices = new ArrayBackedSlices(comparator, Arrays.copyOfRange(slices, i, slices.length)); newSlices.slices[0] = newSlice; return newSlices; } return Slices.NONE; }
public static ComponentOfSlice fromSlice(int component, Slice slice) { Slice.Bound start = slice.start(); Slice.Bound end = slice.end(); if (component >= start.size() && component >= end.size()) return null; boolean startInclusive = true, endInclusive = true; ByteBuffer startValue = null, endValue = null; if (component < start.size()) { startInclusive = start.isInclusive(); startValue = start.get(component); } if (component < end.size()) { endInclusive = end.isInclusive(); endValue = end.get(component); } return new ComponentOfSlice(startInclusive, startValue, endInclusive, endValue); }
/** * Given an array of slices (potentially overlapping and in any order) and return an equivalent * array of non-overlapping slices in clustering order. * * @param slices an array of slices. This may be modified by this method. * @return the smallest possible array of non-overlapping slices in clustering order. If the * original slices are already non-overlapping and in comparator order, this may or may not * return the provided slices directly. */ private List<Slice> normalize(List<Slice> slices) { if (slices.size() <= 1) return slices; Collections.sort( slices, new Comparator<Slice>() { @Override public int compare(Slice s1, Slice s2) { int c = comparator.compare(s1.start(), s2.start()); if (c != 0) return c; return comparator.compare(s1.end(), s2.end()); } }); List<Slice> slicesCopy = new ArrayList<>(slices.size()); Slice last = slices.get(0); for (int i = 1; i < slices.size(); i++) { Slice s2 = slices.get(i); boolean includesStart = last.includes(comparator, s2.start()); boolean includesFinish = last.includes(comparator, s2.end()); if (includesStart && includesFinish) continue; if (!includesStart && !includesFinish) { slicesCopy.add(last); last = s2; continue; } if (includesStart) { last = Slice.make(last.start(), s2.end()); continue; } assert !includesFinish; } slicesCopy.add(last); return slicesCopy; }
/** * Creates a {@code Slices} object that contains a single slice. * * @param comparator the comparator for the table {@code slice} is a slice of. * @param slice the single slice that the return object should contains. * @return the newly created {@code Slices} object. */ public static Slices with(ClusteringComparator comparator, Slice slice) { if (slice.start() == Slice.Bound.BOTTOM && slice.end() == Slice.Bound.TOP) return Slices.ALL; assert comparator.compare(slice.start(), slice.end()) <= 0; return new ArrayBackedSlices(comparator, new Slice[] {slice}); }
public Builder add(Slice.Bound start, Slice.Bound end) { return add(Slice.make(start, end)); }