org.joda.primitives.collection.impl
Class AbstractShortCollection

java.lang.Object
  extended by org.joda.primitives.collection.impl.AbstractPrimitiveCollectable<Short>
      extended by org.joda.primitives.collection.impl.AbstractShortCollection
All Implemented Interfaces:
Iterable<Short>, Collection<Short>, PrimitiveCollection<Short>, ShortCollection, ShortIterable, PrimitiveCollectable<Short>
Direct Known Subclasses:
AbstractShortList, ArrayShortCollection

public abstract class AbstractShortCollection
extends AbstractPrimitiveCollectable<Short>
implements ShortCollection

Abstract base class for collections of primitive short elements.

This class implements Collection allowing seamless integration with other APIs.

The iterator and size must be implemented by subclases. To make the subclass modifiable, the add(short) and iterator remove() methods must also be implemented. Subclasses may override other methods to increase efficiency.

Since:
1.0
Version:
CODE GENERATED
Author:
Stephen Colebourne, Jason Tiscione

Constructor Summary
protected AbstractShortCollection()
          Constructor.
 
Method Summary
 boolean add(short value)
          Adds a primitive value to this collection (optional operation).
 boolean add(Short value)
          Adds the Short value to this collection (optional operation).
 boolean addAll(Collection<? extends Short> coll)
          Adds a collection of Short values to this collection (optional operation).
 boolean addAll(short[] values)
          Adds an array of primitive values to this collection (optional operation).
 boolean addAll(ShortCollection values)
          Adds a collection of primitive values to this collection (optional operation).
 boolean addAll(short startInclusive, short endInclusive)
          Adds a range of primitive values to this collection (optional operation).
protected  void arrayCopy(int fromIndex, short[] dest, int destIndex, int size)
          Copies data from this collection into the specified array.
protected  void checkAddModifiable()
          Check whether add is suported and throw an exception.
protected  void checkRemoveModifiable()
          Check whether remove is suported and throw an exception.
 void clear()
          Clears the collection/map of all elements (optional operation).
 boolean contains(Object value)
          Checks whether this collection contains a specified Short value.
 boolean contains(short value)
          Checks whether this collection contains a specified primitive value.
 boolean containsAll(Collection<?> coll)
          Checks if the collection contains all of the primitive values.
 boolean containsAll(short[] values)
          Checks if this collection contains all of the values in the specified array.
 boolean containsAll(ShortCollection values)
          Checks if this collection contains all of the values in the specified collection.
 boolean containsAll(short startInclusive, short endInclusive)
          Checks if this collection contain all the values in the specified range.
 boolean containsAny(Collection<?> coll)
          Checks if the collection contains any of the primitive values in the array.
 boolean containsAny(short[] values)
          Checks if this collection contains any of the values in the specified array.
 boolean containsAny(ShortCollection values)
          Checks if this collection contains any of the values in the specified collection.
 boolean containsAny(short startInclusive, short endInclusive)
          Checks if this collection contain some of the values in the specified range.
protected  boolean isAddModifiable()
          Are the add methods supported.
 boolean isModifiable()
          Is the collection modifiable in any way.
protected  boolean isRemoveModifiable()
          Are the remove methods supported.
protected  boolean isToPrimitivePossible(Object value)
          Checks if the object can be converted to a primitive successfully.
 boolean remove(Object value)
          Removes the first occurrance of the specified Short value from this collection (optional operation).
 boolean removeAll(Collection<?> coll)
          Removes each of a collection of Short values from this collection (optional operation).
 boolean removeAll(short value)
          Removes all occurrences of the specified primitive value from this collection.
 boolean removeAll(short[] values)
          Removes all occurrences from this collection of each primitive in the specified array.
 boolean removeAll(ShortCollection values)
          Removes all occurrences from this collection of each primitive in the specified collection.
 boolean removeAll(short startInclusive, short endInclusive)
          Removes all occurrences of a range of primitive values from this collection.
 boolean removeFirst(short value)
          Removes the first occurrence of the specified primitive value from this collection
 boolean retainAll(Collection<?> coll)
          Retains each of a collection of Short values, removing other values (optional operation).
 boolean retainAll(short[] values)
          Retains each element of this collection that is present in the specified array removing all other values.
 boolean retainAll(ShortCollection values)
          Retains each element of this collection that is present in the specified collection removing all other values.
 boolean retainAll(short startInclusive, short endInclusive)
          Retains all occurences of a range of primitive values within this collection removing all values outside the range (optional operation).
 Object[] toArray()
          Gets the collection as an array of Short.
