Transforms a Range predicate to a closed range on this partitioner's upper
bounds. Handles edge cases correctly.

@param range a Range of Strings
@return a Range of upper-bound Strings
973651
private Range<String> transformClosed(Range<String> range) {
    if (range.hasLowerBound()) {
      String lower = range.lowerEndpoint();
      // the special case, (a, _] and apply(a) == a is handled by skipping a
      String afterLower = domain.next(apply(lower));
      if (afterLower != null) {
        if (range.hasUpperBound()) {
          String upper = range.upperEndpoint();
          String upperImage = apply(upper);
          // meaning: at the endpoint
          if (upper.equals(upperImage) && range.isUpperBoundClosed()) {
            // include upper
            return Ranges.closed(afterLower, upperImage);
          } else {
            String beforeUpper = domain.previous(upperImage);
            if (afterLower.compareTo(beforeUpper) <= 0) {
              return Ranges.closed(afterLower, beforeUpper);
            }
          }
        } else {
          return Ranges.atLeast(afterLower);
        }
      }
    } else if (range.hasUpperBound()) {
      String upper = range.upperEndpoint();
      String upperImage = apply(upper);
      if (upper.equals(upperImage) && range.isUpperBoundClosed()) {
        // include upper
        return Ranges.atMost(upperImage);
      } else {
        String beforeUpper = domain.previous(upperImage);
        if (beforeUpper != null) {
          return Ranges.atMost(beforeUpper);
        }
      }
    }
    return null;
  }
1304338
public static Range<RowPosition> makeRowRange(Token left, Token right, IPartitioner partitioner)
    {
        return new Range<RowPosition>(left.maxKeyBound(partitioner), right.maxKeyBound(partitioner), partitioner);
    }
880483
public boolean IsOverlapping(DoubleRange range) {
        return ((isInside(range.min)) || (isInside(range.max)) ||
                (range.isInside(min)) || (range.isInside(max)));
    }
996141
public static <C extends Comparable> RangeTree<C> create(final Iterable<Range<C>> ranges) {
        return new CenteredRangeTree<C>(ranges);
    }
555636
public boolean hasIntersection(final Range range) {
		return Math.max(this.start, range.start) <= Math.min(this.end, range.end);
	}
812542
private Range<RowKeyWrapper> rowRangeToRange(RowRange btRange) {
    final BoundType startBound;
    final ByteString startKey;

    switch (btRange.getStartKeyCase()) {
      case START_KEY_OPEN:
        startBound = BoundType.OPEN;
        startKey = btRange.getStartKeyOpen();
        break;
      case START_KEY_CLOSED:
        startBound = BoundType.CLOSED;
        startKey = btRange.getStartKeyClosed();
        break;
      case STARTKEY_NOT_SET:
        startBound = BoundType.CLOSED;
        startKey = ByteString.EMPTY;
        break;
      default:
        throw new IllegalArgumentException("Unexpected start key case: " +
            btRange.getStartKeyCase());
    }

    final BoundType endBound;
    final ByteString endKey;
    switch (btRange.getEndKeyCase()) {
      case END_KEY_OPEN:
        endBound = BoundType.OPEN;
        endKey = btRange.getEndKeyOpen();
        break;
      case END_KEY_CLOSED:
        endBound = BoundType.CLOSED;
        endKey = btRange.getEndKeyClosed();
        break;
      case ENDKEY_NOT_SET:
        endBound = BoundType.OPEN;
        endKey = ByteString.EMPTY;
        break;
      default:
        throw new IllegalArgumentException("Unexpected end key case: " + btRange.getEndKeyCase());
    }

    return boundedRange(startBound, startKey, endBound, endKey);
  }
201406
public Range intersection(final Range range) {
		int c0 = Math.max(this.start, range.start);
		int c1 = Math.min(this.end, range.end);
		return c0 <= c1 ? new Range(c0, c1) : null;
	}
1276915
private static <T extends RingPosition<T>> List<Range<T>> deoverlap(List<Range<T>> ranges)
    {
        if (ranges.isEmpty())
            return ranges;

        List<Range<T>> output = new ArrayList<Range<T>>();

        Iterator<Range<T>> iter = ranges.iterator();
        Range<T> current = iter.next();

        @SuppressWarnings("unchecked")
        T min = (T) current.partitioner.minValue(current.left.getClass());
        while (iter.hasNext())
        {
            // If current goes to the end of the ring, we're done
            if (current.right.equals(min))
            {
                // If one range is the full range, we return only that
                if (current.left.equals(min))
                    return Collections.<Range<T>>singletonList(current);

                output.add(new Range<T>(current.left, min));
                return output;
            }

            Range<T> next = iter.next();

            // if next left is equal to current right, we do not intersect per se, but replacing (A, B] and (B, C] by (A, C] is
            // legit, and since this avoid special casing and will result in more "optimal" ranges, we do the transformation
            if (next.left.compareTo(current.right) <= 0)
            {
                // We do overlap
                // (we've handled current.right.equals(min) already)
                if (next.right.equals(min) || current.right.compareTo(next.right) < 0)
                    current = new Range<T>(current.left, next.right);
            }
            else
            {
                output.add(current);
                current = next;
            }
        }
        output.add(current);
        return output;
    }
759958
public Range<App> listApps(String range) {
        return connection.execute(new AppList(range), apiKey);
    }
1034911
public Range convertToSeq2Range(Range rangeInSeq1) {
        int from = aabs(convertToSeq2Position(rangeInSeq1.getFrom()));
        int to = aabs(convertToSeq2Position(rangeInSeq1.getTo()));

        if (from == -1 || to == -1)
            return null;

        return new Range(from, to);
    }
653139
public Range getAbsoluteRangeFor(Range relativeRange) {
        int from = convertBoundaryToAbsolutePosition(relativeRange.getFrom()),
                to = convertBoundaryToAbsolutePosition(relativeRange.getTo());
        return new Range(from, to);
    }
207395
public static LongStream rangeValues(Protos.Value.Range range) {
		checkNotNull(range);
		return LongStream.rangeClosed(range.getBegin(), range.getEnd());
	}
161870
@SuppressWarnings("unchecked")
    public static List<Long> getAt(long[] array, ObjectRange range) {
        return primitiveArrayGet(array, range);
    }
449399
public void setRange(String range) {
        String single = range.trim();
        int hyphenIndex = range.indexOf('-');

        if (hyphenIndex > 0) {
            this.start = rangeSingle(range.substring(0, hyphenIndex));
            this.end = rangeSingle(range.substring(hyphenIndex + 1));
        } else {
            int number = rangeSingle(range);
            if (number >= 0) { // first n attributes
                this.start = 0;
                this.end = number;
            } else { // last n attributes
                this.start = this.upperLimit + number > 0 ? this.upperLimit + number : 0;
                this.end = this.upperLimit - 1;
            }
        }
    }
443347
public static List<Long> ends(final Iterable<Range<Long>> ranges) {
        List<Long> ends = new ArrayList<Long>();
        for (Range<Long> range : ranges) {
            checkClosedOpen(range);
            ends.add(range.upperEndpoint());
        }
        return ends;
    }
1258598
public List<String> range(int start,int end){
        try {    		
        	return new ArrayList<>(getJedisCommands(groupName).zrange(key, start, end));
    	} finally{
			getJedisProvider(groupName).release();
		}
	}
632945
public MultiChangeBuilder<PS, SEG, S> deleteText(IndexRange range) {
        return deleteText(range.getStart(), range.getEnd());
    }