Rice Pastry API

rice.pastry
Class NodeSet

java.lang.Object
  extended by rice.pastry.NodeSet
All Implemented Interfaces:
java.io.Serializable, NodeHandleSet, NodeSetI

public class NodeSet
extends java.lang.Object
implements NodeSetI, java.io.Serializable

Represents an ordered set of NodeHandles. *

Version:
$Id: NodeSet.java 4654 2009-01-08 16:33:07Z jeffh $
Author:
Peter Druschel
See Also:
Serialized Form

Field Summary
static short TYPE
           
 
Constructor Summary
NodeSet()
          Constructor.
NodeSet(InputBuffer buf, NodeHandleFactory nhf)
           
NodeSet(NodeSet o)
          Copy constructor.
NodeSet(java.util.Vector<NodeHandle> s)
          Constructor.
 
Method Summary
 NodeHandle get(Id nid)
          Finds the NodeHandle associated with a NodeId.
 NodeHandle get(int i)
          Gets the ith element in the set.
 java.util.Collection<NodeHandle> getCollection()
           
 NodeHandle getHandle(Id id)
          Finds the NodeHandle associated with the NodeId.
 NodeHandle getHandle(int i)
          Gets the ith element in the set.
 int getIndex(Id nid)
          Gets the index of the element with the given node id.
 int getIndex(NodeHandle nh)
           
 int getIndexHandle(Id id)
          Gets the index of the element with the given node id.
 java.util.Iterator<NodeHandle> getIterator()
          return an iterator that iterates over the elements of this set
 short getType()
           
 int indexOf(NodeHandle handle)
          determine rank of a member
 boolean insert(int index, NodeHandle handle)
          insert a member at the given index
 java.util.Iterator<NodeHandle> iterator()
           
 boolean member(NodeHandle handle)
          test membership
 boolean memberHandle(Id id)
          Verifies if the set contains this particular id.
 boolean put(NodeHandle handle)
          Appends a member to the ordered set.
 boolean putHandle(NodeHandle handle)
          Puts a NodeHandle into the set.
 void randomize(RandomSource random)
          Method which randomizes the order of this NodeSet
 NodeHandle remove(Id nid)
          Removes a node id and its handle from the set.
 void remove(int index)
          remove a member at a given position
 NodeHandle remove(NodeHandle handle)
          remove a member
 NodeHandle removeHandle(Id id)
          Removes a node id and its handle from the set.
 void serialize(OutputBuffer buf)
           
 int size()
          Gets the number of elements.
 java.lang.String toString()
          Returns a string representation of the NodeSet
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

TYPE

public static final short TYPE
See Also:
Constant Field Values
Constructor Detail

NodeSet

public NodeSet()
Constructor.


NodeSet

public NodeSet(java.util.Vector<NodeHandle> s)
Constructor.


NodeSet

public NodeSet(NodeSet o)
Copy constructor.


NodeSet

public NodeSet(InputBuffer buf,
               NodeHandleFactory nhf)
        throws java.io.IOException
Throws:
java.io.IOException
Method Detail

put

public boolean put(NodeHandle handle)
Appends a member to the ordered set.

Specified by:
put in interface NodeSetI
Parameters:
handle - the handle to put.
Returns:
false if handle was already a member, true otherwise

randomize

public void randomize(RandomSource random)
Method which randomizes the order of this NodeSet


get

public NodeHandle get(Id nid)
Finds the NodeHandle associated with a NodeId.

Specified by:
get in interface NodeSetI
Parameters:
nid - a node id.
Returns:
the handle associated with that id or null if no such handle is found.

get

public NodeHandle get(int i)
Gets the ith element in the set.

Specified by:
get in interface NodeSetI
Parameters:
i - an index.
Returns:
the handle, or null if the position is out of bounds

remove

public NodeHandle remove(Id nid)
Removes a node id and its handle from the set.

Parameters:
nid - the node to remove.
Returns:
the node handle removed or null if nothing.

size

public int size()
Gets the number of elements.

Specified by:
size in interface NodeHandleSet
Specified by:
size in interface NodeSetI
Returns:
the size.

getIndex

public int getIndex(Id nid)
Gets the index of the element with the given node id.

Specified by:
getIndex in interface NodeSetI
Parameters:
nid - the node id.
Returns:
the index or -1 if no such element

getIndex

public int getIndex(NodeHandle nh)
Specified by:
getIndex in interface NodeSetI

insert

public boolean insert(int index,
                      NodeHandle handle)
insert a member at the given index

Parameters:
index - the position at which to insert the element into the ordered set
handle - the handle to add
Returns:
false if handle was already a member, true otherwise

remove

public NodeHandle remove(NodeHandle handle)
remove a member

Specified by:
remove in interface NodeSetI
Parameters:
handle - the handle to remove
Returns:
the node handle removed or null if nothing.

remove

public void remove(int index)
remove a member at a given position

Parameters:
index - the position of the member to remove

indexOf

public int indexOf(NodeHandle handle)
determine rank of a member

Parameters:
handle - the handle to test
Returns:
rank (index) of the handle, or -1 if handle is not a member

member

public boolean member(NodeHandle handle)
test membership

Specified by:
member in interface NodeSetI
Parameters:
handle - the handle to test
Returns:
true of handle is a member, false otherwise

getIterator

public java.util.Iterator<NodeHandle> getIterator()
return an iterator that iterates over the elements of this set

Returns:
the iterator

toString

public java.lang.String toString()
Returns a string representation of the NodeSet

Overrides:
toString in class java.lang.Object

putHandle

public boolean putHandle(NodeHandle handle)
Puts a NodeHandle into the set.

Specified by:
putHandle in interface NodeHandleSet
Parameters:
handle - the handle to put.
Returns:
true if the put succeeded, false otherwise.

getHandle

public NodeHandle getHandle(Id id)
Finds the NodeHandle associated with the NodeId.

Specified by:
getHandle in interface NodeHandleSet
Parameters:
id - a node id.
Returns:
the handle associated with that id or null if no such handle is found.

getHandle

public NodeHandle getHandle(int i)
Gets the ith element in the set.

Specified by:
getHandle in interface NodeHandleSet
Parameters:
i - an index.
Returns:
the handle associated with that id or null if no such handle is found.

memberHandle

public boolean memberHandle(Id id)
Verifies if the set contains this particular id.

Specified by:
memberHandle in interface NodeHandleSet
Parameters:
id - a node id.
Returns:
true if that node id is in the set, false otherwise.

removeHandle

public NodeHandle removeHandle(Id id)
Removes a node id and its handle from the set.

Specified by:
removeHandle in interface NodeHandleSet
Parameters:
nid - the node to remove.
Returns:
the node handle removed or null if nothing.

getIndexHandle

public int getIndexHandle(Id id)
                   throws java.util.NoSuchElementException
Gets the index of the element with the given node id.

Specified by:
getIndexHandle in interface NodeHandleSet
Parameters:
id - the id.
Returns:
the index or throws a NoSuchElementException.
Throws:
java.util.NoSuchElementException

iterator

public java.util.Iterator<NodeHandle> iterator()

serialize

public void serialize(OutputBuffer buf)
               throws java.io.IOException
Specified by:
serialize in interface NodeHandleSet
Throws:
java.io.IOException

getType

public short getType()
Specified by:
getType in interface NodeHandleSet

getCollection

public java.util.Collection<NodeHandle> getCollection()

Rice Pastry API

Copyright © 2001-2005 - Rice Pastry.


Imprint-Dataprotection