src/share/classes/java/util/Vector.java

Print this page




1033      * Removes from this list all of the elements whose index is between
1034      * {@code fromIndex}, inclusive, and {@code toIndex}, exclusive.
1035      * Shifts any succeeding elements to the left (reduces their index).
1036      * This call shortens the list by {@code (toIndex - fromIndex)} elements.
1037      * (If {@code toIndex==fromIndex}, this operation has no effect.)
1038      */
1039     protected synchronized void removeRange(int fromIndex, int toIndex) {
1040         modCount++;
1041         int numMoved = elementCount - toIndex;
1042         System.arraycopy(elementData, toIndex, elementData, fromIndex,
1043                          numMoved);
1044 
1045         // Let gc do its work
1046         int newElementCount = elementCount - (toIndex-fromIndex);
1047         while (elementCount != newElementCount)
1048             elementData[--elementCount] = null;
1049     }
1050 
1051     /**
1052      * Save the state of the {@code Vector} instance to a stream (that
1053      * is, serialize it).  This method is present merely for synchronization.
1054      * It just calls the default writeObject method.

1055      */
1056     private synchronized void writeObject(java.io.ObjectOutputStream s)
1057         throws java.io.IOException
1058     {
1059         s.defaultWriteObject();









1060     }
1061 
1062     /**
1063      * Returns a list iterator over the elements in this list (in proper
1064      * sequence), starting at the specified position in the list.
1065      * The specified index indicates the first element that would be
1066      * returned by an initial call to {@link ListIterator#next next}.
1067      * An initial call to {@link ListIterator#previous previous} would
1068      * return the element with the specified index minus one.
1069      *
1070      * <p>The returned list iterator is <a href="#fail-fast"><i>fail-fast</i></a>.
1071      *
1072      * @throws IndexOutOfBoundsException {@inheritDoc}
1073      */
1074     public synchronized ListIterator<E> listIterator(int index) {
1075         if (index < 0 || index > elementCount)
1076             throw new IndexOutOfBoundsException("Index: "+index);
1077         return new ListItr(index);
1078     }
1079 




1033      * Removes from this list all of the elements whose index is between
1034      * {@code fromIndex}, inclusive, and {@code toIndex}, exclusive.
1035      * Shifts any succeeding elements to the left (reduces their index).
1036      * This call shortens the list by {@code (toIndex - fromIndex)} elements.
1037      * (If {@code toIndex==fromIndex}, this operation has no effect.)
1038      */
1039     protected synchronized void removeRange(int fromIndex, int toIndex) {
1040         modCount++;
1041         int numMoved = elementCount - toIndex;
1042         System.arraycopy(elementData, toIndex, elementData, fromIndex,
1043                          numMoved);
1044 
1045         // Let gc do its work
1046         int newElementCount = elementCount - (toIndex-fromIndex);
1047         while (elementCount != newElementCount)
1048             elementData[--elementCount] = null;
1049     }
1050 
1051     /**
1052      * Save the state of the {@code Vector} instance to a stream (that
1053      * is, serialize it).
1054      * This method performs synchronization to ensure the consistency
1055      * of the serialized data.
1056      */
1057     private void writeObject(java.io.ObjectOutputStream s)
1058             throws java.io.IOException {
1059         final java.io.ObjectOutputStream.PutField fields = s.putFields();
1060         Object[] data = null;
1061         synchronized (this) {
1062             fields.put("capacityIncrement", capacityIncrement);
1063             fields.put("elementCount", elementCount);
1064             final int dataLength = elementData.length;
1065             data = new Object[dataLength];
1066             System.arraycopy(elementData, 0, data, 0, dataLength);
1067         }
1068         fields.put("elementData", data);
1069         s.writeFields();
1070     }
1071 
1072     /**
1073      * Returns a list iterator over the elements in this list (in proper
1074      * sequence), starting at the specified position in the list.
1075      * The specified index indicates the first element that would be
1076      * returned by an initial call to {@link ListIterator#next next}.
1077      * An initial call to {@link ListIterator#previous previous} would
1078      * return the element with the specified index minus one.
1079      *
1080      * <p>The returned list iterator is <a href="#fail-fast"><i>fail-fast</i></a>.
1081      *
1082      * @throws IndexOutOfBoundsException {@inheritDoc}
1083      */
1084     public synchronized ListIterator<E> listIterator(int index) {
1085         if (index < 0 || index > elementCount)
1086             throw new IndexOutOfBoundsException("Index: "+index);
1087         return new ListItr(index);
1088     }
1089