|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.threerings.presents.dobj.DSet<E>
E - the type of entry stored in this set.public class DSet<E extends DSet.Entry>
The distributed set class provides a means by which an unordered set of objects can be maintained as a distributed object field. Entries can be added to and removed from the set, requests for which will generate events much like other distributed object fields.
Classes that wish to act as set entries must implement the DSet.Entry interface which
extends Streamable and adds the requirement that the object provide a key which will be
used to identify entry equality. Thus an entry is declared to be in a set of the object returned
by that entry's DSet.Entry.getKey() method is equal (using Object.equals(java.lang.Object)) to the entry
returned by the DSet.Entry.getKey() method of some other entry in the set. Additionally, in the
case of entry removal, only the key for the entry to be removed will be transmitted with the
removal event to save network bandwidth. Lastly, the object returned by DSet.Entry.getKey()
must be a Streamable type.
| Nested Class Summary | |
|---|---|
static interface |
DSet.Entry
Entries of the set must implement this interface. |
| Field Summary | |
|---|---|
protected E[] |
_entries
The entries of the set (in a sparse array). |
protected int |
_modCount
Used to check for concurrent modification. |
protected int |
_size
The number of entries in this set. |
protected static Comparator<DSet.Entry> |
ENTRY_COMP
Used for lookups and to keep the set contents sorted on insertions. |
protected static int |
INITIAL_CAPACITY
The default capacity of a set instance. |
| Constructor Summary | |
|---|---|
DSet()
Constructs an empty distributed set. |
|
DSet(E[] source)
Creates a distributed set and populates it with values from the supplied array. |
|
DSet(Iterable<E> source)
Creates a distributed set and populates it with values from the supplied iterator. |
|
DSet(Iterator<E> source)
Creates a distributed set and populates it with values from the supplied iterator. |
|
| Method Summary | ||
|---|---|---|
protected boolean |
add(E elem)
Adds the specified entry to the set. |
|
Set<E> |
asSet()
Creates an immutable view of this distributed set as a Java set. |
|
DSet<E> |
clone()
Generates a shallow copy of this object. |
|
static int |
compare(Comparable<?> c1,
Comparable<?> c2)
Compares the first comparable to the second. |
|
boolean |
contains(E elem)
Returns true if the set contains an entry whose getKey() method returns a key
that equals() the key returned by getKey() of the supplied
entry. |
|
boolean |
containsKey(Comparable<?> key)
Returns true if an entry in the set has a key that equals() the supplied
key. |
|
Iterator<E> |
entries()
Deprecated. |
|
E |
get(Comparable<?> key)
Returns the entry that matches ( getKey().equals(key)) the specified key or null
if no entry could be found that matches the key. |
|
protected int |
getWarningSize()
Returns the minimum size where we should warn that we're getting a bit large. |
|
Iterator<E> |
iterator()
Returns an iterator over the entries of this set. |
|
static
|
newDSet()
Creates a new DSet of the appropriate generic type. |
|
static
|
newDSet(Iterable<E> source)
Creates a new DSet of the appropriate generic type. |
|
void |
readObject(ObjectInputStream in)
Custom reader method. |
|
protected boolean |
remove(E elem)
Removes the specified entry from the set. |
|
protected E |
removeKey(Comparable<?> key)
Removes from the set the entry whose key matches the supplied key. |
|
int |
size()
Returns the number of entries in this set. |
|
E[] |
toArray(E[] array)
Copies the elements of this distributed set into the supplied array. |
|
Object[] |
toArray(Object[] array)
Deprecated. use toArray(Entry[]). |
|
String |
toString()
|
|
DSet<E> |
typedClone()
Deprecated. clone() works just fine now. |
|
protected E |
update(E elem)
Updates the specified entry by locating an entry whose key matches the key of the supplied entry and overwriting it. |
|
void |
writeObject(ObjectOutputStream out)
Custom writer method. |
|
| Methods inherited from class java.lang.Object |
|---|
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
protected E extends DSet.Entry[] _entries
protected int _size
protected transient int _modCount
protected static final int INITIAL_CAPACITY
protected static Comparator<DSet.Entry> ENTRY_COMP
| Constructor Detail |
|---|
public DSet(Iterable<E> source)
source - an iterator from which we will initially populate the set.public DSet(Iterator<E> source)
source - an iterator from which we will initially populate the set.public DSet(E[] source)
source - an array from which we will initially populate the set.public DSet()
| Method Detail |
|---|
public static <E extends DSet.Entry> DSet<E> newDSet()
public static <E extends DSet.Entry> DSet<E> newDSet(Iterable<E> source)
public static int compare(Comparable<?> c1,
Comparable<?> c2)
DSet.Entry values.
public int size()
public boolean contains(E elem)
getKey() method returns a key
that equals() the key returned by getKey() of the supplied
entry. Returns false otherwise.
public boolean containsKey(Comparable<?> key)
equals() the supplied
key. Returns false otherwise.
public E get(Comparable<?> key)
getKey().equals(key)) the specified key or null
if no entry could be found that matches the key.
@Deprecated public Iterator<E> entries()
public Iterator<E> iterator()
iterator in interface Iterable<E extends DSet.Entry>public E[] toArray(E[] array)
array argument is null, an object array of sufficient size to contain all
of the elements of this set will be created and returned.
public Set<E> asSet()
@Deprecated public Object[] toArray(Object[] array)
toArray(Entry[]).
protected boolean add(E elem)
addTo{Set}() method should be called on the distributed object that
contains the set in question.
protected boolean remove(E elem)
removeFrom{Set}() method should be called on the distributed object
that contains the set in question.
protected E removeKey(Comparable<?> key)
removeFrom{Set}() method should be called on
the distributed object that contains the set in question.
protected E update(E elem)
update{Set}() method should be called on the distributed object that contains
the set in question.
protected int getWarningSize()
@Deprecated public DSet<E> typedClone()
public DSet<E> clone()
clone in class Objectpublic String toString()
toString in class Object
public void writeObject(ObjectOutputStream out)
throws IOException
IOException
public void readObject(ObjectInputStream in)
throws IOException,
ClassNotFoundException
IOException
ClassNotFoundException
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||