<T> T[]
toArray(T[] array)
          Gets the collection as an array, using the array provided.
protected  Short toObject(short value)
          Wraps an short with an Object wrapper.
protected  short toPrimitive(Object value)
          Unwraps the Short to retrieve the primitive short.
protected  short[] toPrimitiveArray(Collection<?> coll)
          Unwraps a Collection to retrieve the primitive short.
 short[] toShortArray()
          Gets the elements of this collection as an array.
 short[] toShortArray(short[] array, int startIndex)
          Copies the elements of this collection into an array at a specified position.
 String toString()
          Gets a string representing this collection.
 
Methods inherited from class org.joda.primitives.collection.impl.AbstractPrimitiveCollectable
clone, isEmpty, optimize
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.joda.primitives.collection.ShortCollection
iterator
 
Methods inherited from interface org.joda.primitives.PrimitiveCollectable
clone, isEmpty, optimize, size
 
Methods inherited from interface java.util.Collection
equals, hashCode, isEmpty, size
 

Constructor Detail

AbstractShortCollection

protected AbstractShortCollection()
Constructor.

Method Detail

contains

public boolean contains(short value)
Checks whether this collection contains a specified primitive value.

This implementation uses shortIterator().

Specified by:
contains in interface ShortCollection
Parameters:
value - the value to search for
Returns:
true if the value is found

containsAll

public boolean containsAll(short[] values)
Checks if this collection contains all of the values in the specified array. If the specified array is empty, true is returned.

This implementation uses contains(short).

Specified by:
containsAll in interface ShortCollection
Parameters:
values - the values to search for, null treated as empty array
Returns:
true if all of the values are found

containsAll

public boolean containsAll(ShortCollection values)
Checks if this collection contains all of the values in the specified collection. If the specified collection is empty, true is returned.

This implementation uses contains(short).

Specified by:
containsAll in interface ShortCollection
Parameters:
values - the values to search for, null treated as empty collection
Returns:
true if all of the values are found

containsAll

public boolean containsAll(short startInclusive,
                           short endInclusive)
Checks if this collection contain all the values in the specified range.

The range is defined to be inclusive of the start and end. If the start is greater than the end then the result is true as the range is equivalent to an empty collection.

This implementation uses contains(short).

Specified by:
containsAll in interface ShortCollection
Parameters:
startInclusive - the inclusive range start value
endInclusive - the inclusive range end value
Returns:
true if the collection contains the entire range

containsAny

public boolean containsAny(short[] values)
Checks if this collection contains any of the values in the specified array. If the specified array is empty, false is returned.

This implementation uses contains(short).

Specified by:
containsAny in interface ShortCollection
Parameters:
values - the values to search for, null treated as empty array
Returns:
true if at least one of the values is found

containsAny

public boolean containsAny(ShortCollection values)
Checks if this collection contains any of the values in the specified collection. If the specified collection is empty, false is returned.

This implementation uses contains(short).

Specified by:
containsAny in interface ShortCollection
Parameters:
values - the values to search for, null treated as empty collection
Returns:
true if at least one of the values is found

containsAny

public boolean containsAny(short startInclusive,
                           short endInclusive)
Checks if this collection contain some of the values in the specified range.

The range is defined to be inclusive of the start and end. If the start is greater than the end then the result is false as the range is equivalent to an empty collection.

This implementation uses contains(short).

Specified by:
containsAny in interface ShortCollection
Parameters:
startInclusive - the inclusive range start value
endInclusive - the inclusive range end value
Returns:
true if the collection contains at least one of the range

toShortArray

public short[] toShortArray()
Gets the elements of this collection as an array.

