Top Description Fields Constructors Methods
net.sf.ehcache.util

public Class SetAsList<E>

extends Object
implements List<E>
Class Inheritance
All Implemented Interfaces
java.util.List, java.util.SequencedCollection, java.util.Collection, java.lang.Iterable
Imports
java.util.Collection, .Iterator, .List, .ListIterator, .Set

Wraps a set to provide a list interface. All list methods not application to set throws an UnsupportedOperationException
Author
Chris Dennis

Field Summary

Modifier and TypeField and Description
private transient Object[]
private final Set<E>

Constructor Summary

AccessConstructor and Description
public
SetAsList(Set<E> set)

Method Summary

Modifier and TypeMethod and Description
public boolean
add(E
element to be appended to this list
e
)

Implements java.util.List.add.

Appends the specified element to the end of this list (optional operation).
public void
add(int
index at which the specified element is to be inserted
index
,
E
element to be inserted
element
)

Implements java.util.List.add.

Does not support List methods UnsupportedOperationException.
public boolean
addAll(Collection<? extends E>
collection containing elements to be added to this list
c
)

Implements java.util.List.addAll.

Appends all of the elements in the specified collection to the end of this list, in the order that they are returned by the specified collection's iterator (optional operation).
public boolean
addAll(int
index at which to insert the first element from the specified collection
index
,
Collection<? extends E>
collection containing elements to be added to this list
c
)

Implements java.util.List.addAll.

Does not support List methods UnsupportedOperationException.
public void
clear()

Implements java.util.List.clear.

Removes all of the elements from this list (optional operation).
public boolean
contains(Object
element whose presence in this list is to be tested
o
)

Implements java.util.List.contains.

Returns true if this list contains the specified element.
public boolean
containsAll(Collection<?>
collection to be checked for containment in this list
c
)

Implements java.util.List.containsAll.

Returns true if this list contains all of the elements of the specified collection.
public E
get(int
Index
index
)

Implements java.util.List.get.

Does not support List methods UnsupportedOperationException.
public int
indexOf(Object
element to search for
o
)

Implements java.util.List.indexOf.

Does not support List methods UnsupportedOperationException.
public boolean
isEmpty()

Implements java.util.List.isEmpty.

Returns true if this list contains no elements.
public Iterator<E>
iterator()

Implements java.util.List.iterator.

Returns an iterator over the elements in this list in proper sequence.
public int
lastIndexOf(Object
element to search for
o
)

Implements java.util.List.lastIndexOf.

Does not support List methods UnsupportedOperationException.
public ListIterator<E>
listIterator()

Implements java.util.List.listIterator.

Does not support List methods UnsupportedOperationException.
public ListIterator<E>
listIterator(int
index of the first element to be returned from the list iterator (by a call to next)
index
)

Implements java.util.List.listIterator.

Does not support List methods UnsupportedOperationException.
public boolean
remove(Object
element to be removed from this list, if present
o
)

Implements java.util.List.remove.

Removes the first occurrence of the specified element from this list, if it is present (optional operation).
public E
remove(int
the index of the element to be removed
index
)

Implements java.util.List.remove.

Does not support List methods UnsupportedOperationException.
public boolean
removeAll(Collection<?>
collection containing elements to be removed from this list
c
)

Implements java.util.List.removeAll.

Removes from this list all of its elements that are contained in the specified collection (optional operation).
public boolean
retainAll(Collection<?>
collection containing elements to be retained in this list
c
)

Implements java.util.List.retainAll.

Retains only the elements in this list that are contained in the specified collection (optional operation).
public E
set(int
index of the element to replace
index
,
E
element to be stored at the specified position
element
)

Implements java.util.List.set.

Does not support List methods UnsupportedOperationException.
public int
size()

Implements java.util.List.size.

Returns the number of elements in this list.
public List<E>
subList(int
low endpoint (inclusive) of the subList
fromIndex
,
int
high endpoint (exclusive) of the subList
toIndex
)

Implements java.util.List.subList.

Does not support List methods UnsupportedOperationException.
public Object[]
toArray()

Implements java.util.List.toArray.

Returns an array containing all of the elements in this list in proper sequence (from first to last element).
public <T> T[]
toArray(T[]
the array into which the elements of this list are to be stored, if it is big enough; otherwise, a new array of the same runtime type is allocated for this purpose.
a
)

Implements java.util.List.toArray.

Returns an array containing all of the elements in this list in proper sequence (from first to last element); the runtime type of the returned array is that of the specified array.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

arrayback to summary
private transient Object[] array
setback to summary
private final Set<E> set

