PCJ API
Version 1.2

bak.pcj.adapter
Class ListToShortListAdapter

java.lang.Object
  extended bybak.pcj.AbstractShortCollection
      extended bybak.pcj.list.AbstractShortList
          extended bybak.pcj.adapter.ListToShortListAdapter
All Implemented Interfaces:
ShortCollection, ShortList

public class ListToShortListAdapter
extends AbstractShortList

This class represents adaptions of Java Collections Framework lists to primitive lists of short 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:

      ListToShortListAdapter s;
      ...
      assert s.validate();
  
or by letting the adapter throw an exception on illegal values:
      ListToShortListAdapter s;
      ...
      s.evalidate();  // Throws an exception on illegal values
  
Either way, validation must be invoked directly by the client code.

Since:
1.0

Field Summary
protected  List list
          The underlying list.
 
Constructor Summary
ListToShortListAdapter(List list)
          Creates a new adaption of a list to a list of short values.
ListToShortListAdapter(List list, boolean validate)
          Creates a new adaption of a list to a list of short values.
 
Method Summary
 void add(int index, short v)
          Throws UnsupportedOperationException.
 void evalidate()
          Validates the list underlying this adapter and throws an exception if it is invalid.
 short get(int index)
          Returns the element at a specified position in this list.
 ShortListIterator listIterator(int index)
          Returns a list iterator over this list, starting from a specified index.
 short removeElementAt(int index)
          Throws UnsupportedOperationException.
 short set(int index, short 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.AbstractShortList
add, addAll, equals, hashCode, indexOf, indexOf, iterator, lastIndexOf, lastIndexOf, listIterator
 
Methods inherited from class bak.pcj.AbstractShortCollection
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.ShortCollection
addAll, clear, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray, trimToSize
 

Field Detail

list

protected List list
The underlying list.

Constructor Detail

ListToShortListAdapter

public ListToShortListAdapter(List list)
Creates a new adaption of a list to a list of short values.

Parameters:
list - the underlying list. This list must consist of values of class Short. Otherwise a ClassCastException will be thrown by some methods.
Throws:
NullPointerException - if list is null.

ListToShortListAdapter

public ListToShortListAdapter(List list,
                              boolean validate)
Creates a new adaption of a list to a list of short values. The list to adapt is optionally validated.

Parameters:
list - the underlying list. This collection must consist of values of class Short. Otherwise a ClassCastException will be thrown by some methods.
validate - indicates whether list should be checked for illegal values.
Throws:
NullPointerException - if list is null.
IllegalStateException - if validate is true and list contains a null value or a value that is not of class Short.
Method Detail

add

public void add(int index,
                short v)
Description copied from class: AbstractShortList
Throws UnsupportedOperationException.

Specified by:
add in interface ShortList
Overrides:
add in class AbstractShortList

get

public short get(int index)
Description copied from interface: ShortList
Returns the element at a specified position in this list.

Parameters:
index - the position of the element to return.
Returns:
the element at the specified position.

listIterator

public ShortListIterator listIterator(int index)
Description copied from interface: ShortList
Returns a list iterator over this list, starting from a specified index.

Specified by:
listIterator in interface ShortList
Overrides:
listIterator in class AbstractShortList

removeElementAt

public short removeElementAt(int index)
Description copied from class: AbstractShortList
Throws UnsupportedOperationException.

Specified by:
removeElementAt in interface ShortList
Overrides:
removeElementAt in class AbstractShortList

set

public short set(int index,
                 short v)
Description copied from interface: ShortList
Sets a specified element to a new value.

Parameters:
index - the index of the element whose value to set.
v - the new value of the specified element.
Returns:
the previous value of the element.

size

public int size()
Description copied from interface: ShortCollection
Returns the number of elements in this collection.

Specified by:
size in interface ShortCollection
Overrides:
size in class AbstractShortCollection

validate

public boolean validate()
Indicates whether the underlying list is valid for this adapter. For the underlying list to be valid, it can only contain Short values and no null values.

Returns:
true if the underlying list is valid; returns false otherwise.

evalidate

public void evalidate()
Validates the list underlying this adapter and throws an exception if it is invalid. For the underlying list to be valid, it can only contain Short values and no null values.

Throws:
IllegalStateException - if the underlying list is invalid.

PCJ API
Version 1.2

Report a bug or request a feature.
Further information on the development and latest release of PCJ can be found at the project homepage.

Primitive Collections for Java is released under the GNU Lesser General Public License.
Copyright © 2002, 2003 Søren Bak. All Rights Reserved.

Hosted by SourceForge.net
SourceForge.net Logo