cz.cuni.amis.pogamut.base.communication.worldview.object
Class WorldObjectId

java.lang.Object
  extended by cz.cuni.amis.pogamut.base.communication.worldview.object.WorldObjectId
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
UnrealId

public class WorldObjectId
extends java.lang.Object
implements java.io.Serializable

Interface that is returning an unique id of the world object. The id must be unique among all the objects in the world.

Every implementations MUST implement equals() and hashCode() correctly as we will use this inside hashmaps/sets.

See Also:
Serialized Form

Field Summary
protected  boolean isDouble
          Whether the id wolds 'double' inside token.
protected  boolean isLong
          Whether the id wolds 'long' inside token.
protected  Token token
          Unique representation of this id, contains ints that uniquely identifies it.
 
Constructor Summary
protected WorldObjectId(double id)
          Instantiates a new object with id of 'id'.
protected WorldObjectId(long id)
          Instantiates a new object with id of 'id'.
protected WorldObjectId(java.lang.String name)
          Instantiates a new object with id of 'name'.
protected WorldObjectId(Token token)
           
 
Method Summary
 boolean equals(java.lang.Object o)
           
static WorldObjectId get(double objId)
          Returns shared instance of the WorldObjectId for 'objId'.
static WorldObjectId get(long objId)
          Returns shared instance of the WorldObjectId for 'objId'.
static WorldObjectId get(java.lang.String name)
          Returns shared instance of the WorldObjectId for 'name'.
 double getDoubleId()
          Returns id as 'double', only iff isDoubleId(), otherwise it raises a PogamutException.
 long getLongId()
          Returns id as 'long', only iff isLongId(), otherwise it raises a PogamutException.
 java.lang.String getStringId()
          Always returns a string representation of the ID.
 int hashCode()
           
 boolean isDoubleId()
          Whether the is is a double one.
 boolean isLongId()
          Whether the id is a long one.
 boolean isNumericId()
          Whether the id holds a numeric value (i.e., it is either isLongId() or isDoubleId()).
 java.lang.String toString()
          Returns string representation of the id, format: WorldObjectId[id]
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

token

protected Token token
Unique representation of this id, contains ints that uniquely identifies it.


isLong

protected boolean isLong
Whether the id wolds 'long' inside token.


isDouble

protected boolean isDouble
Whether the id wolds 'double' inside token.

Constructor Detail

WorldObjectId

protected WorldObjectId(java.lang.String name)
Instantiates a new object with id of 'name'.

Parameters:
name -

WorldObjectId

protected WorldObjectId(long id)
Instantiates a new object with id of 'id'.

Parameters:
id -

WorldObjectId

protected WorldObjectId(double id)
Instantiates a new object with id of 'id'.

Parameters:
id -

WorldObjectId

protected WorldObjectId(Token token)
Method Detail

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

equals

public boolean equals(java.lang.Object o)
Overrides:
equals in class java.lang.Object

getStringId

public java.lang.String getStringId()
Always returns a string representation of the ID.

Returns:

isNumericId

public boolean isNumericId()
Whether the id holds a numeric value (i.e., it is either isLongId() or isDoubleId()).

Returns:

isLongId

public boolean isLongId()
Whether the id is a long one.

Returns:

isDoubleId

public boolean isDoubleId()
Whether the is is a double one.

Returns:

getLongId

public long getLongId()
Returns id as 'long', only iff isLongId(), otherwise it raises a PogamutException.

Returns:
long

getDoubleId

public double getDoubleId()
Returns id as 'double', only iff isDoubleId(), otherwise it raises a PogamutException.

Returns:
long

toString

public java.lang.String toString()
Returns string representation of the id, format: WorldObjectId[id]

Overrides:
toString in class java.lang.Object
Returns:
string representation of this object

get

public static WorldObjectId get(java.lang.String name)
Returns shared instance of the WorldObjectId for 'name'. If no WorldObjectId exists for 'name', new one is created.

THREAD-SAFE!

Parameters:
name -
Returns:

get

public static WorldObjectId get(long objId)
Returns shared instance of the WorldObjectId for 'objId'. If no WorldObjectId exists for 'objId', new one is created.

THREAD-SAFE!

Parameters:
name -
Returns:

get

public static WorldObjectId get(double objId)
Returns shared instance of the WorldObjectId for 'objId'. If no WorldObjectId exists for 'objId', new one is created.

THREAD-SAFE!

Parameters:
name -
Returns: