org.apache.commons.collections.primitives
Class ArrayUnsignedByteList

java.lang.Object
  extended by org.apache.commons.collections.primitives.AbstractShortCollection
      extended by org.apache.commons.collections.primitives.RandomAccessShortList
          extended by org.apache.commons.collections.primitives.ArrayUnsignedByteList
All Implemented Interfaces:
java.io.Serializable, ShortCollection, ShortList

public class ArrayUnsignedByteList
extends RandomAccessShortList
implements ShortList, java.io.Serializable

A ShortList backed by an array of unsigned byte values. This list stores short values in the range [MIN_VALUE, MAX_VALUE] in 8-bits per element. Attempts to use elements outside this range may cause an IllegalArgumentException to be thrown.

This implementation supports all optional methods.

Since:
Commons Primitives 1.0
Version:
$Revision: 1.3 $ $Date: 2003/10/16 20:49:36 $
Author:
Rodney Waldhoff
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class org.apache.commons.collections.primitives.RandomAccessShortList
RandomAccessShortList.RandomAccessShortListIterator, RandomAccessShortList.RandomAccessShortSubList
 
Field Summary
private  byte[] _data
           
private  int _size
           
static short MAX_VALUE
          The maximum possible unsigned 8-bit value.
static short MIN_VALUE
          The minimum possible unsigned 8-bit value.
 
Constructor Summary
ArrayUnsignedByteList()
          Construct an empty list with the default initial capacity.
ArrayUnsignedByteList(int initialCapacity)
          Construct an empty list with the given initial capacity.
ArrayUnsignedByteList(ShortCollection that)
          Constructs a list containing the elements of the given collection, in the order they are returned by that collection's iterator.
 
Method Summary
 void add(int index, short element)
          Inserts the specified element at the specified position (optional operation).
private  void assertValidUnsignedByte(short value)
           
private  void checkRange(int index)
           
private  void checkRangeIncludingEndpoint(int index)
           
 void ensureCapacity(int mincap)
          Increases my capacity, if necessary, to ensure that I can hold at least the number of elements specified by the minimum capacity argument without growing.
private  byte fromShort(short value)
           
 short get(int index)
          Returns the element at the specified position within me.
private  void readObject(java.io.ObjectInputStream in)
           
 short removeElementAt(int index)
          Removes the element at the specified position in (optional operation).
 short set(int index, short element)
          Replaces the element at the specified position in me with the specified element (optional operation).
 int size()
          Returns the number of elements I contain.
private  short toShort(byte value)
           
 void trimToSize()
          Reduce my capacity, if necessary, to match my current size.
private  void writeObject(java.io.ObjectOutputStream out)
           
 
Methods inherited from class org.apache.commons.collections.primitives.RandomAccessShortList
add, addAll, equals, getModCount, hashCode, incrModCount, indexOf, iterator, lastIndexOf, listIterator, listIterator, subList, toString
 
Methods inherited from class org.apache.commons.collections.primitives.AbstractShortCollection
addAll, clear, contains, containsAll, isEmpty, removeAll, removeElement, retainAll, toArray, toArray
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.apache.commons.collections.primitives.ShortList
add, addAll, equals, hashCode, indexOf, iterator, lastIndexOf, listIterator, listIterator, subList
 
Methods inherited from interface org.apache.commons.collections.primitives.ShortCollection
addAll, clear, contains, containsAll, isEmpty, removeAll, removeElement, retainAll, toArray, toArray
 

Field Detail

_data

private transient byte[] _data

_size

private int _size

MAX_VALUE

public static final short MAX_VALUE
The maximum possible unsigned 8-bit value.

See Also:
Constant Field Values

MIN_VALUE

public static final short MIN_VALUE
The minimum possible unsigned 8-bit value.

See Also:
Constant Field Values
Constructor Detail

ArrayUnsignedByteList

public ArrayUnsignedByteList()
Construct an empty list with the default initial capacity.


ArrayUnsignedByteList

public ArrayUnsignedByteList(int initialCapacity)
Construct an empty list with the given initial capacity.

