Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| Rice Pastry API
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## rice.pastry.leafset
Class SimilarSet

    java.lang.Object
      java.util.Observable
          rice.pastry.leafset.SimilarSet

All Implemented Interfaces:
  java.io.Serializable, java.util.Observer, NodeSetEventSource

    public class SimilarSet

extends java.util.Observable
implements NodeSetEventSource, java.util.Observer, java.io.Serializable

A set of nodes, ordered by numerical distance of their Id from the local Id

Version:
  $Id: SimilarSet.java 3434 2006-10-27 13:34:07Z jeffh $
Author:
  Andrew Ladd, Peter Druschel
See Also:
  Serialized Form

Constructor Summary
`SimilarSet(LeafSet leafSet, NodeHandle localNode, int size, boolean cw)` Constructor.
`SimilarSet(LeafSet leafSet, NodeHandle localNode, int size, boolean cw, NodeHandle[] handles)` Constructor for SimilarSet.

Method Summary
`void` | `addNodeSetListener(NodeSetListener listener)` Adds the specified NodeSet listener to receive NodeSet events from this component.
`void` | `addObserver(java.util.Observer o)` Deprecated. use addNodeSetListener
`void` | `deleteObserver(java.util.Observer o)` Deprecated. use removeNodeSetListener
`void` | `destroy()` DESCRIBE THE METHOD
`NodeHandle` | `get(Id nid)` Finds the NodeHandle associated with the Id.
`NodeHandle` | `get(int i)` Gets the ith element in the set.
`NodeHandle` | `get(NodeHandle nh)` DESCRIBE THE METHOD
`java.util.Collection` | `getCollection()` This is thread safe, in that it won't throw an error if not properly synchronized.
`NodeHandle` | `getHandle(Id id)` Finds the NodeHandle associated with the Id.
`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)` Gets the Index attribute of the SimilarSet object
`int` | `getIndexHandle(Id id)` Gets the index of the element with the given node id.
`boolean` | `member(Id nid)`
`boolean` | `member(NodeHandle nid)` Verifies if the set contains this particular id.
`boolean` | `memberHandle(Id id)` Verifies if the set contains this particular id.
`int` | `mostSimilar(Id nid)` Impl that doesn't produce garbage Numerically closest node to a given a node.
`boolean` | `put(NodeHandle handle)` Puts a NodeHandle into the set.
`boolean` | `putHandle(NodeHandle handle)` Puts a NodeHandle into the set.
`NodeHandle` | `remove(Id nid)` Removes a node id and its handle from the set.
`protected NodeHandle` | `remove(int i)` Removes a node id and its handle from the set.
`NodeHandle` | `remove(NodeHandle nh)` DESCRIBE THE METHOD
`NodeHandle` | `removeHandle(Id id)` Removes a node id and its handle from the set.
`void` | `removeNodeSetListener(NodeSetListener listener)` Removes the specified NodeSet listener so that it no longer receives NodeSet events from this component.
`int` | `size()` Gets the current size of this set.
`protected void` | `swap(int i, int j)` swap two elements
`boolean` | `test(NodeHandle handle)` Test if a NodeHandle belongs into the set.
`java.lang.String` | `toString()` Converts to a String representation of the object.
`void` | `update(java.util.Observable o, java.lang.Object arg)` Is called by the Observer pattern whenever the liveness or proximity of a registered node handle is changed.

Methods inherited from class java.util.Observable
`clearChanged, countObservers, deleteObservers, hasChanged, notifyObservers, notifyObservers, setChanged`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

Constructor Detail

### SimilarSet

    public SimilarSet(LeafSet leafSet,
                      NodeHandle localNode,
                      int size,
                      boolean cw)

  Constructor.

  Parameters:
    `leafSet` - DESCRIBE THE PARAMETER
    `localNode` - the local node
    `size` - the size of the similar set.
    `cw` - true if this is the clockwise leafset half

### SimilarSet

    public SimilarSet(LeafSet leafSet,
                      NodeHandle localNode,
                      int size,
                      boolean cw,
                      NodeHandle[] handles)

  Constructor for SimilarSet.

  Parameters:
    `leafSet` - DESCRIBE THE PARAMETER
    `localNode` - DESCRIBE THE PARAMETER
    `size` - DESCRIBE THE PARAMETER
    `cw` - DESCRIBE THE PARAMETER
    `handles` - DESCRIBE THE PARAMETER

Method Detail

### get

    public NodeHandle get(Id nid)

  Finds the NodeHandle associated with the Id.

  Parameters:
    `nid` - a node id.
  Returns:
    the handle associated with that id or null if no such handle is found.

### get

    public NodeHandle get(NodeHandle nh)

  DESCRIBE THE METHOD

  Parameters:
    `nh` - DESCRIBE THE PARAMETER
  Returns:
    DESCRIBE THE RETURN VALUE

### get

    public NodeHandle get(int i)

  Gets the ith element in the set.

  Parameters:
    `i` - an index. i == -1 refers to the local node
  Returns:
    the handle associated with that id or null if no such handle is found.

### getIndex

    public int getIndex(Id nid)

  Gets the index of the element with the given node id.

  Parameters:
    `nid` - the node id.
  Returns:
    the index or -1 if the element does not exist.

