|
PCJ API Version 1.2 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object bak.pcj.AbstractByteCollection bak.pcj.list.AbstractByteList bak.pcj.adapter.ListToByteListAdapter
This class represents adaptions of Java Collections Framework lists to primitive lists of byte values. The adapter is implemented as a wrapper around the list. Thus, changes to the underlying list are reflected by this list and vice versa.
Adapters from JCF collections to primitive collections will fail if the JCF collection contains null values or values of the wrong class. However, adapters are not fast failing in the case that the underlying collection should contain illegal values. To implement fast failure would require every operation to check every element of the underlying collection before doing anything. Instead validation methods are provided. They can be called using the assertion facility in the client code:
ListToByteListAdapter s; ... assert s.validate();or by letting the adapter throw an exception on illegal values:
ListToByteListAdapter s; ... s.evalidate(); // Throws an exception on illegal valuesEither way, validation must be invoked directly by the client code.
Field Summary | |
protected List |
list
The underlying list. |
Constructor Summary | |
ListToByteListAdapter(List list)
Creates a new adaption of a list to a list of byte values. |
|
ListToByteListAdapter(List list,
boolean validate)
Creates a new adaption of a list to a list of byte values. |
Method Summary | |
void |
add(int index,
byte v)
Throws UnsupportedOperationException. |
void |
evalidate()
Validates the list underlying this adapter and throws an exception if it is invalid. |
byte |
get(int index)
Returns the element at a specified position in this list. |
ByteListIterator |
listIterator(int index)
Returns a list iterator over this list, starting from a specified index. |
byte |
removeElementAt(int index)
Throws UnsupportedOperationException. |
byte |
set(int index,
byte v)
Sets a specified element to a new value. |
int |
size()
Returns the number of elements in this collection. |
boolean |
validate()
Indicates whether the underlying list is valid for this adapter. |
Methods inherited from class bak.pcj.list.AbstractByteList |
add, addAll, equals, hashCode, indexOf, indexOf, iterator, lastIndexOf, lastIndexOf, listIterator |
Methods inherited from class bak.pcj.AbstractByteCollection |
addAll, clear, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray, toString, trimToSize |
Methods inherited from class java.lang.Object |
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Methods inherited from interface bak.pcj.ByteCollection |
addAll, clear, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray, trimToSize |
Field Detail |
protected List list
Constructor Detail |
public ListToByteListAdapter(List list)
list
- the underlying list. This list must
consist of values of class
Byte
. Otherwise a
ClassCastException
will be thrown by some methods.
NullPointerException
- if list is null.public ListToByteListAdapter(List list, boolean validate)
list
- the underlying list. This collection must
consist of values of class
Byte
. Otherwise a
ClassCastException
will be thrown by some methods.validate
- indicates whether list should
be checked for illegal values.
NullPointerException
- if list is null.
IllegalStateException
- if validate is true and
list contains a null value
or a value that is not of class
Byte
.Method Detail |
public void add(int index, byte v)
AbstractByteList
add
in interface ByteList
add
in class AbstractByteList
public byte get(int index)
ByteList
index
- the position of the element to return.
public ByteListIterator listIterator(int index)
ByteList
listIterator
in interface ByteList
listIterator
in class AbstractByteList
public byte removeElementAt(int index)
AbstractByteList
removeElementAt
in interface ByteList
removeElementAt
in class AbstractByteList
public byte set(int index, byte v)
ByteList
index
- the index of the element whose value to set.v
- the new value of the specified element.
public int size()
ByteCollection
size
in interface ByteCollection
size
in class AbstractByteCollection
public boolean validate()
Byte
values and no null
values.
public void evalidate()
Byte
values and no null values.
IllegalStateException
- if the underlying list is invalid.
|
PCJ API Version 1.2 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |