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

Diff of /classpath/java/util/ArrayList.java

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

revision 1.16 by ericb, Mon Oct 22 03:46:07 2001 UTC revision 1.17 by ericb, Mon Oct 22 05:48:01 2001 UTC
# Line 294  public class ArrayList extends AbstractL Line 294  public class ArrayList extends AbstractL
294     */     */
295    public Object get(int index)    public Object get(int index)
296    {    {
297      rangeExclusive(index);      checkBoundExclusive(index);
298      return data[index];      return data[index];
299    }    }
300    
# Line 308  public class ArrayList extends AbstractL Line 308  public class ArrayList extends AbstractL
308     */     */
309    public Object set(int index, Object e)    public Object set(int index, Object e)
310    {    {
311      rangeExclusive(index);      checkBoundExclusive(index);
312      Object result = data[index];      Object result = data[index];
313      data[index] = e;      data[index] = e;
314      return result;      return result;
# Line 339  public class ArrayList extends AbstractL Line 339  public class ArrayList extends AbstractL
339     */     */
340    public void add(int index, Object e)    public void add(int index, Object e)
341    {    {
342      rangeInclusive(index);      checkBoundInclusive(index);
343      modCount++;      modCount++;
344      if (size == data.length)      if (size == data.length)
345        ensureCapacity(size + 1);        ensureCapacity(size + 1);
# Line 358  public class ArrayList extends AbstractL Line 358  public class ArrayList extends AbstractL
358     */     */
359    public Object remove(int index)    public Object remove(int index)
360    {    {
361      rangeExclusive(index);      checkBoundExclusive(index);
362      Object r = data[index];      Object r = data[index];
363      modCount++;      modCount++;
364      if (index != --size)      if (index != --size)
# Line 407  public class ArrayList extends AbstractL Line 407  public class ArrayList extends AbstractL
407     */     */
408    public boolean addAll(int index, Collection c)    public boolean addAll(int index, Collection c)
409    {    {
410      rangeInclusive(index);      checkBoundInclusive(index);
411      Iterator itr = c.iterator();      Iterator itr = c.iterator();
412      int csize = c.size();      int csize = c.size();
413    
# Line 444  public class ArrayList extends AbstractL Line 444  public class ArrayList extends AbstractL
444     * Checks that the index is in the range of possible elements (inclusive).     * Checks that the index is in the range of possible elements (inclusive).
445     *     *
446     * @param index the index to check     * @param index the index to check
447     * @throws IndexOutOfBoundsException if index < 0 || index > size     * @throws IndexOutOfBoundsException if index > size
448     */     */
449    private void rangeInclusive(int index)    private void checkBoundInclusive(int index)
450    {    {
451      // Implementation note: we do not check for negative ranges here, since      // Implementation note: we do not check for negative ranges here, since
452      // that will cause an ArrayIndexOutOfBoundsException, a subclass of      // use of a negative index will cause an ArrayIndexOutOfBoundsException,
453      // the required exception, with no effort on our part.      // a subclass of the required exception, with no effort on our part.
454      if (index > size)      if (index > size)
455        throw new IndexOutOfBoundsException("Index: " + index + ", Size:"        throw new IndexOutOfBoundsException("Index: " + index + ", Size:"
456                                            + size);                                            + size);
# Line 460  public class ArrayList extends AbstractL Line 460  public class ArrayList extends AbstractL
460     * Checks that the index is in the range of existing elements (exclusive).     * Checks that the index is in the range of existing elements (exclusive).
461     *     *
462     * @param index the index to check     * @param index the index to check
463     * @throws IndexOutOfBoundsException if index < 0 || index >= size     * @throws IndexOutOfBoundsException if index >= size
464     */     */
465    private void rangeExclusive(int index)    private void checkBoundExclusive(int index)
466    {    {
467      // Implementation note: we do not check for negative ranges here, since      // Implementation note: we do not check for negative ranges here, since
468      // that will cause an ArrayIndexOutOfBoundsException, a subclass of      // use of a negative index will cause an ArrayIndexOutOfBoundsException,
469      // the required exception, with no effort on our part.      // a subclass of the required exception, with no effort on our part.
470      if (index >= size)      if (index >= size)
471        throw new IndexOutOfBoundsException("Index: " + index + ", Size:"        throw new IndexOutOfBoundsException("Index: " + index + ", Size:"
472                                            + size);                                            + size);

Legend:
Removed from v.1.16  
changed lines
  Added in v.1.17

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