3531 return new CopiesList<>(toIndex - fromIndex, element); |
3531 return new CopiesList<>(toIndex - fromIndex, element); |
3532 } |
3532 } |
3533 } |
3533 } |
3534 |
3534 |
3535 /** |
3535 /** |
3536 * Returns a comparator that imposes the reverse of the <i>natural |
3536 * Returns a comparator that imposes the reverse of the <em>natural |
3537 * ordering</i> on a collection of objects that implement the |
3537 * ordering</em> on a collection of objects that implement the |
3538 * <tt>Comparable</tt> interface. (The natural ordering is the ordering |
3538 * {@code Comparable} interface. (The natural ordering is the ordering |
3539 * imposed by the objects' own <tt>compareTo</tt> method.) This enables a |
3539 * imposed by the objects' own {@code compareTo} method.) This enables a |
3540 * simple idiom for sorting (or maintaining) collections (or arrays) of |
3540 * simple idiom for sorting (or maintaining) collections (or arrays) of |
3541 * objects that implement the <tt>Comparable</tt> interface in |
3541 * objects that implement the {@code Comparable} interface in |
3542 * reverse-natural-order. For example, suppose a is an array of |
3542 * reverse-natural-order. For example, suppose {@code a} is an array of |
3543 * strings. Then: <pre> |
3543 * strings. Then: <pre> |
3544 * Arrays.sort(a, Collections.reverseOrder()); |
3544 * Arrays.sort(a, Collections.reverseOrder()); |
3545 * </pre> sorts the array in reverse-lexicographic (alphabetical) order.<p> |
3545 * </pre> sorts the array in reverse-lexicographic (alphabetical) order.<p> |
3546 * |
3546 * |
3547 * The returned comparator is serializable. |
3547 * The returned comparator is serializable. |
3548 * |
3548 * |
3549 * @return a comparator that imposes the reverse of the <i>natural |
3549 * @return A comparator that imposes the reverse of the <i>natural |
3550 * ordering</i> on a collection of objects that implement |
3550 * ordering</i> on a collection of objects that implement |
3551 * the <tt>Comparable</tt> interface. |
3551 * the <tt>Comparable</tt> interface. |
3552 * @see Comparable |
3552 * @see Comparable |
3553 */ |
3553 */ |
3554 public static <T> Comparator<T> reverseOrder() { |
3554 public static <T> Comparator<T> reverseOrder() { |
3573 private Object readResolve() { return reverseOrder(); } |
3573 private Object readResolve() { return reverseOrder(); } |
3574 } |
3574 } |
3575 |
3575 |
3576 /** |
3576 /** |
3577 * Returns a comparator that imposes the reverse ordering of the specified |
3577 * Returns a comparator that imposes the reverse ordering of the specified |
3578 * comparator. If the specified comparator is null, this method is |
3578 * comparator. If the specified comparator is {@code null}, this method is |
3579 * equivalent to {@link #reverseOrder()} (in other words, it returns a |
3579 * equivalent to {@link #reverseOrder()} (in other words, it returns a |
3580 * comparator that imposes the reverse of the <i>natural ordering</i> on a |
3580 * comparator that imposes the reverse of the <em>natural ordering</em> on |
3581 * collection of objects that implement the Comparable interface). |
3581 * a collection of objects that implement the Comparable interface). |
3582 * |
3582 * |
3583 * <p>The returned comparator is serializable (assuming the specified |
3583 * <p>The returned comparator is serializable (assuming the specified |
3584 * comparator is also serializable or null). |
3584 * comparator is also serializable or {@code null}). |
3585 * |
3585 * |
3586 * @return a comparator that imposes the reverse ordering of the |
3586 * @param cmp a comparator who's ordering is to be reversed by the returned |
3587 * specified comparator |
3587 * comparator or {@code null} |
|
3588 * @return A comparator that imposes the reverse ordering of the |
|
3589 * specified comparator. |
3588 * @since 1.5 |
3590 * @since 1.5 |
3589 */ |
3591 */ |
3590 public static <T> Comparator<T> reverseOrder(Comparator<T> cmp) { |
3592 public static <T> Comparator<T> reverseOrder(Comparator<T> cmp) { |
3591 if (cmp == null) |
3593 if (cmp == null) |
3592 return reverseOrder(); |
3594 return reverseOrder(); |