Top Description Inners Fields Constructors Methods
org.mortbay.util

public Class SingletonList

extends AbstractList
Class Inheritance
Imports
java.util.AbstractList, .Iterator, .ListIterator, .NoSuchElementException

Singleton List. This simple efficient implementation of a List with a single element is provided for JDK 1.2 JVMs, which do not provide the Collections.singletonList method.
Author
Greg Wilkins (gregw)

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class

Field Summary

Modifier and TypeField and Description
private Object
o

Inherited from java.util.AbstractList:
modCount

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public Object
get(int
index of the element to return
i
)

Implements abstract java.util.AbstractList.get.

Implements java.util.List.get.

Returns the element at the specified position in this list.
public Iterator<E>
iterator()

Overrides java.util.AbstractList.iterator.

Implements java.util.List.iterator, java.util.Collection.iterator.

Returns an iterator over the elements in this list in proper sequence.
public ListIterator<E>
listIterator()

Overrides java.util.AbstractList.listIterator.

Implements java.util.List.listIterator.

Returns a list iterator over the elements in this list (in proper sequence).
public ListIterator<E>
listIterator(int
index of the first element to be returned from the list iterator (by a call to next)
i
)

Overrides java.util.AbstractList.listIterator.

Implements java.util.List.listIterator.

Returns a list iterator over the elements in this list (in proper sequence), starting at the specified position in the list.
public static SingletonList
public int
size()

Implements abstract java.util.AbstractCollection.size.

Implements java.util.List.size, java.util.Collection.size.

Returns the number of elements in this list.
Inherited from java.util.AbstractList:
addaddaddAllclearequalshashCodeindexOflastIndexOfremoveremoveRangesetsubList

Field Detail

oback to summary
private Object o

Constructor Detail

SingletonListback to summary
private SingletonList(Object o)

Method Detail

getback to summary
public Object get(int i)

Implements abstract java.util.AbstractList.get.

Implements java.util.List.get.

Doc from java.util.AbstractList.get.

Returns the element at the specified position in this list.

Parameters
i:int

Doc from java.util.List.get.

index of the element to return

Returns:Object

Doc from java.util.List.get.

the element at the specified position in this list

iteratorback to summary
public Iterator<E> iterator()

Overrides java.util.AbstractList.iterator.

Implements java.util.List.iterator, java.util.Collection.iterator.

Doc from java.util.AbstractList.iterator.

Returns an iterator over the elements in this list in proper sequence.

Returns:Iterator<E>

an iterator over the elements in this list in proper sequence

listIteratorback to summary
public ListIterator<E> listIterator()

Overrides java.util.AbstractList.listIterator.

Implements java.util.List.listIterator.

Doc from java.util.AbstractList.listIterator.

Returns a list iterator over the elements in this list (in proper sequence).

Returns:ListIterator<E>

Doc from java.util.List.listIterator.

a list iterator over the elements in this list (in proper sequence)

listIteratorback to summary
public ListIterator<E> listIterator(int i)

Overrides java.util.AbstractList.listIterator.

Implements java.util.List.listIterator.

Doc from java.util.AbstractList.listIterator.

Returns a list iterator over the elements in this list (in proper sequence), starting at the specified position in the list. The specified index indicates the first element that would be returned by an initial call to next. An initial call to previous would return the element with the specified index minus one.

Parameters
i:int

Doc from java.util.List.listIterator.

index of the first element to be returned from the list iterator (by a call to next)

Returns:ListIterator<E>

Doc from java.util.List.listIterator.

a list iterator over the elements in this list (in proper sequence), starting at the specified position in the list

newSingletonListback to summary
public static SingletonList newSingletonList(Object o)
sizeback to summary
public int size()

Implements abstract java.util.AbstractCollection.size.

Implements java.util.List.size, java.util.Collection.size.

Doc from java.util.List.size.

Returns the number of elements in this list. If this list contains more than Integer.MAX_VALUE elements, returns Integer.MAX_VALUE.

Returns:int

the number of elements in this list

org.mortbay.util back to summary

private Class SingletonList.SIterator

extends Object
implements ListIterator
Class Inheritance
All Implemented Interfaces
java.util.ListIterator, java.util.Iterator

Field Summary

Modifier and TypeField and Description
pack-priv int
i

Constructor Summary

AccessConstructor and Description
pack-priv
pack-priv
SIterator(int i)

Method Summary

Modifier and TypeMethod and Description
public void
add(Object
the element to insert
o
)

Implements java.util.ListIterator.add.

Inserts the specified element into the list (optional operation).
public boolean
hasNext()

Implements java.util.ListIterator.hasNext.