Throws:
java.lang.IllegalArgumentException - when initialCapacity is negative

ArrayUnsignedByteList

public ArrayUnsignedByteList(ShortCollection that)
Constructs a list containing the elements of the given collection, in the order they are returned by that collection's iterator.

Parameters:
that - the non-null collection of ints to add
Throws:
java.lang.NullPointerException - if that is null
See Also:
ShortCollection.addAll(org.apache.commons.collections.primitives.ShortCollection)
Method Detail

get

public short get(int index)
Returns the element at the specified position within me. By construction, the returned value will be between MIN_VALUE and MAX_VALUE, inclusive.

Specified by:
get in interface ShortList
Specified by:
get in class RandomAccessShortList
Parameters:
index - the index of the element to return
Returns:
the value of the element at the specified position
Throws:
java.lang.IndexOutOfBoundsException - if the specified index is out of range

size

public int size()
Description copied from interface: ShortCollection
Returns the number of elements I contain.

Specified by:
size in interface ShortCollection
Specified by:
size in class RandomAccessShortList
Returns:
the number of elements I contain

removeElementAt

public short removeElementAt(int index)
Removes the element at the specified position in (optional operation). Any subsequent elements are shifted to the left, subtracting one from their indices. Returns the element that was removed. By construction, the returned value will be between MIN_VALUE and MAX_VALUE, inclusive.

Specified by:
removeElementAt in interface ShortList
Overrides:
removeElementAt in class RandomAccessShortList
Parameters:
index - the index of the element to remove
Returns:
the value of the element that was removed
Throws:
java.lang.UnsupportedOperationException - when this operation is not supported
java.lang.IndexOutOfBoundsException - if the specified index is out of range

set

public short set(int index,
                 short element)
Replaces the element at the specified position in me with the specified element (optional operation). Throws IllegalArgumentException if element is less than MIN_VALUE or greater than MAX_VALUE.

Specified by:
set in interface ShortList
Overrides:
set in class RandomAccessShortList
Parameters:
index - the index of the element to change
element - the value to be stored at the specified position
Returns:
the value previously stored at the specified position
Throws:
java.lang.UnsupportedOperationException - when this operation is not supported
java.lang.IndexOutOfBoundsException - if the specified index is out of range

add

public void add(int index,
                short element)
Inserts the specified element at the specified position (optional operation). Shifts the element currently at that position (if any) and any subsequent elements to the right, increasing their indices. Throws IllegalArgumentException if element is less than MIN_VALUE or greater than MAX_VALUE.

Specified by:
add in interface ShortList
Overrides:
add in class RandomAccessShortList
Parameters:
index - the index at which to insert the element
element - the value to insert
Throws:
java.lang.UnsupportedOperationException - when this operation is not supported
java.lang.IllegalArgumentException - if some aspect of the specified element prevents it from being added to me
java.lang.IndexOutOfBoundsException - if the specified index is out of range

ensureCapacity

public void ensureCapacity(int mincap)
Increases my capacity, if necessary, to ensure that I can hold at least the number of elements specified by the minimum capacity argument without growing.


trimToSize

public void trimToSize()
Reduce my capacity, if necessary, to match my current size.


toShort

private final short toShort(byte value)

fromShort

private final byte fromShort(short value)

assertValidUnsignedByte

private final void assertValidUnsignedByte(short value)
                                    throws java.lang.IllegalArgumentException
Throws:
java.lang.IllegalArgumentException

writeObject

private void writeObject(java.io.ObjectOutputStream out)
                  throws java.io.IOException
Throws:
java.io.IOException

readObject

private void readObject(java.io.ObjectInputStream in)
                 throws java.io.IOException,
                        java.lang.ClassNotFoundException
Throws:
java.io.IOException
java.lang.ClassNotFoundException

checkRange

private final void checkRange(int index)

checkRangeIncludingEndpoint

private final void checkRangeIncludingEndpoint(int index)


Copyright (c) 2002-2003 - Apache Software Foundation