edu.vt.marian.common
Class FullID

java.lang.Object
  |
  +--edu.vt.marian.common.FullID
Direct Known Subclasses:
WtdObj

public class FullID
extends java.lang.Object

The identifier of an object in the MARIAN universe is composed of class id and instance id. Class id can be regarded as database id and instance id can be regarded as a unique id in that database.

NOTE: classID is properly an unsigned 16-bit quantity; instanceID an unsigned 32-bit. Unfortunately there are no unsigneds in Java, so we use an int for classID and test the bounds. Properly, we should use a long for instanceID, but that's a lot of unused bits so we'll use an int and keep our fingers crossed.


Field Summary
static int BAD_PARAMS
           
protected  int classID
           
protected  Debug debug
          just for debugging
protected  int instanceID
           
protected static int MAX_CLASS_ID
           
protected static int MAX_INSTANCE_ID
           
static int NULL_STREAM
           
static int OK
          return values for methods of this class
 
Constructor Summary
FullID(java.io.BufferedReader br, Debug debug)
          Create a full id object from the specified stream.
FullID(Debug debug)
          Create an empty full id object where both classID and instanceID have been set to 0 (ABSURD).
FullID(FullID id, Debug debug)
          Create a full id object from another one.
FullID(int clID, int instID, Debug debug)
          Create a full id object with the specified class id and instance id values.
 
Method Summary
 boolean equals(java.lang.Object o)
          Tell whether this object has the same class id and instance id as the parameter object.
 int getClassID()
          Return the class id of this object.
 int getInstanceID()
          Return the instance id of this object.
 int hashCode()
          Generate a hash value suitable for java.util.HashTable.
 boolean isValid()
          Test whether or not the fullID is valid.
 int readPacked(java.io.ByteArrayInputStream bis)
          Read this out of compact storage in a byte array.
 int setClassID(int clID)
          Set the class id of this object.
 int setInstanceID(int instID)
          Set the instance id of this object.
 int toStream(java.io.PrintWriter pw)
          Print the content of this object to a specified stream.
 java.lang.String toString()
          Convert this to a human-readable string.
 int writePacked(java.io.ByteArrayOutputStream bos)
          Pack this into a byte array for compact storage.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

debug

protected Debug debug
just for debugging

classID

protected int classID

instanceID

protected int instanceID

MAX_CLASS_ID

protected static final int MAX_CLASS_ID

MAX_INSTANCE_ID

protected static final int MAX_INSTANCE_ID

OK

public static final int OK
return values for methods of this class

BAD_PARAMS

public static final int BAD_PARAMS

NULL_STREAM

public static final int NULL_STREAM
Constructor Detail

FullID

public FullID(Debug debug)
Create an empty full id object where both classID and instanceID have been set to 0 (ABSURD).
Parameters:
debug - used for debugging

FullID

public FullID(int clID,
              int instID,
              Debug debug)
Create a full id object with the specified class id and instance id values.
Parameters:
clID - class ID value;
instID - instance ID value;
debug - used for debugging

FullID

public FullID(FullID id,
              Debug debug)
Create a full id object from another one. The created object will have the same class id and instance id as the parameter object.
Parameters:
id - the object to be copied
debug - used for debugging

FullID

public FullID(java.io.BufferedReader br,
              Debug debug)
Create a full id object from the specified stream.
Parameters:
br - the stream to read out a full id object;
debug - used for debugging
Method Detail

isValid

public boolean isValid()
Test whether or not the fullID is valid.

Note: The null object of any class (#classID:0#) is always valid. However, objects with a null classID are not. This is because the null class (CLASS_ABSURD) has no members.

Returns:
true / false

setClassID

public int setClassID(int clID)
Set the class id of this object.

uses the services of class(es): none

Parameters:
clID - the class id of this object will be set to this value.
Returns:
OK == the value has been set;
BAD_PARAMS == invalid value for clID.

getClassID

public int getClassID()
Return the class id of this object.
Returns:
the class id of this object as an integer

setInstanceID

public int setInstanceID(int instID)
Set the instance id of this object.
Parameters:
instID - the instance id of this object will be set to this value
Returns:
OK == the value has been set;
BAD_PARAMS == invalid value for instID.

getInstanceID

public int getInstanceID()
Return the instance id of this object.
Returns:
the instance id of this object as an integer

equals

public boolean equals(java.lang.Object o)
Tell whether this object has the same class id and instance id as the parameter object.
Parameters:
id - the object used to compare with this object
Returns:
true == this object has the same class id and instance id as the parameter object.
false == this object doesn't have the same class id and instance id as the parameter object.
Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Generate a hash value suitable for java.util.HashTable.
Returns:
a positive integer.
Overrides:
hashCode in class java.lang.Object

writePacked

public int writePacked(java.io.ByteArrayOutputStream bos)
Pack this into a byte array for compact storage.
Parameters:
bos - a ByteArrayOutputStream into which to pack this.
Returns:
OK == all jake.
NULL_STREAM == could not write.

readPacked

public int readPacked(java.io.ByteArrayInputStream bis)
Read this out of compact storage in a byte array.
Parameters:
bis - a ByteArrayInputStream from which to unpack this.
Returns:
OK == all jake.
NULL_STREAM == could not read.

toString

public java.lang.String toString()
Convert this to a human-readable string.
Returns:
"@null@" if this is not a valid fullID; "#classID:instanceID#" if it is.
Overrides:
toString in class java.lang.Object

toStream

public int toStream(java.io.PrintWriter pw)
Print the content of this object to a specified stream.
Parameters:
pw - the stream to write this object
Returns:
OK == this object has been write to the stream correctly.
NULL_STREAM == could not read.