|
|||||||||
| Home >> All >> java >> [ util overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.util
Class Collections.SynchronizedRandomAccessList

java.lang.Objectjava.util.Collections.SynchronizedCollection
java.util.Collections.SynchronizedList
java.util.Collections.SynchronizedRandomAccessList
- All Implemented Interfaces:
- Collection, java.lang.Iterable, List, RandomAccess, java.io.Serializable
- Enclosing class:
- Collections
- private static final class Collections.SynchronizedRandomAccessList
- extends Collections.SynchronizedList
- implements RandomAccess
- extends Collections.SynchronizedList
The implementation of Collections.synchronizedList(List) 55 for random-access
lists. This class name is required for compatibility with Sun's JDK
serializability.
| Field Summary | |
(package private) Collection |
c
The wrapped collection. |
(package private) List |
list
The wrapped list; stored both here and in the superclass to avoid excessive casting. |
(package private) java.lang.Object |
mutex
The object to synchronize on. |
private static long |
serialVersionUID
Compatible with JDK 1.4. |
| Constructor Summary | |
(package private) |
Collections.SynchronizedRandomAccessList(List l)
Wrap a given list. |
(package private) |
Collections.SynchronizedRandomAccessList(java.lang.Object sync,
List l)
Called only by trusted code to specify the mutex as well as the collection. |
| Method Summary | |
void |
add(int index,
java.lang.Object o)
Insert an element into the underlying list at a given position (optional operation). |
boolean |
add(java.lang.Object o)
Adds the object to the underlying collection, first obtaining a lock on the mutex. |
boolean |
addAll(Collection col)
Adds the objects in col to the underlying collection, first obtaining a lock on the mutex. |
boolean |
addAll(int index,
Collection c)
Add the contents of a collection to the underlying list at the given index (optional operation). |
void |
clear()
Removes all objects from the underlying collection, first obtaining a lock on the mutex. |
boolean |
contains(java.lang.Object o)
Checks for the existence of o within the underlying collection, first obtaining a lock on the mutex. |
boolean |
containsAll(Collection c1)
Checks for the existence of each object in cl within the underlying collection, first obtaining a lock on the mutex. |
boolean |
equals(java.lang.Object o)
Tests whether the underlying list is equal to the supplied object. |
java.lang.Object |
get(int index)
Retrieves the object at the specified index. |
int |
hashCode()
Obtains a hashcode for the underlying list, first obtaining a lock on the mutex. |
int |
indexOf(java.lang.Object o)
Obtain the first index at which a given object is to be found in the underlying list. |
boolean |
isEmpty()
Returns true if there are no objects in the underlying
collection. |
Iterator |
iterator()
Returns a synchronized iterator wrapper around the underlying collection's iterator. |
int |
lastIndexOf(java.lang.Object o)
Obtain the last index at which a given object is to be found in this underlying list. |
ListIterator |
listIterator()
Retrieves a synchronized wrapper around the underlying list's list iterator. |
ListIterator |
listIterator(int index)
Retrieves a synchronized wrapper around the underlying list's list iterator. |
java.lang.Object |
remove(int index)
Remove the element at a given position in the underlying list (optional operation). |
boolean |
remove(java.lang.Object o)
Removes the specified object from the underlying collection, first obtaining a lock on the mutex. |
boolean |
removeAll(Collection col)
Removes all elements, e, of the underlying collection for which col.contains(e)
returns true. |
boolean |
retainAll(Collection col)
Retains all elements, e, of the underlying collection for which col.contains(e)
returns true. |
java.lang.Object |
set(int index,
java.lang.Object o)
Replace an element of the underlying list with another object (optional operation). |
int |
size()
Retrieves the size of the underlying collection. |
List |
subList(int fromIndex,
int toIndex)
Obtain a List view of a subsection of the underlying list, from fromIndex (inclusive) to toIndex (exclusive). |
java.lang.Object[] |
toArray()
Returns an array containing each object within the underlying collection. |
java.lang.Object[] |
toArray(java.lang.Object[] a)
Copies the elements in the underlying collection to the supplied array. |
java.lang.String |
toString()
Returns a string representation of the underlying collection. |
| Methods inherited from class java.lang.Object |
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Methods inherited from interface java.util.List |
add, addAll, clear, contains, containsAll, isEmpty, iterator, remove, removeAll, retainAll, size, toArray, toArray |
| Field Detail |
serialVersionUID
private static final long serialVersionUID
- Compatible with JDK 1.4.
- See Also:
- Constant Field Values
list
final List list
- The wrapped list; stored both here and in the superclass to avoid
excessive casting. Package visible for use by subclass.
c
final Collection c
- The wrapped collection. Package visible for use by subclasses.
mutex
final java.lang.Object mutex
- The object to synchronize on. When an instance is created via public
methods, it will be this; but other uses like SynchronizedMap.values()
must specify another mutex. Package visible for use by subclasses.
| Constructor Detail |
Collections.SynchronizedRandomAccessList
Collections.SynchronizedRandomAccessList(List l)
- Wrap a given list.
Collections.SynchronizedRandomAccessList
Collections.SynchronizedRandomAccessList(java.lang.Object sync, List l)
- Called only by trusted code to specify the mutex as well as the
collection.
| Method Detail |
subList
public List subList(int fromIndex, int toIndex)
- Obtain a List view of a subsection of the underlying list, from fromIndex
(inclusive) to toIndex (exclusive). If the two indices are equal, the
sublist is empty. The returned list should be modifiable if and only
if this list is modifiable. Changes to the returned list should be
reflected in this list. If this list is structurally modified in
any way other than through the returned list, the result of any subsequent
operations on the returned list is undefined. A lock is obtained
on the mutex before the creation of the sublist. The returned list
is also synchronized, using the same mutex. Random accessibility
is also extended to the new list.
- Specified by:
subListin interfaceList- Overrides:
subListin classCollections.SynchronizedList
add
public void add(int index,
java.lang.Object o)
- Insert an element into the underlying list at a given position (optional
operation). This shifts all existing elements from that position to the
end one index to the right. This version of add has no return, since it is
assumed to always succeed if there is no exception. Before the
addition takes place, a lock is obtained on the mutex.
addAll
public boolean addAll(int index,
Collection c)
- Add the contents of a collection to the underlying list at the given
index (optional operation). If the list imposes restraints on what
can be inserted, such as no null elements, this should be documented.
A lock is obtained on the mutex before any of the elements are added.
equals
public boolean equals(java.lang.Object o)
- Tests whether the underlying list is equal to the supplied object.
The object is deemed to be equal if it is also a
Listof equal size and with the same elements (i.e. each element, e1, in list, l1, and each element, e2, in l2, must returntruefore1 == null ? e2 == null : e1.equals(e2). Before the comparison is made, a lock is obtained on the mutex.
get
public java.lang.Object get(int index)
- Retrieves the object at the specified index. A lock
is obtained on the mutex before the list is accessed.
hashCode
public int hashCode()
- Obtains a hashcode for the underlying list, first obtaining
a lock on the mutex. The calculation of the hashcode is
detailed in the documentation for the
Listinterface.
indexOf
public int indexOf(java.lang.Object o)
- Obtain the first index at which a given object is to be found in the
underlying list. A lock is obtained on the mutex before the list is
accessed.
lastIndexOf
public int lastIndexOf(java.lang.Object o)
- Obtain the last index at which a given object is to be found in this
underlying list. A lock is obtained on the mutex before the list
is accessed.
- Specified by:
lastIndexOfin interfaceList
listIterator
public ListIterator listIterator()
- Retrieves a synchronized wrapper around the underlying list's
list iterator. A lock is obtained on the mutex before the
list iterator is retrieved.
- Specified by:
listIteratorin interfaceList
listIterator
public ListIterator listIterator(int index)
- Retrieves a synchronized wrapper around the underlying list's
list iterator. A lock is obtained on the mutex before the
list iterator is retrieved. The iterator starts at the
index supplied, leading to the element at that index being
the first one returned by
next(). Callingprevious()from this initial position returns index - 1.- Specified by:
listIteratorin interfaceList
remove
public java.lang.Object remove(int index)
- Remove the element at a given position in the underlying list (optional
operation). All remaining elements are shifted to the left to fill the gap.
A lock on the mutex is obtained before the element is removed.
set
public java.lang.Object set(int index, java.lang.Object o)
- Replace an element of the underlying list with another object (optional
operation). A lock is obtained on the mutex before the element is
replaced.
add
public boolean add(java.lang.Object o)
- Adds the object to the underlying collection, first
obtaining a lock on the mutex.
- Specified by:
addin interfaceCollection
addAll
public boolean addAll(Collection col)
- Adds the objects in col to the underlying collection, first
obtaining a lock on the mutex.
- Specified by:
addAllin interfaceCollection
clear
public void clear()
- Removes all objects from the underlying collection,
first obtaining a lock on the mutex.
- Specified by:
clearin interfaceCollection
contains
public boolean contains(java.lang.Object o)
- Checks for the existence of o within the underlying
collection, first obtaining a lock on the mutex.
- Specified by:
containsin interfaceCollection
containsAll
public boolean containsAll(Collection c1)
- Checks for the existence of each object in cl
within the underlying collection, first obtaining
a lock on the mutex.
- Specified by:
containsAllin interfaceCollection
isEmpty
public boolean isEmpty()
- Returns
trueif there are no objects in the underlying collection. A lock on the mutex is obtained before the check is performed.- Specified by:
isEmptyin interfaceCollection
iterator
public Iterator iterator()
- Returns a synchronized iterator wrapper around the underlying
collection's iterator. A lock on the mutex is obtained before
retrieving the collection's iterator.
- Specified by:
iteratorin interfaceCollection
remove
public boolean remove(java.lang.Object o)
- Removes the specified object from the underlying collection,
first obtaining a lock on the mutex.
- Specified by:
removein interfaceCollection
removeAll
public boolean removeAll(Collection col)
- Removes all elements, e, of the underlying
collection for which
col.contains(e)returnstrue. A lock on the mutex is obtained before the operation proceeds.- Specified by:
removeAllin interfaceCollection
retainAll
public boolean retainAll(Collection col)
- Retains all elements, e, of the underlying
collection for which
col.contains(e)returnstrue. That is, every element that doesn't exist in col is removed. A lock on the mutex is obtained before the operation proceeds.- Specified by:
retainAllin interfaceCollection
size
public int size()
- Retrieves the size of the underlying collection.
A lock on the mutex is obtained before the collection
is accessed.
- Specified by:
sizein interfaceCollection
toArray
public java.lang.Object[] toArray()
- Returns an array containing each object within the underlying
collection. A lock is obtained on the mutex before the collection
is accessed.
- Specified by:
toArrayin interfaceCollection
toArray
public java.lang.Object[] toArray(java.lang.Object[] a)
- Copies the elements in the underlying collection to the supplied
array. If
a.length < size(), a new array of the same run-time type is created, with a size equal to that of the collection. Ifa.length > size(), then the elements from 0 tosize() - 1contain the elements from this collection. The following element is set to null to indicate the end of the collection objects. However, this only makes a difference if null is not a permitted value within the collection. Before the copying takes place, a lock is obtained on the mutex.- Specified by:
toArrayin interfaceCollection
toString
public java.lang.String toString()
- Returns a string representation of the underlying collection.
A lock is obtained on the mutex before the string is created.
|
|||||||||
| Home >> All >> java >> [ util overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
JAVADOC