This implementation uses arrayCopy.

Specified by:
toShortArray in interface ShortCollection
Returns:
a new array containing a copy of the elements of this collection

toShortArray

public short[] toShortArray(short[] array,
                            int startIndex)
Copies the elements of this collection into an array at a specified position. Previous values in the array are overwritten.

If the array specified is null a new array is created. If the array specified is large enough, it will be modified. If the array is not large enough, a new array will be created containing the values from the specified array before the startIndex plus those from this collection.

This implementation uses arrayCopy.

Specified by:
toShortArray in interface ShortCollection
Parameters:
array - the array to add the elements to, null treated as empty array
startIndex - the position in the array to start setting elements
Returns:
the array with the populated collection
Throws:
IndexOutOfBoundsException - if the index is negative

clear

public void clear()
Clears the collection/map of all elements (optional operation).

The collection/map will have a zero size after this method completes. This method is optional, throwing an UnsupportedOperationException if the collection/map cannot be cleared.

This implementation uses iterator().

Specified by:
clear in interface Collection<Short>
Specified by:
clear in interface PrimitiveCollectable<Short>
Throws:
UnsupportedOperationException - if method not supported by this collection

add

public boolean add(short value)
Adds a primitive value to this collection (optional operation).

This implementation throws UnsupportedOperationException.

Specified by:
add in interface ShortCollection
Parameters:
value - the value to add to this collection
Returns:
true if this collection was modified by this method call
Throws:
IllegalArgumentException - if value is rejected by this collection
UnsupportedOperationException - if not supported by this collection

addAll

public boolean addAll(short[] values)
Adds an array of primitive values to this collection (optional operation).

This implementation uses add(short).

Specified by:
addAll in interface ShortCollection
Parameters:
values - the values to add to this collection, null treated as empty array
Returns:
true if this collection was modified by this method call
Throws:
IllegalArgumentException - if a value is rejected by this collection
UnsupportedOperationException - if not supported by this collection

addAll

public boolean addAll(ShortCollection values)
Adds a collection of primitive values to this collection (optional operation).

This implementation uses add(short).

Specified by:
addAll in interface ShortCollection
Parameters:
values - the values to add to this collection, null treated as empty collection
Returns:
true if this collection was modified by this method call
Throws:
IllegalArgumentException - if a value is rejected by this collection
UnsupportedOperationException - if not supported by this collection

addAll

public boolean addAll(short startInclusive,
                      short endInclusive)
Adds a range of primitive values to this collection (optional operation).

The range is defined to be inclusive of the start and end. If the start is greater than the end then the range is equivalent to an empty collection.

This implementation uses add(short).

Specified by:
addAll in interface ShortCollection
Parameters:
startInclusive - the inclusive range start value
endInclusive - the inclusive range end value
Returns:
true if this collection was modified by this method call
Throws:
IllegalArgumentException - if a value is rejected by this set
UnsupportedOperationException - if not supported by this set

removeFirst

public boolean removeFirst(short value)
Removes the first occurrence of the specified primitive value from this collection

This implementation uses iterator().remove().

Specified by:
removeFirst in interface ShortCollection
Parameters:
value - the value to remove
Returns:
true if this collection was modified by this method call
Throws:
UnsupportedOperationException - if not supported by this collection

removeAll

public boolean removeAll(short value)
Removes all occurrences of the specified primitive value from this collection.

This implementation uses iterator().remove().

Specified by:
removeAll in interface ShortCollection
Parameters:
value - the value to remove
Returns:
true if this collection was modified by this method call
Throws:
UnsupportedOperationException - if not supported by this collection

removeAll

public boolean removeAll(short[] values)
Removes all occurrences from this collection of each primitive in the specified array.

This implementation uses iterator().remove().

Specified by:
removeAll in interface ShortCollection
Parameters:
values - the values to remove from this collection, null treated as empty array
Returns:
true if this list was modified by this method call
Throws:
UnsupportedOperationException - if not supported by this collection

removeAll

public boolean removeAll(ShortCollection values)
Removes all occurrences from this collection of each primitive in the specified collection.

