替换指定位置的比较器，保持原排序方式

@param index 位置
@param comparator {@link Comparator}
@return this
@exception IndexOutOfBoundsException if index &lt; 0 or index &gt;= size()
432983
public ComparatorChain<E> setComparator(final int index, final Comparator<E> comparator) throws IndexOutOfBoundsException {
		return setComparator(index, comparator, false);
	}
1094464
protected final void rangeCheck (int index, boolean insert)
    {
        if ((index < 0) || (insert ? (index > _size) : (index >= _size))) {
            throw new IndexOutOfBoundsException(
                "Index: " + index + ", Size: " + _size);
        }
    }
159938
@Override
    public void sortAtomContainers(final Comparator<IAtomContainer> comparator) {

        // need to use boxed primitives as we can't customise sorting of int primitives
        Integer[] indexes = new Integer[atomContainerCount];
        for (int i = 0; i < indexes.length; i++)
            indexes[i] = i;

        // proxy the index comparison to the atom container comparator
        Arrays.sort(indexes, new Comparator<Integer>() {

            @Override
            public int compare(Integer o1, Integer o2) {
                return comparator.compare(atomContainers[o1], atomContainers[o2]);
            }
        });

        // copy the original arrays (we could modify in place with swaps but this is cleaner)
        IAtomContainer[] containersTmp = Arrays.copyOf(atomContainers, indexes.length);
        Double[] multipliersTmp = Arrays.copyOf(multipliers, indexes.length);

        // order the arrays based on the order of the indices
        for (int i = 0; i < indexes.length; i++) {
            atomContainers[i] = containersTmp[indexes[i]];
            multipliers[i] = multipliersTmp[indexes[i]];
        }

    }
609229
public static <V> V[] sort(V[] array, Comparator<? super V> comparator) {
        Arrays.sort(array, comparator);
        return array;
    }
41266
public static final <T> void quickSort(List<T> list, Comparator<T> comparator)
    {
        quickSort(list, 0, list.size()-1, comparator);
    }
1002518
public Object remove(int index) {

        //Check that the index is less than size because the getInternal
        //method is being called with index - 1 and its checks will therefore
        //not be useful in this case.
        if (index >= size()) {
            throw new IndexOutOfBoundsException("Index out of bounds: "
                                                + index + " >= " + size());
        }

        //Get the node that is previous to the node being removed
        Node previousToRemove;

        if (index == 0) {
            previousToRemove = first;
        } else {
            previousToRemove = getInternal(index - 1);
        }

        //previousToRemove.next will never be null because of the check above
        //that index < size.
        Node toRemove = previousToRemove.next;

        previousToRemove.next = toRemove.next;

        elementCount--;

        //If they removed at the last valid index, then a the last element
        //was removed, therfore update the last pointer
        if (last == toRemove) {
            last = previousToRemove;
        }

        return toRemove.data;
    }
11232
public boolean get(long index) {
    if (!(index < size))
      throw new IndexOutOfBoundsException();
    return (bytes.readLong(offset(index)) & (1l << (position(index)))) != 0;
  }
14417
public static <T> PositionFactory<Iterable<? extends T>, T> atIndex(final int index) {
        return new PositionFactory<Iterable<? extends T>, T>(index) {

            @Override
            public String toString() {
                return String.format("Element [%s]", index);
            }

            @Override
            protected <P> Type evaluateElementType(Position<P> parentPosition) {
                return TypeUtils.getTypeArguments(parentPosition.getType(), Iterable.class)
                    .get(Iterable.class.getTypeParameters()[0]);
            }
        };
    }
79677
public boolean get(int index) throws ArrayIndexOutOfBoundsException {
        if (index < 0 || index >= length) {
            throw new ArrayIndexOutOfBoundsException(Integer.toString(index));
        }

        return (repn[subscript(index)] & position(index)) != 0;
    }
900131
public StrBuilder deleteCharAt(final int index) {
        if (index < 0 || index >= size) {
            throw new StringIndexOutOfBoundsException(index);
        }
        deleteImpl(index, index + 1, 1);
        return this;
    }
584027
private static void checkNumericIndex(long index) {
		if (index > Integer.MAX_VALUE) {
			throw EvaluationException.create(MSG_INDEX_EXCEEDS_MAXIMUM, index,
					Integer.MAX_VALUE);
		} else if (index < Integer.MIN_VALUE) {
			throw EvaluationException.create(MSG_INDEX_BELOW_MINIMUM, index,
					Integer.MIN_VALUE);
		}
	}
832735
public void sort(@NonNull Comparator<? super T> comparator) {
        final ArrayList<T> copy = new ArrayList<>(mObjects);
        Collections.sort(copy, comparator);
        swap(copy);
    }
1279979
public void add(int index, float e) {
    if (index < 0 || index > size) {
      throw new IndexOutOfBoundsException();
    }
    ensureCapacity(size + 1);
    if (index < size) {
      for (int i = size; i > index; i--) {
        elements[i] = elements[i - 1];
      }
    }
    elements[index] = e;
    size++;
  }
891137
public static void boundsCheck(final byte[] buffer, final long index, final int length)
    {
        final int capacity = buffer.length;
        final long resultingPosition = index + (long)length;
        if (index < 0 || resultingPosition > capacity)
        {
            throw new IndexOutOfBoundsException("index=" + index + " length=" + length + " capacity=" + capacity);
        }
    }
439704
public void sort (Comparator<? super T> comp)
    {
        if (_size > 1) {
            QuickSort.sort(_elements, 0, _size-1, comp);
        }
    }
695023
public double getExpectationAt(int index){
		if(index <0 || index>=expectations.getObservationCount())
			throw new IndexOutOfBoundsException();
		return expectations.getValueAt(index);
	}
1046373
@Override
    public void sortIt(Comparator comp) {
	if (getDimension() > 1) throw new PageRuntimeException("only 1 dimensional arrays can be sorted");
	Collections.sort(list, comp);
    }