コード例 #1
0
 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;
 }
コード例 #2
0
    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;
    }
コード例 #3
0
    /**
     * 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;
    }
コード例 #4
0
      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);
      }
コード例 #5
0
  /**
   * 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});
  }