Returns true if this list iterator has more elements when traversing the list in the forward direction.
public boolean
hasPrevious()

Implements java.util.ListIterator.hasPrevious.

Returns true if this list iterator has more elements when traversing the list in the reverse direction.
public Object
next()

Implements java.util.ListIterator.next.

Returns the next element in the list and advances the cursor position.
public int
nextIndex()

Implements java.util.ListIterator.nextIndex.

Returns the index of the element that would be returned by a subsequent call to next.
public Object
previous()

Implements java.util.ListIterator.previous.

Returns the previous element in the list and moves the cursor position backwards.
public int
previousIndex()

Implements java.util.ListIterator.previousIndex.

Returns the index of the element that would be returned by a subsequent call to previous.
public void
remove()

Implements java.util.ListIterator.remove.

Removes from the list the last element that was returned by next or previous (optional operation).
public void
set(Object
the element with which to replace the last element returned by next or previous
o
)

Implements java.util.ListIterator.set.

Replaces the last element returned by next or previous with the specified element (optional operation).
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

iback to summary
pack-priv int i

Constructor Detail

SIteratorback to summary
pack-priv SIterator()
SIteratorback to summary
pack-priv SIterator(int i)

Method Detail

addback to summary
public void add(Object o)

Implements java.util.ListIterator.add.

Doc from java.util.ListIterator.add.

Inserts the specified element into the list (optional operation). The element is inserted immediately before the element that would be returned by next, if any, and after the element that would be returned by previous, if any. (If the list contains no elements, the new element becomes the sole element on the list.) The new element is inserted before the implicit cursor: a subsequent call to next would be unaffected, and a subsequent call to previous would return the new element. (This call increases by one the value that would be returned by a call to nextIndex or previousIndex.)

Parameters
o:Object

the element to insert

hasNextback to summary
public boolean hasNext()

Implements java.util.ListIterator.hasNext.

Doc from java.util.ListIterator.hasNext.

Returns true if this list iterator has more elements when traversing the list in the forward direction. (In other words, returns true if next would return an element rather than throwing an exception.)

Returns:boolean

true if the list iterator has more elements when traversing the list in the forward direction

hasPreviousback to summary
public boolean hasPrevious()

Implements java.util.ListIterator.hasPrevious.

Doc from java.util.ListIterator.hasPrevious.

Returns true if this list iterator has more elements when traversing the list in the reverse direction. (In other words, returns true if previous would return an element rather than throwing an exception.)

Returns:boolean

true if the list iterator has more elements when traversing the list in the reverse direction

nextback to summary
public Object next()

Implements java.util.ListIterator.next.

Doc from java.util.ListIterator.next.

Returns the next element in the list and advances the cursor position. This method may be called repeatedly to iterate through the list, or intermixed with calls to previous to go back and forth. (Note that alternating calls to next and previous will return the same element repeatedly.)

Returns:Object

the next element in the list

nextIndexback to summary
public int nextIndex()

Implements java.util.ListIterator.nextIndex.

Doc from java.util.ListIterator.nextIndex.

Returns the index of the element that would be returned by a subsequent call to next. (Returns list size if the list iterator is at the end of the list.)

Returns:int

the index of the element that would be returned by a subsequent call to next, or list size if the list iterator is at the end of the list

previousback to summary
public Object previous()

Implements java.util.ListIterator.previous.

Doc from java.util.ListIterator.previous.

Returns the previous element in the list and moves the cursor position backwards. This method may be called repeatedly to iterate through the list backwards, or intermixed with calls to next to go back and forth. (Note that alternating calls to next and previous will return the same element repeatedly.)

Returns:Object

the previous element in the list

previousIndexback to summary
public int previousIndex()

Implements java.util.ListIterator.previousIndex.

Doc from java.util.ListIterator.previousIndex.

Returns the index of the element that would be returned by a subsequent call to previous. (Returns -1 if the list iterator is at the beginning of the list.)

Returns:int

the index of the element that would be returned by a subsequent call to previous, or -1 if the list iterator is at the beginning of the list

removeback to summary
public void remove()

Implements java.util.ListIterator.remove.

Doc from java.util.ListIterator.remove.

Removes from the list the last element that was returned by next or previous (optional operation). This call can only be made once per call to next or previous. It can be made only if add has not been called after the last call to next or previous.

setback to summary
public void set(Object o)

Implements java.util.ListIterator.set.

Doc from java.util.ListIterator.set.

Replaces the last element returned by next or previous with the specified element (optional operation). This call can be made only if neither remove nor add have been called after the last call to next or previous.

Parameters
o:Object

the element with which to replace the last element returned by next or previous