520 */
521 public static <T> void fill(List<? super T> list, T obj) {
522 int size = list.size();
523
524 if (size < FILL_THRESHOLD || list instanceof RandomAccess) {
525 for (int i=0; i<size; i++)
526 list.set(i, obj);
527 } else {
528 ListIterator<? super T> itr = list.listIterator();
529 for (int i=0; i<size; i++) {
530 itr.next();
531 itr.set(obj);
532 }
533 }
534 }
535
536 /**
537 * Copies all of the elements from one list into another. After the
538 * operation, the index of each copied element in the destination list
539 * will be identical to its index in the source list. The destination
540 * list must be at least as long as the source list. If it is longer, the
541 * remaining elements in the destination list are unaffected. <p>
542 *
543 * This method runs in linear time.
544 *
545 * @param <T> the class of the objects in the lists
546 * @param dest The destination list.
547 * @param src The source list.
548 * @throws IndexOutOfBoundsException if the destination list is too small
549 * to contain the entire source List.
550 * @throws UnsupportedOperationException if the destination list's
551 * list-iterator does not support the {@code set} operation.
552 */
553 public static <T> void copy(List<? super T> dest, List<? extends T> src) {
554 int srcSize = src.size();
555 if (srcSize > dest.size())
556 throw new IndexOutOfBoundsException("Source does not fit in dest");
557
558 if (srcSize < COPY_THRESHOLD ||
559 (src instanceof RandomAccess && dest instanceof RandomAccess)) {
560 for (int i=0; i<srcSize; i++)
561 dest.set(i, src.get(i));
|
520 */
521 public static <T> void fill(List<? super T> list, T obj) {
522 int size = list.size();
523
524 if (size < FILL_THRESHOLD || list instanceof RandomAccess) {
525 for (int i=0; i<size; i++)
526 list.set(i, obj);
527 } else {
528 ListIterator<? super T> itr = list.listIterator();
529 for (int i=0; i<size; i++) {
530 itr.next();
531 itr.set(obj);
532 }
533 }
534 }
535
536 /**
537 * Copies all of the elements from one list into another. After the
538 * operation, the index of each copied element in the destination list
539 * will be identical to its index in the source list. The destination
540 * list's size must be greater than or equal to the source list's size.
541 * If it is greater, the remaining elements in the destination list are
542 * unaffected. <p>
543 *
544 * This method runs in linear time.
545 *
546 * @param <T> the class of the objects in the lists
547 * @param dest The destination list.
548 * @param src The source list.
549 * @throws IndexOutOfBoundsException if the destination list is too small
550 * to contain the entire source List.
551 * @throws UnsupportedOperationException if the destination list's
552 * list-iterator does not support the {@code set} operation.
553 */
554 public static <T> void copy(List<? super T> dest, List<? extends T> src) {
555 int srcSize = src.size();
556 if (srcSize > dest.size())
557 throw new IndexOutOfBoundsException("Source does not fit in dest");
558
559 if (srcSize < COPY_THRESHOLD ||
560 (src instanceof RandomAccess && dest instanceof RandomAccess)) {
561 for (int i=0; i<srcSize; i++)
562 dest.set(i, src.get(i));
|