This implementation uses iterator().remove().

Specified by:
removeAll in interface ShortCollection
Parameters:
values - the values to remove from this collection, null treated as empty collection
Returns:
true if this list was modified by this method call
Throws:
UnsupportedOperationException - if not supported by this collection

removeAll

public boolean removeAll(short startInclusive,
                         short endInclusive)
Removes all occurrences of a range of primitive values from this collection.

The range is defined to be inclusive of the start and end. The elements removed are greater than or equal to the start and less than or equal to the end. Thus if the start is greater than the end then no elements are removed.

This method is optional, throwing an UnsupportedOperationException if the set cannot be changed.

This implementation uses iterator().remove().

Specified by:
removeAll in interface ShortCollection
Parameters:
startInclusive - the inclusive range start value
endInclusive - the inclusive range end value
Returns:
true if this collection was modified by this method call
Throws:
UnsupportedOperationException - if not supported by this collection

retainAll

public boolean retainAll(short[] values)
Retains each element of this collection that is present in the specified array removing all other values.

This implementation uses iterator().remove().

Specified by:
retainAll in interface ShortCollection
Parameters:
values - the values to remove from this collection, null treated as empty array
Returns:
true if this list was modified by this method call
Throws:
UnsupportedOperationException - if not supported by this collection

retainAll

public boolean retainAll(ShortCollection values)
Retains each element of this collection that is present in the specified collection removing all other values.

This implementation uses iterator().remove().

Specified by:
retainAll in interface ShortCollection
Parameters:
values - the values to retain in this collection, null treated as empty collection
Returns:
true if this collection was modified by this method call
Throws:
UnsupportedOperationException - if not supported by this collection

retainAll

public boolean retainAll(short startInclusive,
                         short endInclusive)
Retains all occurences of a range of primitive values within this collection removing all values outside the range (optional operation).

The range is defined to be inclusive of the start and end. If the start is greater than the end then the range is equivalent to an empty collection.

This method is optional, throwing an UnsupportedOperationException if the set cannot be changed.

Specified by:
retainAll in interface ShortCollection
Parameters:
startInclusive - the inclusive range start value
endInclusive - the inclusive range end value
Returns:
true if this collection was modified by this method call
Throws:
UnsupportedOperationException - if not supported by this collection

contains

public boolean contains(Object value)
Checks whether this collection contains a specified Short value.

This implementation uses contains(short).

Specified by:
contains in interface Collection<Short>
Parameters:
value - the value to search for
Returns:
true if the value is found

containsAll

public boolean containsAll(Collection<?> coll)
Checks if the collection contains all of the primitive values.

This implementation uses containsAll(short[]).

Specified by:
containsAll in interface Collection<Short>
Parameters:
coll - the collection of values to search for
Returns:
true if all the values are found

containsAny

public boolean containsAny(Collection<?> coll)
Checks if the collection contains any of the primitive values in the array. If the specified collection is empty, false is returned.

This implementation uses containsAny(short[]).

Specified by:
containsAny in interface PrimitiveCollection<Short>
Parameters:
coll - the collection of values to search for
Returns:
true if at least one of the values is found

toArray

public Object[] toArray()
Gets the collection as an array of Short.

Specified by:
toArray in interface Collection<Short>
Returns:
an array of Short

toArray

public <T> T[] toArray(T[] array)
Gets the collection as an array, using the array provided.

Specified by:
toArray in interface Collection<Short>
Parameters:
array - the array to populate
Returns:
an array of Short

add

public boolean add(Short value)
Adds the Short value to this collection (optional operation).

This method is optional, throwing an UnsupportedOperationException if the collection cannot be added to.

This implementation uses add(short).

Specified by:
add in interface Collection<Short>
Parameters:
value - the value to add to this collection
Returns:
true if this collection was modified by this method call
Throws:
IllegalArgumentException - if value is rejected by this collection
UnsupportedOperationException - if not supported by this collection

addAll

public boolean addAll(Collection<? extends Short> coll)
Adds a collection of Short values to this collection (optional operation).

This method is optional, throwing an UnsupportedOperationException if the collection cannot be added to.