Constructor Detail

SetAsListback to summary
public SetAsList(Set<E> set)

Method Detail

addback to summary
public boolean add(E e)

Implements java.util.List.add.

Doc from java.util.List.add.

Appends the specified element to the end of this list (optional operation).

Lists that support this operation may place limitations on what elements may be added to this list. In particular, some lists will refuse to add null elements, and others will impose restrictions on the type of elements that may be added. List classes should clearly specify in their documentation any restrictions on what elements may be added.

Parameters
e:E

element to be appended to this list

Returns:boolean

true (as specified by Collection#add)

addback to summary
public void add(int index, E element)

Implements java.util.List.add.

Does not support List methods UnsupportedOperationException.

Parameters
index:int

Doc from java.util.List.add.

index at which the specified element is to be inserted

element:E

Doc from java.util.List.add.

element to be inserted

addAllback to summary
public boolean addAll(Collection<? extends E> c)

Implements java.util.List.addAll.

Doc from java.util.List.addAll.

Appends all of the elements in the specified collection to the end of this list, in the order that they are returned by the specified collection's iterator (optional operation). The behavior of this operation is undefined if the specified collection is modified while the operation is in progress. (Note that this will occur if the specified collection is this list, and it's nonempty.)

Parameters
c:Collection<? extends E>

collection containing elements to be added to this list

Returns:boolean

true if this list changed as a result of the call

addAllback to summary
public boolean addAll(int index, Collection<? extends E> c)

Implements java.util.List.addAll.

Does not support List methods UnsupportedOperationException.

Parameters
index:int

Doc from java.util.List.addAll.

index at which to insert the first element from the specified collection

c:Collection<? extends E>

Doc from java.util.List.addAll.

collection containing elements to be added to this list

Returns:boolean

Doc from java.util.List.addAll.

true if this list changed as a result of the call

clearback to summary
public void clear()

Implements java.util.List.clear.

Doc from java.util.List.clear.

Removes all of the elements from this list (optional operation). The list will be empty after this call returns.

containsback to summary
public boolean contains(Object o)

Implements java.util.List.contains.

Doc from java.util.List.contains.

Returns true if this list contains the specified element. More formally, returns true if and only if this list contains at least one element e such that Objects.equals(o, e).

Parameters
o:Object

element whose presence in this list is to be tested

Returns:boolean

true if this list contains the specified element

containsAllback to summary
public boolean containsAll(Collection<?> c)

Implements java.util.List.containsAll.

Doc from java.util.List.containsAll.

Returns true if this list contains all of the elements of the specified collection.

Parameters
c:Collection<?>

collection to be checked for containment in this list

Returns:boolean

true if this list contains all of the elements of the specified collection

getback to summary
public E get(int index)

Implements java.util.List.get.

Does not support List methods UnsupportedOperationException.

Parameters
index:int

Index

Returns:E

Doc from java.util.List.get.

the element at the specified position in this list

indexOfback to summary
public int indexOf(Object o)

Implements java.util.List.indexOf.

Does not support List methods UnsupportedOperationException.

Parameters
o:Object

Doc from java.util.List.indexOf.

element to search for

Returns:int

Doc from java.util.List.indexOf.

the index of the first occurrence of the specified element in this list, or -1 if this list does not contain the element

isEmptyback to summary
public boolean isEmpty()

Implements java.util.List.isEmpty.

Doc from java.util.List.isEmpty.

Returns true if this list contains no elements.

Returns:boolean

true if this list contains no elements

iteratorback to summary
public Iterator<E> iterator()

Implements java.util.List.iterator.

Doc from java.util.List.iterator.

Returns an iterator over the elements in this list in proper sequence.

Returns:Iterator<E>

an iterator over the elements in this list in proper sequence

lastIndexOfback to summary
public int lastIndexOf(Object o)

Implements java.util.List.lastIndexOf.

Does not support List methods UnsupportedOperationException.

Parameters
o:Object

Doc from java.util.List.lastIndexOf.

element to search for

Returns:int

Doc from java.util.List.lastIndexOf.

the index of the last occurrence of the specified element in this list, or -1 if this list does not contain the element

listIteratorback to summary
public ListIterator<E> listIterator()

Implements java.util.List.listIterator.

Does not support List methods UnsupportedOperationException.

Returns:ListIterator<E>

Doc from java.util.List.listIterator.

a list iterator over the elements in this list (in proper sequence)

listIteratorback to summary
public ListIterator<E> listIterator(int index)

Implements java.util.List.listIterator.

Does not support List methods UnsupportedOperationException.

Parameters
index:int

