planet.symphony
Class SymphonyId

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

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
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].
SymphonyId(java.math.BigInteger value)
          Always throws an InitializationException because this constructor is nonapplicable to this type of Id.
SymphonyId(byte[] data)
          Builds an Id with the data in byte[] format.
SymphonyId(double id)
          Builds a new SymphonyId with the decimals that appear in id double argument.
SymphonyId(int id)
          Always throws an InitializationException, because this constructor is nonapplicable to this type of Id.
SymphonyId(int[] data)
          Always throws an InitializationException because this constructor is nonapplicable to this type of Id.
SymphonyId(java.lang.String sid)
          Builds a new Id with the double value that appear in the argument as String value.
 
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
 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)
           
 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 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
 
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].


SymphonyId

public SymphonyId(int id)
           throws InitializationException
Always throws an InitializationException, because this constructor is nonapplicable to this type of Id.

Parameters:
id - internal value as int argument.
Throws:
InitializationException - Always

SymphonyId

public SymphonyId(double id)
Builds a new SymphonyId with the decimals that appear in id double argument.

Parameters:
id - double with the internal value to set to new Id.

SymphonyId

public SymphonyId(byte[] data)
           throws InitializationException
Builds an Id with the data in byte[] format. This data must have to be builded as on SymphonyId.toByteArray().

Parameters:
data - A byte[] with the internal value.
Throws:
InitializationException - if an error occurs during the initialization.
See Also:
toByteArray()

SymphonyId

public SymphonyId(int[] data)
           throws InitializationException
Always throws an InitializationException because this constructor is nonapplicable to this type of Id.

Parameters:
data - int[] with the internal value to set to new Id.
Throws:
InitializationException - Always

SymphonyId

public SymphonyId(java.lang.String sid)
           throws InitializationException
Builds a new Id with the double value that appear in the argument as String value.

Parameters:
sid - String representation of a double value.
Throws:
InitializationException - if an error occurs during the initialization.

SymphonyId

public SymphonyId(java.math.BigInteger value)
           throws InitializationException
Always throws an InitializationException because this constructor is nonapplicable to this type of Id.

Parameters:
value - BigInteger with the internal value to the new Id.
Throws:
InitializationException - Always.
Method Detail

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()