heap
Class Tuple

java.lang.Object
  extended byheap.Tuple
All Implemented Interfaces:
GlobalConst

public class Tuple
extends java.lang.Object
implements GlobalConst


Field Summary
static int max_size
          Maximum size of any tuple
 
Fields inherited from interface global.GlobalConst
INVALID_PAGE, MAX_NAME, MAX_SPACE, MAXATTRNAME, MAXFILENAME, MAXINDEXNAME, MINIBASE_BUFFER_POOL_SIZE, MINIBASE_DB_SIZE, MINIBASE_DEFAULT_SHAREDMEM_SIZE, MINIBASE_MAX_TRANSACTIONS, MINIBASE_MAXARRSIZE, MINIBASE_PAGESIZE, NUMBUF
 
Constructor Summary
Tuple()
          Class constructor Creat a new tuple with length = max_size,tuple offset = 0.
Tuple(byte[] atuple, int offset, int length)
          Constructor
Tuple(int size)
          Class constructor Creat a new tuple with length = size,tuple offset = 0.
Tuple(Tuple fromTuple)
          Constructor(used as tuple copy)
 
Method Summary
 short[] copyFldOffset()
          Makes a copy of the fldOffset array
 char getCharFld(int fldNo)
          Convert this field into a character
 float getFloFld(int fldNo)
          Convert this field in to float
 int getIntFld(int fldNo)
          Convert this field into integer
 int getLength()
          get the length of a tuple, call this method if you did not call setHdr () before
 int getOffset()
          get the offset of a tuple
 java.lang.String getStrFld(int fldNo)
          Convert this field into String
 byte[] getTupleByteArray()
          Copy the tuple byte array out
 short noOfFlds()
          Returns number of fields in this tuple
 void print(AttrType[] type)
          Print out the tuple
 byte[] returnTupleByteArray()
          return the data byte array
 Tuple setFloFld(int fldNo, float val)
          Set this field to float value
 void setHdr(short numFlds, AttrType[] types, short[] strSizes)
          setHdr will set the header of this tuple.
 Tuple setIntFld(int fldNo, int val)
          Set this field to integer value
 Tuple setStrFld(int fldNo, java.lang.String val)
          Set this field to String value
 short size()
          get the length of a tuple, call this method if you did call setHdr () before
 void tupleCopy(Tuple fromTuple)
          Copy a tuple to the current tuple position you must make sure the tuple lengths must be equal
 void tupleInit(byte[] atuple, int offset, int length)
          This is used when you don't want to use the constructor
 void tupleSet(byte[] record, int offset, int length)
          Set a tuple with the given tuple length and offset
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

max_size

public static final int max_size
Maximum size of any tuple

See Also:
Constant Field Values
Constructor Detail

Tuple

public Tuple()
Class constructor Creat a new tuple with length = max_size,tuple offset = 0.


Tuple

public Tuple(byte[] atuple,
             int offset,
             int length)
Constructor

Parameters:
atuple - a byte array which contains the tuple
offset - the offset of the tuple in the byte array
length - the length of the tuple

Tuple

public Tuple(Tuple fromTuple)
Constructor(used as tuple copy)

Parameters:
fromTuple - a byte array which contains the tuple

Tuple

public Tuple(int size)
Class constructor Creat a new tuple with length = size,tuple offset = 0.

Method Detail

tupleCopy

public void tupleCopy(Tuple fromTuple)
Copy a tuple to the current tuple position you must make sure the tuple lengths must be equal

Parameters:
fromTuple - the tuple being copied

tupleInit

public void tupleInit(byte[] atuple,
                      int offset,
                      int length)
This is used when you don't want to use the constructor

Parameters:
atuple - a byte array which contains the tuple
offset - the offset of the tuple in the byte array
length - the length of the tuple

tupleSet

public void tupleSet(byte[] record,
                     int offset,
                     int length)
Set a tuple with the given tuple length and offset

