|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectbb.util.ListWithIndex
public class ListWithIndex
Contains an internal List, as well as keeps track of the current position (index) in the List. Elements are gotten, added, or removed from the current index. The index is -1 if the List has size 0.
This component is a Java Bean, and supports "index" as a bound property. See the Sun tutorial for details. Implementation note: must always use the setIndex method to change the index field to guarantee proper index event firing.
This class is not multithread safe.
Field Summary | |
---|---|
private PropertyChangeSupport |
changes
|
private int |
index
|
private List<Object> |
list
|
Constructor Summary | |
---|---|
ListWithIndex()
|
Method Summary | |
---|---|
void |
add(Object obj)
Inserts obj into the List right after the element that index currently points to. |
void |
addPropertyChangeListener(PropertyChangeListener listener)
|
void |
decrementIndex()
If hasPrevious() returns true, then this method decrements index. |
Object |
get()
Returns the element at index. |
Object |
getAtOffset(int offset)
Returns the element at index + offset. |
int |
getIndex()
Returns the current value of index. |
List<Object> |
getList()
Returns a new List instance which contains all the elements currently in the internal List. |
boolean |
hasAtOffset(int offset)
Reports whether or not there is an element at index + offset. |
boolean |
hasNext()
Reports whether or not there is an element after the current value of index. |
boolean |
hasPrevious()
Reports whether or not there is an element before the current value of index. |
void |
incrementIndex()
If hasNext() returns true, then this method increments index. |
void |
offsetIndex(int offset)
Changes index to index + offset. |
Object |
remove()
Removes the element at index from the list. |
void |
removePropertyChangeListener(PropertyChangeListener listener)
|
void |
setIndex(int index)
Assigns the current value of index. |
int |
size()
Returns the size of the internal List. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private final List<Object> list
private final PropertyChangeSupport changes
private int index
Constructor Detail |
---|
public ListWithIndex()
Method Detail |
---|
public Object get() throws IllegalStateException
IllegalStateException
- if list.size() == 0public Object getAtOffset(int offset) throws IllegalStateException
IllegalStateException
- if hasAtOffset(offset) returns falsepublic void add(Object obj)
obj
- any Object, including nullpublic Object remove() throws IllegalStateException
IllegalStateException
- if list.size() == 0public int size()
public List<Object> getList()
public int getIndex()
public void setIndex(int index) throws IllegalStateException
IllegalStateException
- if list.size() == 0 && index != -1;
list.size() > 0 && index < 0; index >= list.size()public void offsetIndex(int offset) throws IllegalStateException
IllegalStateException
- if setIndex objects to index + offset as a new indexpublic void incrementIndex()
public void decrementIndex()
public boolean hasPrevious()
public boolean hasNext()
public boolean hasAtOffset(int offset)
public void addPropertyChangeListener(PropertyChangeListener listener) throws IllegalArgumentException
IllegalArgumentException
public void removePropertyChangeListener(PropertyChangeListener listener) throws IllegalArgumentException
IllegalArgumentException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |