Rice Pastry API

rice.pastry
Class NodeSet

java.lang.Object
  |
  +--rice.pastry.NodeSet
All Implemented Interfaces:
NodeHandleSet, NodeSetI, java.io.Serializable

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

Represents an ordered set of NodeHandles. *

Version:
$Id: NodeSet.java,v 1.10 2003/07/28 21:48:10 amislove Exp $
Author:
Peter Druschel
See Also:
Serialized Form

Constructor Summary
NodeSet()
          Constructor.
NodeSet(rice.pastry.NodeSet o)
          Copy constructor.
NodeSet(java.util.Vector s)
          Constructor.
 
Method Summary
 rice.pastry.NodeHandle get(int i)
          Gets the ith element in the set.
 rice.pastry.NodeHandle get(rice.pastry.NodeId nid)
          Finds the NodeHandle associated with a NodeId.
 rice.p2p.commonapi.NodeHandle getHandle(rice.p2p.commonapi.Id id)
          Finds the NodeHandle associated with the NodeId.
 rice.p2p.commonapi.NodeHandle getHandle(int i)
          Gets the ith element in the set.
 int getIndex(rice.pastry.NodeId nid)
          Gets the index of the element with the given node id.
 int getIndexHandle(rice.p2p.commonapi.Id id)
          Gets the index of the element with the given node id.
 java.util.Iterator getIterator()
          return an iterator that iterates over the elements of this set
 int indexOf(rice.pastry.NodeHandle handle)
          determine rank of a member
 boolean insert(int index, rice.pastry.NodeHandle handle)
          insert a member at the given index
 boolean member(rice.pastry.NodeHandle handle)
          test membership
 boolean member(rice.pastry.NodeId nid)
          test membership using Id
 boolean memberHandle(rice.p2p.commonapi.Id id)
          Verifies if the set contains this particular id.
 boolean put(rice.pastry.NodeHandle handle)
          Appends a member to the ordered set.
 boolean putHandle(rice.p2p.commonapi.NodeHandle handle)
          Puts a NodeHandle into the set.
 void remove(int index)
          remove a member at a given position
 void remove(rice.pastry.NodeHandle handle)
          remove a member
 rice.pastry.NodeHandle remove(rice.pastry.NodeId nid)
          Removes a node id and its handle from the set.
 rice.p2p.commonapi.NodeHandle removeHandle(rice.p2p.commonapi.Id id)
          Removes a node id and its handle from the set.
 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
 

Constructor Detail

NodeSet

public NodeSet()
Constructor.


NodeSet

public NodeSet(java.util.Vector s)
Constructor.


NodeSet

public NodeSet(rice.pastry.NodeSet o)
Copy constructor.

Method Detail

put

public boolean put(rice.pastry.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

get

public rice.pastry.NodeHandle get(rice.pastry.NodeId 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 rice.pastry.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

member

public boolean member(rice.pastry.NodeId nid)
test membership using Id

Specified by:
member in interface NodeSetI
Parameters:
nid - a node id.
Returns:
true of NodeHandle associated with id is a member, false otherwise

remove

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

Specified by:
remove in interface NodeSetI
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 NodeSetI
Returns:
the size.

getIndex

public int getIndex(rice.pastry.NodeId 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

insert

public boolean insert(int index,
                      rice.pastry.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 void remove(rice.pastry.NodeHandle handle)
remove a member

Parameters:
handle - the handle to remove

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(rice.pastry.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(rice.pastry.NodeHandle handle)
test membership

Parameters:
handle - the handle to test
Returns:
true of handle is a member, false otherwise

getIterator

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

Returns:
the interator

toString

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

Overrides:
toString in class java.lang.Object

putHandle

public boolean putHandle(rice.p2p.commonapi.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 rice.p2p.commonapi.NodeHandle getHandle(rice.p2p.commonapi.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 rice.p2p.commonapi.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(rice.p2p.commonapi.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 rice.p2p.commonapi.NodeHandle removeHandle(rice.p2p.commonapi.Id id)
Removes a node id and its handle from the set.

Specified by:
removeHandle in interface NodeHandleSet
Returns:
the node handle removed or null if nothing.

getIndexHandle

public int getIndexHandle(rice.p2p.commonapi.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.
java.util.NoSuchElementException

Rice Pastry API

Copyright © 2001 - Rice Pastry.


Imprint-Dataprotection