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

Diff of /classpath/java/util/Vector.java

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

revision 1.14 by ericb, Mon Oct 22 03:46:07 2001 UTC revision 1.15 by ericb, Mon Oct 22 05:48:01 2001 UTC
# Line 354  public class Vector extends AbstractList Line 354  public class Vector extends AbstractList
354     */     */
355    public synchronized int lastIndexOf(Object e, int index)    public synchronized int lastIndexOf(Object e, int index)
356    {    {
357      if (index >= elementCount)      checkBoundExclusive(index);
       throw new IndexOutOfBoundsException(index + " >= " + elementCount);  
   
358      for (int i = index; i >= 0; i--)      for (int i = index; i >= 0; i--)
359        if (equals(e, elementData[i]))        if (equals(e, elementData[i]))
360          return i;          return i;
# Line 373  public class Vector extends AbstractList Line 371  public class Vector extends AbstractList
371     */     */
372    public synchronized Object elementAt(int index)    public synchronized Object elementAt(int index)
373    {    {
374      // Within the bounds of this Vector does not necessarily mean within      checkBoundExclusive(index);
     // the bounds of the internal array.  
     if (index >= elementCount)  
       throw new ArrayIndexOutOfBoundsException(index + " >= " + elementCount);  
   
375      return elementData[index];      return elementData[index];
376    }    }
377    
# Line 446  public class Vector extends AbstractList Line 440  public class Vector extends AbstractList
440     */     */
441    public synchronized void insertElementAt(Object obj, int index)    public synchronized void insertElementAt(Object obj, int index)
442    {    {
443      if (index > elementCount)      checkBoundInclusive(index);
       throw new ArrayIndexOutOfBoundsException(index + " > " + elementCount);  
   
444      if (elementCount == elementData.length)      if (elementCount == elementData.length)
445        ensureCapacity(elementCount + 1);        ensureCapacity(elementCount + 1);
446      modCount++;      modCount++;
# Line 598  public class Vector extends AbstractList Line 590  public class Vector extends AbstractList
590     */     */
591    public synchronized Object set(int index, Object element)    public synchronized Object set(int index, Object element)
592    {    {
593      if (index >= elementCount)      checkBoundExclusive(index);
       throw new ArrayIndexOutOfBoundsException(index + " >= " + elementCount);  
   
594      Object temp = elementData[index];      Object temp = elementData[index];
595      elementData[index] = element;      elementData[index] = element;
596      return temp;      return temp;
# Line 656  public class Vector extends AbstractList Line 646  public class Vector extends AbstractList
646     */     */
647    public synchronized Object remove(int index)    public synchronized Object remove(int index)
648    {    {
649      if (index >= elementCount)      checkBoundExclusive(index);
       throw new ArrayIndexOutOfBoundsException(index + " >= " + elementCount);  
   
650      Object temp = elementData[index];      Object temp = elementData[index];
651      modCount++;      modCount++;
652      elementCount--;      elementCount--;
# Line 771  public class Vector extends AbstractList Line 759  public class Vector extends AbstractList
759     */     */
760    public synchronized boolean addAll(int index, Collection c)    public synchronized boolean addAll(int index, Collection c)
761    {    {
762      if (index > elementCount)      checkBoundInclusive(index);
       throw new ArrayIndexOutOfBoundsException(index);  
763      Iterator itr = c.iterator();      Iterator itr = c.iterator();
764      int csize = c.size();      int csize = c.size();
765    
# Line 871  public class Vector extends AbstractList Line 858  public class Vector extends AbstractList
858          Arrays.fill(elementData, elementCount, save, null);          Arrays.fill(elementData, elementCount, save, null);
859        }        }
860    }    }
861    
862      /**
863       * Checks that the index is in the range of possible elements (inclusive).
864       *
865       * @param index the index to check
866       * @throws ArrayIndexOutOfBoundsException if index > size
867       */
868      private void checkBoundInclusive(int index)
869      {
870        // Implementation note: we do not check for negative ranges here, since
871        // use of a negative index will cause an ArrayIndexOutOfBoundsException
872        // with no effort on our part.
873        if (index > elementCount)
874          throw new ArrayIndexOutOfBoundsException(index + " > " + elementCount);
875      }
876    
877      /**
878       * Checks that the index is in the range of existing elements (exclusive).
879       *
880       * @param index the index to check
881       * @throws ArrayIndexOutOfBoundsException if index >= size
882       */
883      private void checkBoundExclusive(int index)
884      {
885        // Implementation note: we do not check for negative ranges here, since
886        // use of a negative index will cause an ArrayIndexOutOfBoundsException
887        // with no effort on our part.
888        if (index >= elementCount)
889          throw new ArrayIndexOutOfBoundsException(index + " >= " + elementCount);
890      }
891  }  }

Legend:
Removed from v.1.14  
changed lines
  Added in v.1.15

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