planet.commonapi
Class Id

java.lang.Object
  extended byplanet.commonapi.Id
All Implemented Interfaces:
java.lang.Comparable, java.io.Serializable
Direct Known Subclasses:
ChordId, SymphonyId

public abstract class Id
extends java.lang.Object
implements java.lang.Comparable, java.io.Serializable

This interface is an abstraction of an Id (or key) from the CommonAPI paper.

Any class that extends this Id for a specific overlay, must to offer all theese constructors, based with its argument list:

  1. empty: This constructor must to build always an Id with the initial value, e.a. a zero value in most of cases.
  2. int: This constructor uses the int value to build a new Id. For a specific overlay Id implementation.
  3. double: This constructor uses the double value to build a new Id. For a specific overlay Id implementation.
  4. byte[]: This constructor uses the byte[] to build the internal value of the new Id. This argument must to be according the related Id.toByteArray() return value. For all overlay Id implementation.
  5. int[]: This constructor uses the int[] to build the internal value of the new Id. For a specific overlay Id implementation.
  6. String: This constructor obtains from the String the internal representation of the new Id. For all overlay Id implementation.
  7. BigInteger: This constructor obtains from the BigInteger the internal value of the new Id. For a specific overlay Id implementation.
If the above constructors someone is nonapplicable to any Id implementation, an InitializationException must to be thrown.

Author:
Carles Pairot, Ruben Mondejar, Jordi Pujol
See Also:
InitializationException, Serialized Form

Constructor Summary
Id()
           
 
Method Summary
abstract  Id add(Id offset)
          Returns an Id corresponding to this Id plus a given distance
abstract  boolean between(Id ccw, Id cw)
          Checks if this Id is between two given ids ccw (inclusive) and cw (exclusive) on the circle
 boolean betweenE(Id init, Id end)
          Checks if this Id is in interval (init,end]
abstract  boolean clockwise(Id nid)
          Checks to see if the Id nid is clockwise or counterclockwise from this, on the ring.
 boolean Ebetween(Id init, Id end)
          Checks if this Id is in interval [init,end)
static Id getMaximum()
          This method returns the maximum value for an Id that is possible to build.
abstract  java.lang.Object getValue()
          Returns the internal representation value of this Id.
 void setValue(Id newValue)
          Sets the new value with Id newValue.
abstract  void setValue(java.lang.Object newValue)
          Sets the new value to this Id with newValue
abstract  Id shift(int cnt, int fill)
          Shift operator. shift(-1,0) multiplies value of this by two, shift(1,0) divides by 2
abstract  Id subtract(Id offset)
          Returns an Id corresponding to this Id minus a given distance
abstract  byte[] toByteArray()
          Returns a (mutable) byte array representing this Id
abstract  java.lang.String toStringFull()
          Returns a string representing the full length of this Id.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.lang.Comparable
compareTo
 

Constructor Detail

Id

public Id()
Method Detail

between

public abstract boolean between(Id ccw,
                                Id cw)
Checks if this Id is between two given ids ccw (inclusive) and cw (exclusive) on the circle

Parameters:
ccw - the counterclockwise id
cw - the clockwise id
Returns:
true if this is between ccw (inclusive) and cw (exclusive), false otherwise

Ebetween

public boolean Ebetween(Id init,
                        Id end)
Checks if this Id is in interval [init,end)

Parameters:
init - Id that open the interval
Returns:
end Id that close the interval

betweenE

public boolean betweenE(Id init,
                        Id end)
Checks if this Id is in interval (init,end]

Parameters:
init - Id that open the interval
Returns:
end Id that close the interval

clockwise

public abstract boolean clockwise(Id nid)
Checks to see if the Id nid is clockwise or counterclockwise from this, on the ring. An Id is clockwise if it is within the half circle clockwise from this on the ring. An Id is considered counter-clockwise from itself.

Parameters:
nid - The id to compare to
Returns:
true if clockwise, false otherwise.

add

public abstract Id add(Id offset)
Returns an Id corresponding to this Id plus a given distance

Parameters:
offset - the distance to add
Returns:
the new Id

subtract

public abstract Id subtract(Id offset)
Returns an Id corresponding to this Id minus a given distance

Parameters:
offset - the distance to subtract
Returns:
the new Id

shift

public abstract Id shift(int cnt,
                         int fill)
Shift operator. shift(-1,0) multiplies value of this by two, shift(1,0) divides by 2

Parameters:
cnt - the number of bits to shift, negative shifts left, positive shifts right
fill - value of bit shifted in (0 if fill == 0, 1 otherwise)
Returns:
this

toByteArray

public abstract byte[] toByteArray()
Returns a (mutable) byte array representing this Id

Returns:
A byte[] representing this Id

toStringFull

public abstract java.lang.String toStringFull()
Returns a string representing the full length of this Id.

Returns:
A string with all of this Id

setValue

public void setValue(Id newValue)
Sets the new value with Id newValue.

This invokes:
setValue(newValue.getValue());

Parameters:
newValue - Id with the new value.
See Also:
setValue(planet.commonapi.Id)

setValue

public abstract void setValue(java.lang.Object newValue)
Sets the new value to this Id with newValue

Parameters:
newValue - Internal representation with the new value to set to this Id.

getValue

public abstract java.lang.Object getValue()
Returns the internal representation value of this Id.

Returns:
The internal representatio value of this Id.

getMaximum

public static Id getMaximum()
This method returns the maximum value for an Id that is possible to build. Must to be reimplemented for any specific overlay Id.

Returns:
The maximum value sets to an Id. In this case, always null.