E
- the type of the list elementspublic class ReadonlyList<E>
extends java.lang.Object
implements java.util.List<E>, java.io.Serializable
List
. This is similar to
Collections.unmodifyableList, except that this can be extended when this is
just a read-only view of a changing list. The bad thing about this is that it
provides functions (eg add(Object)
) that will just throw an
exception. Such functions should not be available in the first place.
We have a better alternative in the ImmutableList
. However that is a
bare-bones and not common known class , which might confuse standard java
programmers.
Constructor and Description |
---|
ReadonlyList(java.util.List<E> infos) |
Modifier and Type | Method and Description |
---|---|
boolean |
add(E e) |
void |
add(int index,
E element) |
boolean |
addAll(java.util.Collection<? extends E> c) |
boolean |
addAll(int index,
java.util.Collection<? extends E> c) |
void |
clear() |
boolean |
contains(java.lang.Object o) |
boolean |
containsAll(java.util.Collection<?> c) |
E |
get(int index) |
int |
indexOf(java.lang.Object o) |
boolean |
isEmpty() |
java.util.Iterator<E> |
iterator() |
int |
lastIndexOf(java.lang.Object o) |
java.util.ListIterator<E> |
listIterator() |
java.util.ListIterator<E> |
listIterator(int index) |
E |
remove(int index) |
boolean |
remove(java.lang.Object o) |
boolean |
removeAll(java.util.Collection<?> c) |
boolean |
retainAll(java.util.Collection<?> c) |
E |
set(int index,
E element) |
int |
size() |
java.util.List<E> |
subList(int fromIndex,
int toIndex) |
java.lang.Object[] |
toArray() |
<T> T[] |
toArray(T[] a) |
java.lang.String |
toString() |
protected final java.util.List<E> list
public ReadonlyList(java.util.List<E> infos)
infos
- the list contents.public int size()
public boolean isEmpty()
public boolean contains(java.lang.Object o)
public java.util.Iterator<E> iterator()
public java.lang.Object[] toArray()
public <T> T[] toArray(T[] a)
public boolean add(E e)
public boolean remove(java.lang.Object o)
public boolean containsAll(java.util.Collection<?> c)
public boolean addAll(java.util.Collection<? extends E> c)
public boolean addAll(int index, java.util.Collection<? extends E> c)
addAll
in interface java.util.List<E>
public boolean removeAll(java.util.Collection<?> c)
public boolean retainAll(java.util.Collection<?> c)
public void clear()
public int indexOf(java.lang.Object o)
indexOf
in interface java.util.List<E>
public int lastIndexOf(java.lang.Object o)
lastIndexOf
in interface java.util.List<E>
public java.util.ListIterator<E> listIterator()
listIterator
in interface java.util.List<E>
public java.util.ListIterator<E> listIterator(int index)
listIterator
in interface java.util.List<E>
public java.util.List<E> subList(int fromIndex, int toIndex)
subList
in interface java.util.List<E>
public java.lang.String toString()
toString
in class java.lang.Object