Doc from java.util.List.listIterator.

index of the first element to be returned from the list iterator (by a call to next)

Returns:ListIterator<E>

Doc from java.util.List.listIterator.

a list iterator over the elements in this list (in proper sequence), starting at the specified position in the list

removeback to summary
public boolean remove(Object o)

Implements java.util.List.remove.

Doc from java.util.List.remove.

Removes the first occurrence of the specified element from this list, if it is present (optional operation). If this list does not contain the element, it is unchanged. More formally, removes the element with the lowest index i such that Objects.equals(o, get(i)) (if such an element exists). Returns true if this list contained the specified element (or equivalently, if this list changed as a result of the call).

Parameters
o:Object

element to be removed from this list, if present

Returns:boolean

true if this list contained the specified element

removeback to summary
public E remove(int index)

Implements java.util.List.remove.

Does not support List methods UnsupportedOperationException.

Parameters
index:int

Doc from java.util.List.remove.

the index of the element to be removed

Returns:E

Doc from java.util.List.remove.

the element previously at the specified position

removeAllback to summary
public boolean removeAll(Collection<?> c)

Implements java.util.List.removeAll.

Doc from java.util.List.removeAll.

Removes from this list all of its elements that are contained in the specified collection (optional operation).

Parameters
c:Collection<?>

collection containing elements to be removed from this list

Returns:boolean

true if this list changed as a result of the call

retainAllback to summary
public boolean retainAll(Collection<?> c)

Implements java.util.List.retainAll.

Doc from java.util.List.retainAll.

Retains only the elements in this list that are contained in the specified collection (optional operation). In other words, removes from this list all of its elements that are not contained in the specified collection.

Parameters
c:Collection<?>

collection containing elements to be retained in this list

Returns:boolean

true if this list changed as a result of the call

setback to summary
public E set(int index, E element)

Implements java.util.List.set.

Does not support List methods UnsupportedOperationException.

Parameters
index:int

Doc from java.util.List.set.

index of the element to replace

element:E

Doc from java.util.List.set.

element to be stored at the specified position

Returns:E

Doc from java.util.List.set.

the element previously at the specified position

sizeback to summary
public int size()

Implements java.util.List.size.

Doc from java.util.List.size.

Returns the number of elements in this list. If this list contains more than Integer.MAX_VALUE elements, returns Integer.MAX_VALUE.

Returns:int

the number of elements in this list

subListback to summary
public List<E> subList(int fromIndex, int toIndex)

Implements java.util.List.subList.

Does not support List methods UnsupportedOperationException.

Parameters
fromIndex:int

Doc from java.util.List.subList.

low endpoint (inclusive) of the subList

toIndex:int

Doc from java.util.List.subList.

high endpoint (exclusive) of the subList

Returns:List<E>

Doc from java.util.List.subList.

a view of the specified range within this list

toArrayback to summary
public Object[] toArray()

Implements java.util.List.toArray.

Doc from java.util.List.toArray.

Returns an array containing all of the elements in this list in proper sequence (from first to last element).

The returned array will be "safe" in that no references to it are maintained by this list. (In other words, this method must allocate a new array even if this list is backed by an array). The caller is thus free to modify the returned array.

This method acts as bridge between array-based and collection-based APIs.

Returns:Object[]

an array containing all of the elements in this list in proper sequence

toArrayback to summary
public <T> T[] toArray(T[] a)

Implements java.util.List.toArray.

Doc from java.util.List.toArray.

Returns an array containing all of the elements in this list in proper sequence (from first to last element); the runtime type of the returned array is that of the specified array. If the list fits in the specified array, it is returned therein. Otherwise, a new array is allocated with the runtime type of the specified array and the size of this list.

If the list fits in the specified array with room to spare (i.e., the array has more elements than the list), the element in the array immediately following the end of the list is set to null. (This is useful in determining the length of the list only if the caller knows that the list does not contain any null elements.)

Like the toArray() method, this method acts as bridge between array-based and collection-based APIs. Further, this method allows precise control over the runtime type of the output array, and may, under certain circumstances, be used to save allocation costs.

Suppose x is a list known to contain only strings. The following code can be used to dump the list into a newly allocated array of String:

String[] y = x.toArray(new String[0]);
Note that toArray(new Object[0]) is identical in function to toArray().
Parameters
<T>

Doc from java.util.Collection.toArray. the component type of the array to contain the collection

a:T[]

the array into which the elements of this list are to be stored, if it is big enough; otherwise, a new array of the same runtime type is allocated for this purpose.

Returns:T[]

an array containing the elements of this list