Parameters:
record - a byte array contains the tuple
offset - the offset of the tuple ( =0 by default)
length - the length of the tuple

getLength

public int getLength()
get the length of a tuple, call this method if you did not call setHdr () before

Returns:
length of this tuple in bytes

size

public short size()
get the length of a tuple, call this method if you did call setHdr () before

Returns:
size of this tuple in bytes

getOffset

public int getOffset()
get the offset of a tuple

Returns:
offset of the tuple in byte array

getTupleByteArray

public byte[] getTupleByteArray()
Copy the tuple byte array out

Returns:
byte[], a byte array contains the tuple the length of byte[] = length of the tuple

returnTupleByteArray

public byte[] returnTupleByteArray()
return the data byte array

Returns:
data byte array

getIntFld

public int getIntFld(int fldNo)
              throws java.io.IOException,
                     FieldNumberOutOfBoundException
Convert this field into integer

Parameters:
fldNo - the field number
Returns:
the converted integer if success
Throws:
java.io.IOException - I/O errors
FieldNumberOutOfBoundException - Tuple field number out of bound

getFloFld

public float getFloFld(int fldNo)
                throws java.io.IOException,
                       FieldNumberOutOfBoundException
Convert this field in to float

Parameters:
fldNo - the field number
Returns:
the converted float number if success
Throws:
java.io.IOException - I/O errors
FieldNumberOutOfBoundException - Tuple field number out of bound

getStrFld

public java.lang.String getStrFld(int fldNo)
                           throws java.io.IOException,
                                  FieldNumberOutOfBoundException
Convert this field into String

Parameters:
fldNo - the field number
Returns:
the converted string if success
Throws:
java.io.IOException - I/O errors
FieldNumberOutOfBoundException - Tuple field number out of bound

getCharFld

public char getCharFld(int fldNo)
                throws java.io.IOException,
                       FieldNumberOutOfBoundException
Convert this field into a character

Parameters:
fldNo - the field number
Returns:
the character if success
Throws:
java.io.IOException - I/O errors
FieldNumberOutOfBoundException - Tuple field number out of bound

setIntFld

public Tuple setIntFld(int fldNo,
                       int val)
                throws java.io.IOException,
                       FieldNumberOutOfBoundException
Set this field to integer value

Parameters:
fldNo - the field number
val - the integer value
Throws:
java.io.IOException - I/O errors
FieldNumberOutOfBoundException - Tuple field number out of bound

setFloFld

public Tuple setFloFld(int fldNo,
                       float val)
                throws java.io.IOException,
                       FieldNumberOutOfBoundException
Set this field to float value

Parameters:
fldNo - the field number
val - the float value
Throws:
java.io.IOException - I/O errors
FieldNumberOutOfBoundException - Tuple field number out of bound

setStrFld

public Tuple setStrFld(int fldNo,
                       java.lang.String val)
                throws java.io.IOException,
                       FieldNumberOutOfBoundException
Set this field to String value

Parameters:
fldNo - the field number
val - the string value
Throws:
java.io.IOException - I/O errors
FieldNumberOutOfBoundException - Tuple field number out of bound

setHdr

public void setHdr(short numFlds,
                   AttrType[] types,
                   short[] strSizes)
            throws java.io.IOException,
                   InvalidTypeException,
                   InvalidTupleSizeException
setHdr will set the header of this tuple.

Parameters:
numFlds - number of fields
Throws:
java.io.IOException - I/O errors
InvalidTypeException - Invalid tupe type
InvalidTupleSizeException - Tuple size too big

noOfFlds

public short noOfFlds()
Returns number of fields in this tuple

Returns:
the number of fields in this tuple

copyFldOffset

public short[] copyFldOffset()
Makes a copy of the fldOffset array

Returns:
a copy of the fldOffset arrray

print

public void print(AttrType[] type)
           throws java.io.IOException
Print out the tuple

Parameters:
type - the types in the tuple
Throws:
java.io.IOException