This implementation uses addAll(short[]).

Specified by:
addAll in interface Collection<Short>
Parameters:
coll - the values to add to this collection
Returns:
true if this list was modified by this method call
Throws:
IndexOutOfBoundsException - if the index is invalid
ClassCastException - if any object is not Short
IllegalArgumentException - if value is rejected by this collection
UnsupportedOperationException - if not supported by this collection

remove

public boolean remove(Object value)
Removes the first occurrance of the specified Short value from this collection (optional operation).

This method is optional, throwing an UnsupportedOperationException if the collection cannot be removed from.

This implementation uses removeFirst(short).

Specified by:
remove in interface Collection<Short>
Parameters:
value - the value to remove
Returns:
true if this collection was modified by this method call
Throws:
UnsupportedOperationException - if not supported by this collection

removeAll

public boolean removeAll(Collection<?> coll)
Removes each of a collection of Short values from this collection (optional operation).

This method is optional, throwing an UnsupportedOperationException if the collection cannot be added to.

This implementation uses removeAll(short[]).

Specified by:
removeAll in interface Collection<Short>
Parameters:
coll - the values to remove from this collection
Returns:
true if this list was modified by this method call
Throws:
UnsupportedOperationException - if not supported by this collection

retainAll

public boolean retainAll(Collection<?> coll)
Retains each of a collection of Short values, removing other values (optional operation).

This method is optional, throwing an UnsupportedOperationException if the collection cannot be added to.

This implementation uses retainAll(short[]).

Specified by:
retainAll in interface Collection<Short>
Parameters:
coll - the values to retain in this collection
Returns:
true if this list was modified by this method call
Throws:
UnsupportedOperationException - if not supported by this collection

toString

public String toString()
Gets a string representing this collection.

The format used is as per Collection.

Overrides:
toString in class Object
Returns:
collection as a String

arrayCopy

protected void arrayCopy(int fromIndex,
                         short[] dest,
                         int destIndex,
                         int size)
Copies data from this collection into the specified array. This method is pre-validated.

Parameters:
fromIndex - the index to start from
dest - the destination array
destIndex - the destination start index
size - the number of items to copy

isAddModifiable

protected boolean isAddModifiable()
Are the add methods supported.

This implementation returns false.

Returns:
true if supported

isRemoveModifiable

protected boolean isRemoveModifiable()
Are the remove methods supported.

This implementation returns false.

Returns:
true if supported

isModifiable

public boolean isModifiable()
Is the collection modifiable in any way.

Specified by:
isModifiable in interface PrimitiveCollectable<Short>
Overrides:
isModifiable in class AbstractPrimitiveCollectable<Short>
Returns:
true if supported

checkAddModifiable

protected void checkAddModifiable()
Check whether add is suported and throw an exception.


checkRemoveModifiable

protected void checkRemoveModifiable()
Check whether remove is suported and throw an exception.


toObject

protected Short toObject(short value)
Wraps an short with an Object wrapper.

Parameters:
value - the primitive value
Returns:
the Object wrapper

isToPrimitivePossible

protected boolean isToPrimitivePossible(Object value)
Checks if the object can be converted to a primitive successfully.

This implementation only allows non-null Short objects.

Parameters:
value - the Object wrapper
Returns:
true if a primitive value can be successfully extracted

toPrimitive

protected short toPrimitive(Object value)
Unwraps the Short to retrieve the primitive short.

This implementation only allows non-null Short objects.

Parameters:
value - the Object to convert to a primitive
Returns:
the primitive value
Throws:
NullPointerException - if the value is null and this is unacceptable
ClassCastException - if the object is of an unsuitable type

toPrimitiveArray

protected short[] toPrimitiveArray(Collection<?> coll)
Unwraps a Collection to retrieve the primitive short.

This implementation only allows non-null Short objects.

Parameters:
coll - the Collection to convert to primitives
Returns:
the primitive value
Throws:
NullPointerException - if the value is null and this is unacceptable
ClassCastException - if any object is of an unsuitable type


Copyright © 2005-2010 Joda.org. All Rights Reserved.