348 349 public boolean hasMoreElements() { 350 return count < elementCount; 351 } 352 353 public E nextElement() { 354 synchronized (Vector.this) { 355 if (count < elementCount) { 356 return elementData(count++); 357 } 358 } 359 throw new NoSuchElementException("Vector Enumeration"); 360 } 361 }; 362 } 363 364 /** 365 * Returns {@code true} if this vector contains the specified element. 366 * More formally, returns {@code true} if and only if this vector 367 * contains at least one element {@code e} such that 368 * <tt>(o==null ? e==null : o.equals(e))</tt>. 369 * 370 * @param o element whose presence in this vector is to be tested 371 * @return {@code true} if this vector contains the specified element 372 */ 373 public boolean contains(Object o) { 374 return indexOf(o, 0) >= 0; 375 } 376 377 /** 378 * Returns the index of the first occurrence of the specified element 379 * in this vector, or -1 if this vector does not contain the element. 380 * More formally, returns the lowest index {@code i} such that 381 * <tt>(o==null ? get(i)==null : o.equals(get(i)))</tt>, 382 * or -1 if there is no such index. 383 * 384 * @param o element to search for 385 * @return the index of the first occurrence of the specified element in 386 * this vector, or -1 if this vector does not contain the element 387 */ 388 public int indexOf(Object o) { 389 return indexOf(o, 0); 390 } 391 392 /** 393 * Returns the index of the first occurrence of the specified element in 394 * this vector, searching forwards from {@code index}, or returns -1 if 395 * the element is not found. 396 * More formally, returns the lowest index {@code i} such that 397 * <tt>(i >= index && (o==null ? get(i)==null : o.equals(get(i))))</tt>, 398 * or -1 if there is no such index. 399 * 400 * @param o element to search for 401 * @param index index to start searching from 402 * @return the index of the first occurrence of the element in 403 * this vector at position {@code index} or later in the vector; 404 * {@code -1} if the element is not found. 405 * @throws IndexOutOfBoundsException if the specified index is negative 406 * @see Object#equals(Object) 407 */ 408 public synchronized int indexOf(Object o, int index) { 409 if (o == null) { 410 for (int i = index ; i < elementCount ; i++) 411 if (elementData[i]==null) 412 return i; 413 } else { 414 for (int i = index ; i < elementCount ; i++) 415 if (o.equals(elementData[i])) 416 return i; 417 } 418 return -1; 419 } 420 421 /** 422 * Returns the index of the last occurrence of the specified element 423 * in this vector, or -1 if this vector does not contain the element. 424 * More formally, returns the highest index {@code i} such that 425 * <tt>(o==null ? get(i)==null : o.equals(get(i)))</tt>, 426 * or -1 if there is no such index. 427 * 428 * @param o element to search for 429 * @return the index of the last occurrence of the specified element in 430 * this vector, or -1 if this vector does not contain the element 431 */ 432 public synchronized int lastIndexOf(Object o) { 433 return lastIndexOf(o, elementCount-1); 434 } 435 436 /** 437 * Returns the index of the last occurrence of the specified element in 438 * this vector, searching backwards from {@code index}, or returns -1 if 439 * the element is not found. 440 * More formally, returns the highest index {@code i} such that 441 * <tt>(i <= index && (o==null ? get(i)==null : o.equals(get(i))))</tt>, 442 * or -1 if there is no such index. 443 * 444 * @param o element to search for 445 * @param index index to start searching backwards from 446 * @return the index of the last occurrence of the element at position 447 * less than or equal to {@code index} in this vector; 448 * -1 if the element is not found. 449 * @throws IndexOutOfBoundsException if the specified index is greater 450 * than or equal to the current size of this vector 451 */ 452 public synchronized int lastIndexOf(Object o, int index) { 453 if (index >= elementCount) 454 throw new IndexOutOfBoundsException(index + " >= "+ elementCount); 455 456 if (o == null) { 457 for (int i = index; i >= 0; i--) 458 if (elementData[i]==null) 459 return i; 460 } else { 461 for (int i = index; i >= 0; i--) | 348 349 public boolean hasMoreElements() { 350 return count < elementCount; 351 } 352 353 public E nextElement() { 354 synchronized (Vector.this) { 355 if (count < elementCount) { 356 return elementData(count++); 357 } 358 } 359 throw new NoSuchElementException("Vector Enumeration"); 360 } 361 }; 362 } 363 364 /** 365 * Returns {@code true} if this vector contains the specified element. 366 * More formally, returns {@code true} if and only if this vector 367 * contains at least one element {@code e} such that 368 * <code>(o==null ? e==null : o.equals(e))</code>. 369 * 370 * @param o element whose presence in this vector is to be tested 371 * @return {@code true} if this vector contains the specified element 372 */ 373 public boolean contains(Object o) { 374 return indexOf(o, 0) >= 0; 375 } 376 377 /** 378 * Returns the index of the first occurrence of the specified element 379 * in this vector, or -1 if this vector does not contain the element. 380 * More formally, returns the lowest index {@code i} such that 381 * <code>(o==null ? get(i)==null : o.equals(get(i)))</code>, 382 * or -1 if there is no such index. 383 * 384 * @param o element to search for 385 * @return the index of the first occurrence of the specified element in 386 * this vector, or -1 if this vector does not contain the element 387 */ 388 public int indexOf(Object o) { 389 return indexOf(o, 0); 390 } 391 392 /** 393 * Returns the index of the first occurrence of the specified element in 394 * this vector, searching forwards from {@code index}, or returns -1 if 395 * the element is not found. 396 * More formally, returns the lowest index {@code i} such that 397 * <code>(i >= index && (o==null ? get(i)==null : o.equals(get(i))))</code>, 398 * or -1 if there is no such index. 399 * 400 * @param o element to search for 401 * @param index index to start searching from 402 * @return the index of the first occurrence of the element in 403 * this vector at position {@code index} or later in the vector; 404 * {@code -1} if the element is not found. 405 * @throws IndexOutOfBoundsException if the specified index is negative 406 * @see Object#equals(Object) 407 */ 408 public synchronized int indexOf(Object o, int index) { 409 if (o == null) { 410 for (int i = index ; i < elementCount ; i++) 411 if (elementData[i]==null) 412 return i; 413 } else { 414 for (int i = index ; i < elementCount ; i++) 415 if (o.equals(elementData[i])) 416 return i; 417 } 418 return -1; 419 } 420 421 /** 422 * Returns the index of the last occurrence of the specified element 423 * in this vector, or -1 if this vector does not contain the element. 424 * More formally, returns the highest index {@code i} such that 425 * <code>(o==null ? get(i)==null : o.equals(get(i)))</code>, 426 * or -1 if there is no such index. 427 * 428 * @param o element to search for 429 * @return the index of the last occurrence of the specified element in 430 * this vector, or -1 if this vector does not contain the element 431 */ 432 public synchronized int lastIndexOf(Object o) { 433 return lastIndexOf(o, elementCount-1); 434 } 435 436 /** 437 * Returns the index of the last occurrence of the specified element in 438 * this vector, searching backwards from {@code index}, or returns -1 if 439 * the element is not found. 440 * More formally, returns the highest index {@code i} such that 441 * <code>(i <= index && (o==null ? get(i)==null : o.equals(get(i))))</code>, 442 * or -1 if there is no such index. 443 * 444 * @param o element to search for 445 * @param index index to start searching backwards from 446 * @return the index of the last occurrence of the element at position 447 * less than or equal to {@code index} in this vector; 448 * -1 if the element is not found. 449 * @throws IndexOutOfBoundsException if the specified index is greater 450 * than or equal to the current size of this vector 451 */ 452 public synchronized int lastIndexOf(Object o, int index) { 453 if (index >= elementCount) 454 throw new IndexOutOfBoundsException(index + " >= "+ elementCount); 455 456 if (o == null) { 457 for (int i = index; i >= 0; i--) 458 if (elementData[i]==null) 459 return i; 460 } else { 461 for (int i = index; i >= 0; i--) |