|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.mattbusche.util.partition.GroupIterator<M,V>
public class GroupIterator<M,V>
A bidirectional iterator for traversing the Entry
objects of a
Group
.
GroupIterator
design differs significantly from the design
of iterators in the Java Collections Framework (JCF):
GroupIterator
s point to a particular list
Entry
. In contrast, iterators from the JCF point
between two list entries.GroupIterator
s are only invalidated by those operations
that remove the Entry
they point to from their
Group
. In particular, memory reallocation events do not
invalidate GroupIterator
s. In contrast, any update to a JCF
container necessarily invalidates all iterators on that container except
the one iterator used to perform that update (if any).GroupIterator
is
undefined. In contrast, any use of an invalidated iterator from the JCF,
results in the well-defined behavior of throwing a
ConcurrentModificationException
.Because GroupIterator
s point to a particular list entry
and because they are not regularly invalidated, they can be used as
semi-permanent references to Group entries. This is at the cost of user
safety: accidental use of an invalidated iterator will not produce an
exception, but instead has undefined behavior.
Notes on GroupIterator invalidation:
The behavior of an invalidated GroupIterator
is undefined
so one must take care to avoid unintentional iterator invalidation. For
this Java-based implementation of partition, the only way a
GroupIterator
can become invalidated is for the
Entry
pointed to by the GroupIterator
to be
removed from its Group
. This may seem obvious, but remember
that any operation that inserts an Entry
to a
Group
also removes that same Entry
from its
previous Group
; so all operations that affect
Group
membership can invalidate GroupIterator
s.
Also note that the Domain
's resize methods can be used to
eliminate Entry
s from the Domain
entirely (and
from their Group
s).
Constructor Summary | |
---|---|
GroupIterator(GroupIterator<M,V> iter)
Copy constructor. |
Method Summary | |
---|---|
void |
addAfter(int id)
Removes the Entry with the given id from the
Group with which it was previously a member (if any), and adds
it into this iterator's Group immediately after the
position pointed to by this iterator. |
void |
addBefore(int id)
Removes the Entry with the given id from the
Group with which it was previously a member (if any), and adds
it into this iterator's Group immediately before the
position pointed to by this iterator. |
GroupIterator<M,V> |
dec()
Decrements the iterator to the previous list position and returns a reference to itself. |
Group<M,V> |
getContainer()
Returns the Group associated with this iterator. |
Entry<M> |
getEntry()
Returns the Entry object pointed to by this iterator. |
GroupIterator<M,V> |
inc()
Increments the iterator to the next list position and returns a reference to itself. |
boolean |
isAfterBack()
Returns true if this iterator is pointing one logical
position after the last Entry in the list, and
false if it is pointing to any list Entry . |
boolean |
isAtBack()
Returns true if this iterator points to the last Entry of a non-empty list, or to the beforeFront position of an empty
list; and false otherwise. |
boolean |
isAtFront()
Returns true if this iterator points to the first
Entry of a non-empty list, or to the afterBack position
of an empty list; and false otherwise. |
boolean |
isBeforeFront()
Returns true if this iterator is pointing one logical
position before the first Entry in the list, and
false if it is pointing to any list Entry . |
Entry<M> |
removeAndDec()
Removes and returns the Entry pointed to by this iterator
from its Group 's list, and updates this iterator to point to
the previous Entry in the list. |
Entry<M> |
removeAndInc()
Removes and returns the Entry pointed to by this iterator
from its Group 's list, and updates this iterator to point to
the next Entry in the list. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public GroupIterator(GroupIterator<M,V> iter)
Method Detail |
---|
public GroupIterator<M,V> inc()
public GroupIterator<M,V> dec()
public boolean isBeforeFront()
true
if this iterator is pointing one logical
position before the first Entry
in the list, and
false
if it is pointing to any list Entry
.
public boolean isAfterBack()
true
if this iterator is pointing one logical
position after the last Entry
in the list, and
false
if it is pointing to any list Entry
.
public boolean isAtFront()
true
if this iterator points to the first
Entry
of a non-empty list, or to the afterBack position
of an empty list; and false
otherwise.
public boolean isAtBack()
true
if this iterator points to the last Entry
of a non-empty list, or to the beforeFront position of an empty
list; and false
otherwise.
public Entry<M> getEntry()
Entry
object pointed to by this iterator.
PartitionException
- if this iterator isBeforeFront()
or
isAfterBack()
.public Group<M,V> getContainer()
Group
associated with this iterator.
public void addBefore(int id)
Removes the Entry
with the given id
from the
Group
with which it was previously a member (if any), and adds
it into this iterator's Group
immediately before the
position pointed to by this iterator.
Computational Complexity: Constant.
java.lang.NullPointerException
- if this iterator's Group
is
not associated with a Domain
.
ArrayIndexOutOfBoundException
- if id
is not a
member of the associated Domain.public void addAfter(int id)
Removes the Entry
with the given id
from the
Group
with which it was previously a member (if any), and adds
it into this iterator's Group
immediately after the
position pointed to by this iterator.
Computational Complexity: Constant.
java.lang.NullPointerException
- if this iterator's Group
is
not associated with a Domain
.
ArrayIndexOutOfBoundException
- if id
is not a
member of the associated Domain
.public Entry<M> removeAndInc()
Removes and returns the Entry
pointed to by this iterator
from its Group
's list, and updates this iterator to point to
the next Entry
in the list.
Computational Complexity: Constant.
PartitionException
- if this iterator isBeforeFront()
or
isAfterBack()
.public Entry<M> removeAndDec()
Removes and returns the Entry
pointed to by this iterator
from its Group
's list, and updates this iterator to point to
the previous Entry
in the list.
Computational Complexity: Constant.
PartitionException
- if this iterator isBeforeFront()
or
isAfterBack()
.
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |