planet.symphony
Class SymphonyId

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

public class SymphonyId
extends Id
implements java.io.Serializable

This Id is backed up a double value. This value always must to be between 0.0 and 1.0, as Symphony establish.

Author:
Helio Tejedor, Jordi Pujol, Marc Sanchez
See Also:
Serialized Form

Field Summary
protected static Id MAX
          Inform the maximum value for this SymphonyId (1.0).
static double MAX_SYMPHONY
          Symphony specific constant: Maximum value for the internal value of Id.
 
Constructor Summary
SymphonyId()
          Must be initialized to initial value, in this case to [0.00].
 
Method Summary
 Id add(Id offset)
          Returns an Id corresponding to this Id plus a given distance
 boolean between(Id ccw, Id cw)
          Checks if this Id is between two given ids ccw (inclusive) and cw (exclusive) on the circle
static double buildIdFrom(byte[] data)
          Builds the double Id from a byte[].
 boolean clockwise(Id nid)
          Checks to see if the Id nid is clockwise or counterclockwise from this, on the ring.
 int compareTo(java.lang.Object o)
           
static Id divide(int num)
          Overwrite the static method to return the required Id.
 Id divideOn(int divisor)
          This method returns the arithmetical result of this division:
thisId/divisor
 boolean equals(java.lang.Object o)
           
protected static double getDecimals(double value)
          Gives back the value between 0.0 and 1.0 of the value, using only the decimals of the argument.
 double getDoubleValue()
           
static Id getMaximum()
          This method returns the maximum value for a SymphonyId that is possible to build.
 java.lang.Object getValue()
          Returns the internal representation value of this Id.
 int hashCode()
           
 void setValue(double id)
           
 void setValue(java.lang.Object newValue)
          Sets the new value for this SymphonyId.
 Id setValues(java.math.BigInteger newValue)
          Always throws a NoSuchMethodError error.
 Id setValues(byte[] newValue)
          Sets the internal double value from the byte[] newValue.
 Id setValues(double newValue)
          Sets the internal double value from the newValue
 Id setValues(int newValue)
          Always throws a NoSuchMethodError error.
 Id setValues(int[] newValue)
          Always throws a NoSuchMethodError error.
 Id setValues(java.util.Random valueGenerator)
          Uses the valueGenerator to radomly build a new value.
 Id setValues(java.lang.String newValue)
          Copies the string representation of a number to the internal double.
 Id shift(int cnt, int fill)
          Shift operator. shift(-1,0) multiplies value of this by two, shift(1,0) divides by 2
 Id subtract(Id offset)
          Returns an Id corresponding to this Id minus a given distance
 byte[] toByteArray()
          Returns a (mutable) byte array representing this Id
 java.lang.String toString()
           
 java.lang.String toStringFull()
          Returns a string representing the full length of this Id.
 
Methods inherited from class planet.commonapi.Id
betweenE, Ebetween, setValue, setValues
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

MAX_SYMPHONY

public static final double MAX_SYMPHONY
Symphony specific constant: Maximum value for the internal value of Id.

See Also:
Constant Field Values

MAX

protected static Id MAX
Inform the maximum value for this SymphonyId (1.0).

Constructor Detail

SymphonyId

public SymphonyId()
Must be initialized to initial value, in this case to [0.00].

Method Detail

buildIdFrom

public static double buildIdFrom(byte[] data)
Builds the double Id from a byte[].

Parameters:
data - Byte array get from a hashing function, like SHA-1 or MD5.
Returns:
The double value once the 'data' has been converted.

getDecimals

protected static double getDecimals(double value)
Gives back the value between 0.0 and 1.0 of the value, using only the decimals of the argument.

Parameters:
value - Double which gives back its decimals.
Returns:
The decimals that appear in the argument.

getValue

public java.lang.Object getValue()
Description copied from class: Id
Returns the internal representation value of this Id.

Specified by:
getValue in class Id
Returns:
The internal representatio value of this Id.

getDoubleValue

public double getDoubleValue()

setValue

public void setValue(double id)

between

public boolean between(Id ccw,
                       Id cw)
Description copied from class: Id
Checks if this Id is between two given ids ccw (inclusive) and cw (exclusive) on the circle

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

clockwise

public boolean clockwise(Id nid)
Description copied from class: Id
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.

Specified by:
clockwise in class Id
Parameters:
nid - The id to compare to
Returns:
true if clockwise, false otherwise.

add

public Id add(Id offset)
Description copied from class: Id
Returns an Id corresponding to this Id plus a given distance

Specified by:
add in class Id
Parameters:
offset - the distance to add
Returns:
the new Id

subtract

public Id subtract(Id offset)
Description copied from class: Id
Returns an Id corresponding to this Id minus a given distance

Specified by:
subtract in class Id
Parameters:
offset - the distance to subtract
Returns:
the new Id

shift

public Id shift(int cnt,
                int fill)
Description copied from class: Id
Shift operator. shift(-1,0) multiplies value of this by two, shift(1,0) divides by 2

Specified by:
shift in class Id
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 byte[] toByteArray()
Description copied from class: Id
Returns a (mutable) byte array representing this Id

Specified by:
toByteArray in class Id
Returns:
A byte[] representing this Id

toStringFull

public java.lang.String toStringFull()
Description copied from class: Id
Returns a string representing the full length of this Id.

Specified by:
toStringFull in class Id
Returns:
A string with all of this Id

equals

public boolean equals(java.lang.Object o)

compareTo

public int compareTo(java.lang.Object o)
Specified by:
compareTo in interface java.lang.Comparable

hashCode

public int hashCode()

toString

public java.lang.String toString()

setValue

public void setValue(java.lang.Object newValue)
Sets the new value for this SymphonyId. This method waits an Double object as parameter.

Specified by:
setValue in class Id
Parameters:
newValue - New double value for this Id, wrapped by a Double.
See Also:
Id.setValue(java.lang.Object)

getMaximum

public static Id getMaximum()
This method returns the maximum value for a SymphonyId that is possible to build. To return this maximum value use the design pattern Singleton.

Returns:
The maximum value sets to an Id (1.0).
See Also:
Id.getMaximum()

divide

public static Id divide(int num)
Overwrite the static method to return the required Id.

Parameters:
num - Total number of nodes in the network.
Returns:
A new instance of this Id, with the increment between two consecutive Ids.
See Also:
Id.divide(int)

divideOn

public Id divideOn(int divisor)
This method returns the arithmetical result of this division:
thisId/divisor

Specified by:
divideOn in class Id
Parameters:
divisor - The number of parts to divide this Id.
Returns:
The result of division.

setValues

public Id setValues(java.math.BigInteger newValue)
Always throws a NoSuchMethodError error.

Specified by:
setValues in class Id
Parameters:
newValue - The new value
Returns:
The Id itself
See Also:
Id.setValues(java.math.BigInteger)

setValues

public Id setValues(byte[] newValue)
Sets the internal double value from the byte[] newValue.

Specified by:
setValues in class Id
Parameters:
newValue - The new value
Returns:
The Id itself
See Also:
Id.setValues(byte[])

setValues

public Id setValues(double newValue)
Sets the internal double value from the newValue

Specified by:
setValues in class Id
Parameters:
newValue - The new value
Returns:
The Id itself
See Also:
Id.setValues(double)

setValues

public Id setValues(int newValue)
Always throws a NoSuchMethodError error.

Specified by:
setValues in class Id
Parameters:
newValue - The new value.
Returns:
The Id itself
See Also:
Id.setValues(int)

setValues

public Id setValues(int[] newValue)
Always throws a NoSuchMethodError error.

Specified by:
setValues in class Id
Parameters:
newValue - The new value
Returns:
The Id itself
See Also:
Id.setValues(int[])

setValues

public Id setValues(java.util.Random valueGenerator)
Uses the valueGenerator to radomly build a new value.

Specified by:
setValues in class Id
Parameters:
valueGenerator - A Random number generator.
Returns:
The Id itself
See Also:
Id.setValues(java.util.Random)

setValues

public Id setValues(java.lang.String newValue)
Copies the string representation of a number to the internal double.

Specified by:
setValues in class Id
Parameters:
newValue - The new value.
Returns:
The Id itself
Throws:
An - Error if the newValue is not a double value.
See Also:
Id.setValues(java.lang.String)