### getIndex

    public int getIndex(NodeHandle nh)

  Gets the Index attribute of the SimilarSet object

  Parameters:
    `nh` - DESCRIBE THE PARAMETER
  Returns:
    The Index value

### getHandle

    public NodeHandle getHandle(Id id)

  Finds the NodeHandle associated with the Id.

  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.

  Parameters:
    `i` - an index.
  Returns:
    the handle associated with that id or null if no such handle is found.

### getIndexHandle

    public int getIndexHandle(Id id)
                       throws java.util.NoSuchElementException

  Gets the index of the element with the given node id.

  Parameters:
    `id` - the id.
  Returns:
    the index or throws a NoSuchElementException.
  Throws:
    `java.util.NoSuchElementException` - DESCRIBE THE EXCEPTION

### getCollection

    public java.util.Collection getCollection()

  This is thread safe, in that it won't throw an error if not properly synchronized.

  Returns:

### swap

    protected void swap(int i,
                        int j)

  swap two elements

  Parameters:
    `i` - the index of the first element
    `j` - the indes of the second element

### test

    public boolean test(NodeHandle handle)

  Test if a NodeHandle belongs into the set. Predicts if a put would succeed.

  Parameters:
    `handle` - the handle to test.
  Returns:
    true if a put would succeed, false otherwise.

### put

    public boolean put(NodeHandle handle)

  Puts a NodeHandle into the set.

  Parameters:
    `handle` - the handle to put.
  Returns:
    true if the put succeeded, false otherwise.

### addObserver

    public void addObserver(java.util.Observer o)

  Deprecated. use addNodeSetListener

  Generates too many objects to use this interface

  Overrides:
    `addObserver` in class `java.util.Observable`
  Parameters:
    `o` - The feature to be added to the Observer attribute

### deleteObserver

    public void deleteObserver(java.util.Observer o)

  Deprecated. use removeNodeSetListener

  Generates too many objects to use this interface

  Overrides:
    `deleteObserver` in class `java.util.Observable`
  Parameters:
    `o` - DESCRIBE THE PARAMETER

### addNodeSetListener

    public void addNodeSetListener(NodeSetListener listener)

  Adds the specified NodeSet listener to receive NodeSet events from this component. If listener l is null, no exception is thrown and no action is performed.

  Specified by:
    `addNodeSetListener` in interface `NodeSetEventSource`
  Parameters:
    `listener` - Contains the NodeSetListener for NodeSetEvent data.

### removeNodeSetListener

    public void removeNodeSetListener(NodeSetListener listener)

  Removes the specified NodeSet listener so that it no longer receives NodeSet events from this component. This method performs no function, nor does it throw an exception, if the listener specified by the argument was not previously added to this component. If listener l is null, no exception is thrown and no action is performed.

  Specified by:
    `removeNodeSetListener` in interface `NodeSetEventSource`
  Parameters:
    `listener` - Contains the NodeSetListener for NodeSetEvent data.

### update

    public void update(java.util.Observable o,
                       java.lang.Object arg)

  Is called by the Observer pattern whenever the liveness or proximity of a registered node handle is changed.

  Specified by:
    `update` in interface `java.util.Observer`
  Parameters:
    `o` - The node handle
    `arg` - the event type (PROXIMITY_CHANGE, DECLARED_LIVE, DECLARED_DEAD)

### member

    public boolean member(NodeHandle nid)

  Verifies if the set contains this particular id.

  Parameters:
    `nid` - a node id.
  Returns:
    true if that node id is in the set, false otherwise.

### member

    public boolean member(Id nid)

  Parameters:
    `nid` - DESCRIBE THE PARAMETER
  Returns:
    DESCRIBE THE RETURN VALUE

### 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.

### remove

    public NodeHandle remove(NodeHandle nh)

  DESCRIBE THE METHOD

  Parameters:
    `nh` - DESCRIBE THE PARAMETER
  Returns:
    DESCRIBE THE RETURN VALUE

### remove

    protected NodeHandle remove(int i)

  Removes a node id and its handle from the set.

  Parameters:
    `i` - the index of the node to remove.
  Returns:
    the node handle removed or null if nothing.

### size

    public int size()

  Gets the current size of this set.

  Returns:
    the size.

### mostSimilar

    public int mostSimilar(Id nid)

  Impl that doesn't produce garbage Numerically closest node to a given a node. Returns -1 if the local Id is the most similar and returns an index otherwise.

  Parameters:
    `nid` - a node id.
  Returns:
    -1 if the local Id is most similar, else the index of the most similar node.

### putHandle

    public boolean putHandle(NodeHandle handle)

  Puts a NodeHandle into the set.

  Parameters:
    `handle` - the handle to put.
  Returns:
    true if the put succeeded, false otherwise.

### memberHandle

    public boolean memberHandle(Id id)

  Verifies if the set contains this particular id.

  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.

  Parameters:
    `id` - DESCRIBE THE PARAMETER
  Returns:
    the node handle removed or null if nothing.

### toString

    public java.lang.String toString()

  Converts to a String representation of the object.

  Overrides:
    `toString` in class `java.lang.Object`
  Returns:
    A string representation of the object.

### destroy

    public void destroy()

  DESCRIBE THE METHOD

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| Rice Pastry API
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2001-2005 - Rice Pastry.