relop
Class Tuple

java.lang.Object
  extended by relop.Tuple

public class Tuple
extends java.lang.Object

Each tuple in a relation is a collection of bytes that must fit within a single page. The Tuple class provides a logical view of fields, allowing get and set operations while automatically handling offsets and type conversions.


Constructor Summary
Tuple(Schema schema)
          Creates a new empty tuple, given its schema.
Tuple(Schema schema, byte[] data)
          Creates a new tuple, given existing values to wrap.
Tuple(Schema schema, java.lang.Object... values)
          Creates a new tuple, given its schema and values.
 
Method Summary
 java.lang.Object[] getAllFields()
          Returns generic values for all fields.
 byte[] getData()
          Gets the underlying data buffer.
 java.lang.Object getField(int fldno)
          Gets a field's value generically.
 java.lang.Object getField(java.lang.String fldName)
          Gets a field's value generically, by column name.
 float getFloatFld(int fldno)
          Gets a float field.
 int getIntFld(int fldno)
          Gets an integer field.
 java.lang.String getStringFld(int fldno)
          Gets a string field.
 RID insertIntoFile(HeapFile file)
          Inserts the tuple into the given heap file.
static Tuple join(Tuple t1, Tuple t2, Schema schema)
          Builds and returns a new tuple resulting from joining two tuples.
 void print()
          Prints the tuple in a human-readable format.
 void setAllFields(java.lang.Object... values)
          Sets all fields, given generic values.
 void setField(int fldno, java.lang.Object val)
          Sets a field's value generically.
 void setField(java.lang.String fldName, java.lang.Object val)
          Sets a field's value generically, by column name.
 void setFloatFld(int fldno, float val)
          Sets a float field.
 void setIntFld(int fldno, int val)
          Sets an integer field.
 void setStringFld(int fldno, java.lang.String val)
          Sets a string field (automatically truncates, if necessary).
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Tuple

public Tuple(Schema schema)
Creates a new empty tuple, given its schema.

Parameters:
schema - logical information for the fields

Tuple

public Tuple(Schema schema,
             java.lang.Object... values)
Creates a new tuple, given its schema and values.

Parameters:
schema - logical information for the fields
values - individual data values of the fields

Tuple

public Tuple(Schema schema,
             byte[] data)
Creates a new tuple, given existing values to wrap.

Parameters:
schema - logical information for the fields
data - record buffer containing the tuple
Method Detail

join

public static Tuple join(Tuple t1,
                         Tuple t2,
                         Schema schema)
Builds and returns a new tuple resulting from joining two tuples.

Parameters:
t1 - the left tuple
t2 - the right tuple
schema - of the result

getData

public byte[] getData()
Gets the underlying data buffer.


insertIntoFile

public RID insertIntoFile(HeapFile file)
Inserts the tuple into the given heap file.


getField

public java.lang.Object getField(int fldno)
Gets a field's value generically.


getField

public java.lang.Object getField(java.lang.String fldName)
Gets a field's value generically, by column name.


setField

public void setField(int fldno,
                     java.lang.Object val)
Sets a field's value generically.


setField

public void setField(java.lang.String fldName,
                     java.lang.Object val)
Sets a field's value generically, by column name.


getAllFields

public java.lang.Object[] getAllFields()
Returns generic values for all fields.


setAllFields

public void setAllFields(java.lang.Object... values)
Sets all fields, given generic values.


getIntFld

public int getIntFld(int fldno)
Gets an integer field.


setIntFld

public void setIntFld(int fldno,
                      int val)
Sets an integer field.


getFloatFld

public float getFloatFld(int fldno)
Gets a float field.


setFloatFld

public void setFloatFld(int fldno,
                        float val)
Sets a float field.


getStringFld

public java.lang.String getStringFld(int fldno)
Gets a string field.


setStringFld

public void setStringFld(int fldno,
                         java.lang.String val)
Sets a string field (automatically truncates, if necessary).


print

public void print()
Prints the tuple in a human-readable format.