|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.mattbusche.util.partition.Domain<M,V>
public class Domain<M,V>
A resizable array of Entry<M>
objects having
sequentially numbered IDs which may be partitioned across an arbitrary
number of associated Group
s.
Read the package summary for
introductory information about Domain
and its related
classes.
The ID of the first Entry
object (being the
Entry
with the lowest numbered ID in the
Domain
's internal array) may have an arbitrary value and is
tracked by min()
. The ID of the
last Entry
object (being the Entry
with the
highest numbered ID in the Domain's internal array) is given by min()+size()-1
. This
internal array may be dynamically resized in either direction (either by
adding entries after the end of the array which increases the maximum ID
or by adding entries before the beginning of the array which decreases the
minimum ID).
The methods
addEntry()
,
compact()
,
reserve()
, and
resize()
(and their
overloaded variants) are the operations that can result in memory
reallocation. Memory reallocation does not disturb Group membership nor
does it invalidate GroupIterators.
Constructor Summary | |
---|---|
Domain()
Constructs an empty Domain . |
|
Domain(Domain<M,V> d)
Constructs a Domain that is a copy of d . |
|
Domain(int size)
Constructs a Domain with size Entry objects having IDs ranging from 0 to
size-1 . |
|
Domain(int size,
int min)
Constructs a Domain with size
Entry objects having IDs ranging from min to
min+size-1 . |
Method Summary | |
---|---|
void |
addEntry(int id)
Equivalent to addEntry(id, null) . |
void |
addEntry(int id,
M member)
Similar to setMember(id, member) but will resize
this Domain as neccessary to accomodate the given
id . |
int |
capacity()
Returns high() - low() . |
void |
compact()
If the capacity of the Domain exceeds its size() , then
compact reallocates internal storage reducing capacity to match the
current size of the Domain. |
Entry<M> |
getEntry(int id)
Returns the Entry object with the given id . |
Group<M,V> |
getGroup(int id)
Returns the Group to which the Entry with given
id belongs or null if that member belongs to
no Group . |
M |
getMember(int id)
Returns the member object associated with the given id . |
V |
getValue(int id)
Returns the value of the Group to which the
Entry with the given id belongs. |
int |
high()
Returns one plus the highest numbered ID that can be added to the Domain without memory reallocation. |
int |
low()
Returns the lowest numbered ID that can be added to the Domain without memory reallocation. |
int |
min()
Returns the lowest numbered ID of this Domain . |
void |
reserve(int newHigh)
Equivalent to reserve(newHigh, low()) . |
void |
reserve(int newHigh,
int newLow)
If either high() < newHigh or low()
> newLow , then the internal array is reallocated so
that high is increased to at least newHigh
and low is reduced to at most newLow . |
void |
resize(int newSize)
Equivalent to resize(newSize, min()) |
void |
resize(int newSize,
int newMin)
Resizes this Domain to contain newSize
Entry objects with IDs ranging from newMin to
newMin+newSize-1 . |
void |
setMember(int id,
M m)
Finds the Entry in this Domain with the given
ID and sets its member field to m . |
int |
size()
Returns the number of Entry objects in this
Domain |
java.lang.String |
toString()
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public Domain()
Constructs an empty Domain
. The Domain
's
min property is set to 0.
public Domain(int size)
Constructs a Domain
with size
Entry
objects having IDs ranging from 0
to
size-1
. All Entry
member fields are
initialized to null
.
PartitionException
- if size
is negative.public Domain(int size, int min)
Constructs a Domain
with size
Entry
objects having IDs ranging from min
to
min+size-1
. All Entry
member fields are
initialized to null
PartitionException
- if size
is negative.public Domain(Domain<M,V> d)
Constructs a Domain
that is a copy of d
.
Members are only copied by reference (not a deep copy or clone). The
capacity of the new Domain
matches the size of the
original (minimizing storage requirements for the copy).
java.lang.NullPointerException
- if d
is null
.Method Detail |
---|
public int size()
Returns the number of Entry
objects in this
Domain
public int min()
Returns the lowest numbered ID of this Domain
.
public Group<M,V> getGroup(int id)
Returns the Group
to which the Entry
with given
id
belongs or null
if that member belongs to
no Group
.
Computational Complexity: Constant.
PartitionException
- if id
is less than min()
or greater than min()
+size()
-1
.public V getValue(int id)
Returns the value of the Group
to which the
Entry
with the given id
belongs. Equivalent
to getGroup(id)
.getValue()
.
Computational Complexity: Constant.
PartitionException
- if id
is less than min()
or greater than min()
+size()
-1
.
java.lang.NullPointerException
- if the Entry
with the given
id
belongs to no Group
.public M getMember(int id)
Returns the member object associated with the given id
.
Computational Complexity: Constant.
PartitionException
- if id
is less than min()
or greater than min()
+size()
-1
.public void setMember(int id, M m)
Finds the Entry
in this Domain
with the given
ID and sets its member field to m
.
Computational Complexity: Constant.
PartitionException
- if id
is less than min()
or greater than min()
+size()
-1
.public Entry<M> getEntry(int id)
Returns the Entry
object with the given id
.
Computational Complexity: Constant.
PartitionException
- if id
is less than min()
or greater than min()
+size()
-1
.public void addEntry(int id)
Equivalent to addEntry(id, null)
.
public void addEntry(int id, M member)
Similar to setMember(id, member)
but will resize
this Domain
as neccessary to accomodate the given
id
. If the Domain
has size zero or if
id
is less than the current min
, then min
is set to id
. If the Domain
has capacity
zero, then both min
and low
are set to
id
.
public void resize(int newSize)
Equivalent to resize(newSize, min())
public void resize(int newSize, int newMin)
Resizes this Domain
to contain newSize
Entry
objects with IDs ranging from newMin
to
newMin+newSize-1
.
Previously existing Entry objects having IDs that fall in this newly defined range have both their member fields as well as their group memberships preserved.
Previously existing Entry
objects having IDs that fall
outside this newly defined range are removed from their
Group
s and have internal references to the
Entry
removed.
If newMin
< low()
or newMin+newSize
>
then resize will perform a reallocation to
accomodate the requested high()
Entry
range.
PartitionException
- if newSize
is negative.public int high()
Returns one plus the highest numbered ID that can be added to the
Domain
without memory reallocation.
public int low()
Returns the lowest numbered ID that can be added to the
Domain
without memory reallocation.
public int capacity()
public void reserve(int newHigh)
Equivalent to reserve(newHigh, low())
.
public void reserve(int newHigh, int newLow)
If either high()
< newHigh
or low()
> newLow
, then the internal array is reallocated so
that high
is increased to at least newHigh
and low
is reduced to at most newLow
. After
the call, IDs from newLow
to newHigh-1
may
subsequently added to the Domain
without additional
reallocations.
PartitionException
- if newHigh
is less than
newLow
.public void compact()
If the capacity of the Domain exceeds its size()
, then
compact reallocates internal storage reducing capacity to match the
current size of the Domain.
public java.lang.String toString()
toString
in class java.lang.Object
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |