simpledb
Class TupleDesc

java.lang.Object
  extended by simpledb.TupleDesc

public class TupleDesc
extends java.lang.Object

TupleDesc describes the schema of a tuple.


Constructor Summary
TupleDesc(Type[] typeAr)
          Constructor.
TupleDesc(Type[] typeAr, java.lang.String[] fieldAr)
          Create a new TupleDesc with typeAr.length fields with fields of the specified types, with associated named fields.
 
Method Summary
 boolean equals(java.lang.Object o)
          Compares the specified object with this TupleDesc for equality.
 int fieldNameToIndex(java.lang.String name)
          Find the index of the field with a given name.
 java.lang.String getFieldName(int i)
          Gets the (possibly null) field name of the ith field of this TupleDesc.
 Type getFieldType(int i)
          Gets the type of the ith field of this TupleDesc.
 int getSize()
           
 int hashCode()
           
static TupleDesc merge(TupleDesc td1, TupleDesc td2)
          Merge two TupleDescs into one, with td1.numFields + td2.numFields fields, with the first td1.numFields coming from td1 and the remaining from td2.
 int numFields()
           
 java.lang.String toString()
          Returns a String describing this descriptor.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

TupleDesc

public TupleDesc(Type[] typeAr,
                 java.lang.String[] fieldAr)
Create a new TupleDesc with typeAr.length fields with fields of the specified types, with associated named fields.

Parameters:
typeAr - array specifying the number of and types of fields in this TupleDesc. It must contain at least one entry.
fieldAr - array specifying the names of the fields. Note that names may be null.

TupleDesc

public TupleDesc(Type[] typeAr)
Constructor. Create a new tuple desc with typeAr.length fields with fields of the specified types, with anonymous (unnamed) fields.

Parameters:
typeAr - array specifying the number of and types of fields in this TupleDesc. It must contain at least one entry.
Method Detail

numFields

public int numFields()
Returns:
the number of fields in this TupleDesc

getFieldName

public java.lang.String getFieldName(int i)
                              throws java.util.NoSuchElementException
Gets the (possibly null) field name of the ith field of this TupleDesc.

Parameters:
i - index of the field name to return. It must be a valid index.
Returns:
the name of the ith field
Throws:
java.util.NoSuchElementException - if i is not a valid field reference.

getFieldType

public Type getFieldType(int i)
                  throws java.util.NoSuchElementException
Gets the type of the ith field of this TupleDesc.

Parameters:
i - The index of the field to get the type of. It must be a valid index.
Returns:
the type of the ith field
Throws:
java.util.NoSuchElementException - if i is not a valid field reference.

fieldNameToIndex

public int fieldNameToIndex(java.lang.String name)
                     throws java.util.NoSuchElementException
Find the index of the field with a given name.

Parameters:
name - name of the field.
Returns:
the index of the field that is first to have the given name.
Throws:
java.util.NoSuchElementException - if no field with a matching name is found.

getSize

public int getSize()
Returns:
The size (in bytes) of tuples corresponding to this TupleDesc. Note that tuples from a given TupleDesc are of a fixed size.

merge

public static TupleDesc merge(TupleDesc td1,
                              TupleDesc td2)
Merge two TupleDescs into one, with td1.numFields + td2.numFields fields, with the first td1.numFields coming from td1 and the remaining from td2.

Parameters:
td1 - The TupleDesc with the first fields of the new TupleDesc
td2 - The TupleDesc with the last fields of the TupleDesc
Returns:
the new TupleDesc

equals

public boolean equals(java.lang.Object o)
Compares the specified object with this TupleDesc for equality. Two TupleDescs are considered equal if they are the same size and if the n-th type in this TupleDesc is equal to the n-th type in td.

Overrides:
equals in class java.lang.Object
Parameters:
o - the Object to be compared for equality with this TupleDesc.
Returns:
true if the object is equal to this TupleDesc.

hashCode

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

toString

public java.lang.String toString()
Returns a String describing this descriptor. It should be of the form "fieldType[0](fieldName[0]), ..., fieldType[M](fieldName[M])", although the exact format does not matter.

Overrides:
toString in class java.lang.Object
Returns:
String describing this descriptor.