/[classpath]/classpath/java/util/AbstractList.java
ViewVC logotype

Diff of /classpath/java/util/AbstractList.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.21.2.3 by tromey, Wed Jan 12 01:12:48 2005 UTC revision 1.21.2.4 by gnu_andrew, Thu Jan 13 22:40:39 2005 UTC
# Line 87  public abstract class AbstractList<E> Line 87  public abstract class AbstractList<E>
87     * <code>add(int, Object)</code> and <code>remove(int)</code> methods.     * <code>add(int, Object)</code> and <code>remove(int)</code> methods.
88     * Otherwise, this field may be ignored.     * Otherwise, this field may be ignored.
89     */     */
90    protected int modCount;    protected transient int modCount;
91    
92    /**    /**
93     * The main constructor, for use by subclasses.     * The main constructor, for use by subclasses.
# Line 310  while (i.hasNext()) Line 310  while (i.hasNext())
310        private int knownMod = modCount;        private int knownMod = modCount;
311    
312        // This will get inlined, since it is private.        // This will get inlined, since it is private.
313          /**
314           * Checks for modifications made to the list from
315           * elsewhere while iteration is in progress.
316           *
317           * @throws ConcurrentModificationException if the
318           *         list has been modified elsewhere.
319           */
320        private void checkMod()        private void checkMod()
321        {        {
322          if (knownMod != modCount)          if (knownMod != modCount)
323            throw new ConcurrentModificationException();            throw new ConcurrentModificationException();
324        }        }
325    
326          /**
327           * Tests to see if there are any more objects to
328           * return.
329           *
330           * @return True if the end of the list has not yet been
331           *         reached.
332           * @throws ConcurrentModificationException if the
333           *         list has been modified elsewhere.
334           */
335        public boolean hasNext()        public boolean hasNext()
336        {        {
337          checkMod();          checkMod();
338          return pos < size;          return pos < size;
339        }        }
340    
341          /**
342           * Retrieves the next object from the list.
343           *
344           * @return The next object.
345           * @throws NoSuchElementException if there are
346           *         no more objects to retrieve.
347           * @throws ConcurrentModificationException if the
348           *         list has been modified elsewhere.
349           */
350        public E next()        public E next()
351        {        {
352          checkMod();          checkMod();
# Line 331  while (i.hasNext()) Line 356  while (i.hasNext())
356          return get(pos++);          return get(pos++);
357        }        }
358    
359          /**
360           * Removes the last object retrieved by <code>next()</code>
361           * from the list, if the list supports object removal.
362           *
363           * @throws ConcurrentModificationException if the list
364           *         has been modified elsewhere.
365           * @throws IllegalStateException if the iterator is positioned
366           *         before the start of the list or the last object has already
367           *         been removed.
368           * @throws UnsupportedOperationException if the list does
369           *         not support removing elements.
370           */
371        public void remove()        public void remove()
372        {        {
373          checkMod();          checkMod();
# Line 407  while (i.hasNext()) Line 444  while (i.hasNext())
444        private int size = size();        private int size = size();
445    
446        // This will get inlined, since it is private.        // This will get inlined, since it is private.
447          /**
448           * Checks for modifications made to the list from
449           * elsewhere while iteration is in progress.
450           *
451           * @throws ConcurrentModificationException if the
452           *         list has been modified elsewhere.
453           */
454        private void checkMod()        private void checkMod()
455        {        {
456          if (knownMod != modCount)          if (knownMod != modCount)
457            throw new ConcurrentModificationException();            throw new ConcurrentModificationException();
458        }        }
459    
460          /**
461           * Tests to see if there are any more objects to
462           * return.
463           *
464           * @return True if the end of the list has not yet been
465           *         reached.
466           * @throws ConcurrentModificationException if the
467           *         list has been modified elsewhere.
468           */
469        public boolean hasNext()        public boolean hasNext()
470        {        {
471          checkMod();          checkMod();
472          return position < size;          return position < size;
473        }        }
474    
475          /**
476           * Tests to see if there are objects prior to the
477           * current position in the list.
478           *
479           * @return True if objects exist prior to the current
480           *         position of the iterator.
481           * @throws ConcurrentModificationException if the
482           *         list has been modified elsewhere.
483           */
484        public boolean hasPrevious()        public boolean hasPrevious()
485        {        {
486          checkMod();          checkMod();
487          return position > 0;          return position > 0;
488        }        }
489    
490          /**
491           * Retrieves the next object from the list.
492           *
493           * @return The next object.
494           * @throws NoSuchElementException if there are no
495           *         more objects to retrieve.
496           * @throws ConcurrentModificationException if the
497           *         list has been modified elsewhere.
498           */
499        public E next()        public E next()
500        {        {
501          checkMod();          checkMod();
# Line 434  while (i.hasNext()) Line 505  while (i.hasNext())
505          return get(position++);          return get(position++);
506        }        }
507    
508          /**
509           * Retrieves the previous object from the list.
510           *
511           * @return The next object.
512           * @throws NoSuchElementException if there are no
513           *         previous objects to retrieve.
514           * @throws ConcurrentModificationException if the
515           *         list has been modified elsewhere.
516           */
517        public E previous()        public E previous()
518        {        {
519          checkMod();          checkMod();
# Line 443  while (i.hasNext()) Line 523  while (i.hasNext())
523          return get(lastReturned);          return get(lastReturned);
524        }        }
525    
526          /**
527           * Returns the index of the next element in the
528           * list, which will be retrieved by <code>next()</code>
529           *
530           * @return The index of the next element.
531           * @throws ConcurrentModificationException if the list
532           *         has been modified elsewhere.
533           */
534        public int nextIndex()        public int nextIndex()
535        {        {
536          checkMod();          checkMod();
537          return position;          return position;
538        }        }
539    
540          /**
541           * Returns the index of the previous element in the
542           * list, which will be retrieved by <code>previous()</code>
543           *
544           * @return The index of the previous element.
545           * @throws ConcurrentModificationException if the list
546           *         has been modified elsewhere.
547           */
548        public int previousIndex()        public int previousIndex()
549        {        {
550          checkMod();          checkMod();
551          return position - 1;          return position - 1;
552        }        }
553    
554         /**
555          * Removes the last object retrieved by <code>next()</code>
556          * or <code>previous()</code> from the list, if the list
557          * supports object removal.
558          *
559          * @throws IllegalStateException if the iterator is positioned
560          *         before the start of the list or the last object has already
561          *         been removed.
562          * @throws UnsupportedOperationException if the list does
563          *         not support removing elements.
564          * @throws ConcurrentModificationException if the list
565          *         has been modified elsewhere.
566          */
567        public void remove()        public void remove()
568        {        {
569          checkMod();          checkMod();
# Line 467  while (i.hasNext()) Line 576  while (i.hasNext())
576          knownMod = modCount;          knownMod = modCount;
577        }        }
578    
579         /**
580          * Replaces the last object retrieved by <code>next()</code>
581          * or <code>previous</code> with o, if the list supports object
582          * replacement and an add or remove operation has not already
583          * been performed.
584          *
585          * @throws IllegalStateException if the iterator is positioned
586          *         before the start of the list or the last object has already
587          *         been removed.
588          * @throws UnsupportedOperationException if the list doesn't support
589          *         the addition or removal of elements.
590          * @throws ClassCastException if the type of o is not a valid type
591          *         for this list.
592          * @throws IllegalArgumentException if something else related to o
593          *         prevents its addition.
594          * @throws ConcurrentModificationException if the list
595          *         has been modified elsewhere.
596          */
597        public void set(E o)        public void set(E o)
598        {        {
599          checkMod();          checkMod();
# Line 475  while (i.hasNext()) Line 602  while (i.hasNext())
602          AbstractList.this.set(lastReturned, o);          AbstractList.this.set(lastReturned, o);
603        }        }
604    
605          /**
606           * Adds the supplied object before the element that would be returned
607           * by a call to <code>next()</code>, if the list supports addition.
608           *
609           * @param o The object to add to the list.
610           * @throws UnsupportedOperationException if the list doesn't support
611           *         the addition of new elements.
612           * @throws ClassCastException if the type of o is not a valid type
613           *         for this list.
614           * @throws IllegalArgumentException if something else related to o
615           *         prevents its addition.
616           * @throws ConcurrentModificationException if the list
617           *         has been modified elsewhere.
618           */
619        public void add(E o)        public void add(E o)
620        {        {
621          checkMod();          checkMod();
# Line 521  while (i.hasNext()) Line 662  while (i.hasNext())
662     *     *
663     * @param fromIndex the index, inclusive, to remove from.     * @param fromIndex the index, inclusive, to remove from.
664     * @param toIndex the index, exclusive, to remove to.     * @param toIndex the index, exclusive, to remove to.
665       * @throws UnsupportedOperationException if the list does
666       *         not support removing elements.
667     */     */
668    protected void removeRange(int fromIndex, int toIndex)    protected void removeRange(int fromIndex, int toIndex)
669    {    {
# Line 665  class SubList<E> extends AbstractList<E> Line 808  class SubList<E> extends AbstractList<E>
808     * it is not, an exception is thrown.     * it is not, an exception is thrown.
809     *     *
810     * @param index the value to check     * @param index the value to check
811     * @throws IndexOutOfBoundsException if the value is out of range     * @throws IndexOutOfBoundsException if index &lt; 0 || index &gt; size()
812     */     */
813    // This will get inlined, since it is private.    // This will get inlined, since it is private.
814    private void checkBoundsInclusive(int index)    private void checkBoundsInclusive(int index)
# Line 680  class SubList<E> extends AbstractList<E> Line 823  class SubList<E> extends AbstractList<E>
823     * (exclusive). If it is not, an exception is thrown.     * (exclusive). If it is not, an exception is thrown.
824     *     *
825     * @param index the value to check     * @param index the value to check
826     * @throws IndexOutOfBoundsException if the value is out of range     * @throws IndexOutOfBoundsException if index &lt; 0 || index &gt;= size()
827     */     */
828    // This will get inlined, since it is private.    // This will get inlined, since it is private.
829    private void checkBoundsExclusive(int index)    private void checkBoundsExclusive(int index)
# Line 694  class SubList<E> extends AbstractList<E> Line 837  class SubList<E> extends AbstractList<E>
837     * Specified by AbstractList.subList to return the private field size.     * Specified by AbstractList.subList to return the private field size.
838     *     *
839     * @return the sublist size     * @return the sublist size
840       * @throws ConcurrentModificationException if the backing list has been
841       *         modified externally to this sublist
842     */     */
843    public int size()    public int size()
844    {    {
# Line 707  class SubList<E> extends AbstractList<E> Line 852  class SubList<E> extends AbstractList<E>
852     * @param index the location to modify     * @param index the location to modify
853     * @param o the new value     * @param o the new value
854     * @return the old value     * @return the old value
855       * @throws ConcurrentModificationException if the backing list has been
856       *         modified externally to this sublist
857       * @throws UnsupportedOperationException if the backing list does not
858       *         support the set operation
859       * @throws IndexOutOfBoundsException if index &lt; 0 || index &gt;= size()
860       * @throws ClassCastException if o cannot be added to the backing list due
861       *         to its type
862       * @throws IllegalArgumentException if o cannot be added to the backing list
863       *         for some other reason
864     */     */
865    public E set(int index, E o)    public E set(int index, E o)
866    {    {
# Line 720  class SubList<E> extends AbstractList<E> Line 874  class SubList<E> extends AbstractList<E>
874     *     *
875     * @param index the location to get from     * @param index the location to get from
876     * @return the object at that location     * @return the object at that location
877       * @throws ConcurrentModificationException if the backing list has been
878       *         modified externally to this sublist
879       * @throws IndexOutOfBoundsException if index &lt; 0 || index &gt;= size()
880     */     */
881    public E get(int index)    public E get(int index)
882    {    {
# Line 733  class SubList<E> extends AbstractList<E> Line 890  class SubList<E> extends AbstractList<E>
890     *     *
891     * @param index the index to insert at     * @param index the index to insert at
892     * @param o the object to add     * @param o the object to add
893       * @throws ConcurrentModificationException if the backing list has been
894       *         modified externally to this sublist
895       * @throws IndexOutOfBoundsException if index &lt; 0 || index &gt; size()
896       * @throws UnsupportedOperationException if the backing list does not
897       *         support the add operation.
898       * @throws ClassCastException if o cannot be added to the backing list due
899       *         to its type.
900       * @throws IllegalArgumentException if o cannot be added to the backing
901       *         list for some other reason.
902     */     */
903    public void add(int index, E o)    public void add(int index, E o)
904    {    {
# Line 748  class SubList<E> extends AbstractList<E> Line 914  class SubList<E> extends AbstractList<E>
914     *     *
915     * @param index the index to remove     * @param index the index to remove
916     * @return the removed object     * @return the removed object
917       * @throws ConcurrentModificationException if the backing list has been
918       *         modified externally to this sublist
919       * @throws IndexOutOfBoundsException if index &lt; 0 || index &gt;= size()
920       * @throws UnsupportedOperationException if the backing list does not
921       *         support the remove operation
922     */     */
923    public E remove(int index)    public E remove(int index)
924    {    {
# Line 766  class SubList<E> extends AbstractList<E> Line 937  class SubList<E> extends AbstractList<E>
937     *     *
938     * @param fromIndex the lower bound, inclusive     * @param fromIndex the lower bound, inclusive
939     * @param toIndex the upper bound, exclusive     * @param toIndex the upper bound, exclusive
940       * @throws ConcurrentModificationException if the backing list has been
941       *         modified externally to this sublist
942       * @throws UnsupportedOperationException if the backing list does
943       *         not support removing elements.
944     */     */
945    protected void removeRange(int fromIndex, int toIndex)    protected void removeRange(int fromIndex, int toIndex)
946    {    {
# Line 782  class SubList<E> extends AbstractList<E> Line 957  class SubList<E> extends AbstractList<E>
957     * @param index the location to insert at     * @param index the location to insert at
958     * @param c the collection to insert     * @param c the collection to insert
959     * @return true if this list was modified, in other words, c is non-empty     * @return true if this list was modified, in other words, c is non-empty
960       * @throws ConcurrentModificationException if the backing list has been
961       *         modified externally to this sublist
962       * @throws IndexOutOfBoundsException if index &lt; 0 || index &gt; size()
963       * @throws UnsupportedOperationException if this list does not support the
964       *         addAll operation
965       * @throws ClassCastException if some element of c cannot be added to this
966       *         list due to its type
967       * @throws IllegalArgumentException if some element of c cannot be added
968       *         to this list for some other reason
969       * @throws NullPointerException if the specified collection is null
970     */     */
971    public boolean addAll(int index, Collection<? extends E> c)    public boolean addAll(int index, Collection<? extends E> c)
972    {    {
# Line 799  class SubList<E> extends AbstractList<E> Line 984  class SubList<E> extends AbstractList<E>
984     *     *
985     * @param c the collection to insert     * @param c the collection to insert
986     * @return true if this list was modified, in other words, c is non-empty     * @return true if this list was modified, in other words, c is non-empty
987       * @throws ConcurrentModificationException if the backing list has been
988       *         modified externally to this sublist
989       * @throws UnsupportedOperationException if this list does not support the
990       *         addAll operation
991       * @throws ClassCastException if some element of c cannot be added to this
992       *         list due to its type
993       * @throws IllegalArgumentException if some element of c cannot be added
994       *         to this list for some other reason
995       * @throws NullPointerException if the specified collection is null
996     */     */
997    public boolean addAll(Collection<? extends E> c)    public boolean addAll(Collection<? extends E> c)
998    {    {
# Line 821  class SubList<E> extends AbstractList<E> Line 1015  class SubList<E> extends AbstractList<E>
1015     *     *
1016     * @param index the start location of the iterator     * @param index the start location of the iterator
1017     * @return a list iterator over the sublist     * @return a list iterator over the sublist
1018       * @throws ConcurrentModificationException if the backing list has been
1019       *         modified externally to this sublist
1020       * @throws IndexOutOfBoundsException if the value is out of range
1021     */     */
1022    public ListIterator<E> listIterator(final int index)    public ListIterator<E> listIterator(final int index)
1023    {    {
# Line 833  class SubList<E> extends AbstractList<E> Line 1030  class SubList<E> extends AbstractList<E>
1030          = backingList.listIterator(index + offset);          = backingList.listIterator(index + offset);
1031        private int position = index;        private int position = index;
1032    
1033          /**
1034           * Tests to see if there are any more objects to
1035           * return.
1036           *
1037           * @return True if the end of the list has not yet been
1038           *         reached.
1039           * @throws ConcurrentModificationException if the
1040           *         list has been modified elsewhere.
1041           */
1042        public boolean hasNext()        public boolean hasNext()
1043        {        {
1044          checkMod();          checkMod();
1045          return position < size;          return position < size;
1046        }        }
1047    
1048          /**
1049           * Tests to see if there are objects prior to the
1050           * current position in the list.
1051           *
1052           * @return True if objects exist prior to the current
1053           *         position of the iterator.
1054           * @throws ConcurrentModificationException if the
1055           *         list has been modified elsewhere.
1056           */
1057        public boolean hasPrevious()        public boolean hasPrevious()
1058        {        {
1059          checkMod();          checkMod();
1060          return position > 0;          return position > 0;
1061        }        }
1062    
1063          /**
1064           * Retrieves the next object from the list.
1065           *
1066           * @return The next object.
1067           * @throws NoSuchElementException if there are no
1068           *         more objects to retrieve.
1069           * @throws ConcurrentModificationException if the
1070           *         list has been modified elsewhere.
1071           */
1072        public E next()        public E next()
1073        {        {
1074          if (position == size)          if (position == size)
# Line 853  class SubList<E> extends AbstractList<E> Line 1077  class SubList<E> extends AbstractList<E>
1077          return i.next();          return i.next();
1078        }        }
1079    
1080          /**
1081           * Retrieves the previous object from the list.
1082           *
1083           * @return The next object.
1084           * @throws NoSuchElementException if there are no
1085           *         previous objects to retrieve.
1086           * @throws ConcurrentModificationException if the
1087           *         list has been modified elsewhere.
1088           */
1089        public E previous()        public E previous()
1090        {        {
1091          if (position == 0)          if (position == 0)
# Line 861  class SubList<E> extends AbstractList<E> Line 1094  class SubList<E> extends AbstractList<E>
1094          return i.previous();          return i.previous();
1095        }        }
1096    
1097          /**
1098           * Returns the index of the next element in the
1099           * list, which will be retrieved by <code>next()</code>
1100           *
1101           * @return The index of the next element.
1102           * @throws ConcurrentModificationException if the
1103           *         list has been modified elsewhere.
1104           */
1105        public int nextIndex()        public int nextIndex()
1106        {        {
1107          return i.nextIndex() - offset;          return i.nextIndex() - offset;
1108        }        }
1109    
1110          /**
1111           * Returns the index of the previous element in the
1112           * list, which will be retrieved by <code>previous()</code>
1113           *
1114           * @return The index of the previous element.
1115           * @throws ConcurrentModificationException if the
1116           *         list has been modified elsewhere.
1117           */
1118        public int previousIndex()        public int previousIndex()
1119        {        {
1120          return i.previousIndex() - offset;          return i.previousIndex() - offset;
1121        }        }
1122    
1123          /**
1124           * Removes the last object retrieved by <code>next()</code>
1125           * from the list, if the list supports object removal.
1126           *
1127           * @throws IllegalStateException if the iterator is positioned
1128           *         before the start of the list or the last object has already
1129           *         been removed.
1130           * @throws UnsupportedOperationException if the list does
1131           *         not support removing elements.
1132           */
1133        public void remove()        public void remove()
1134        {        {
1135          i.remove();          i.remove();
# Line 879  class SubList<E> extends AbstractList<E> Line 1138  class SubList<E> extends AbstractList<E>
1138          modCount = backingList.modCount;          modCount = backingList.modCount;
1139        }        }
1140    
1141    
1142         /**
1143          * Replaces the last object retrieved by <code>next()</code>
1144          * or <code>previous</code> with o, if the list supports object
1145          * replacement and an add or remove operation has not already
1146          * been performed.
1147          *
1148          * @throws IllegalStateException if the iterator is positioned
1149          *         before the start of the list or the last object has already
1150          *         been removed.
1151          * @throws UnsupportedOperationException if the list doesn't support
1152          *         the addition or removal of elements.
1153          * @throws ClassCastException if the type of o is not a valid type
1154          *         for this list.
1155          * @throws IllegalArgumentException if something else related to o
1156          *         prevents its addition.
1157          * @throws ConcurrentModificationException if the list
1158          *         has been modified elsewhere.
1159          */
1160        public void set(E o)        public void set(E o)
1161        {        {
1162          i.set(o);          i.set(o);
1163        }        }
1164    
1165          /**
1166           * Adds the supplied object before the element that would be returned
1167           * by a call to <code>next()</code>, if the list supports addition.
1168           *
1169           * @param o The object to add to the list.
1170           * @throws UnsupportedOperationException if the list doesn't support
1171           *         the addition of new elements.
1172           * @throws ClassCastException if the type of o is not a valid type
1173           *         for this list.
1174           * @throws IllegalArgumentException if something else related to o
1175           *         prevents its addition.
1176           * @throws ConcurrentModificationException if the list
1177           *         has been modified elsewhere.
1178           */
1179        public void add(E o)        public void add(E o)
1180        {        {
1181          i.add(o);          i.add(o);

Legend:
Removed from v.1.21.2.3  
changed lines
  Added in v.1.21.2.4

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26