public class Tuple
extends java.lang.Object
Constructor and Description |
---|
Tuple(Table table)
create an empty tuple for the given table
|
Tuple(TableSchema schema)
create an empty tuple for the given schema
|
Modifier and Type | Method and Description |
---|---|
void |
addColumnValue(java.lang.String name,
java.lang.String value)
adds an individual column,value pair to a tuple; Error thrown if column
is not existent
|
void |
addColumnValuesEH(java.lang.String... vals)
adds a list of values, in order in which their columns are defined, to an
empty tuple.
|
Tuple |
copy(TableSchema newSchema)
returns a (deep) copy of a tuple;
precondition: newSchema and tableSchema must have identically
defined sets of columns; the schemas may have different names
|
java.lang.String |
get(java.lang.String columnName)
returns value of given columnName; if columnName unrecognized, Error is
thrown
Note: do not rename this method; required by velocity
|
boolean |
getBool(java.lang.String columnName)
return boolean value of a column with columnName; no checking is done to
know if column value can be converted into a boolean
|
java.util.List<Column> |
getColumns()
returns list of all columns for this tuple.
|
double |
getDouble(java.lang.String columnName)
return double value of a column with columnName; no checking is done to
know if column value can be converted into an double
|
float |
getFloat(java.lang.String columnName)
return float value of a column with columnName; no checking is done to
know if column value can be converted into a float
|
int |
getInt(java.lang.String columnName)
return int value of column with columnName; no checking is done to know
if column value can be converted into an int
|
java.lang.String |
getNull(java.lang.String columnName)
returns 'null' if string content of columnName is "null" otherwise string
column value is returned
|
TableSchema |
getSchema()
returns TableSchema of 'this' tuple
|
boolean |
is(java.lang.String columnName)
does columnName have boolean true?
|
boolean |
is(java.lang.String columnName,
double value)
does columnName have double value?
|
boolean |
is(java.lang.String columnName,
float value)
does columnName have float value?
|
boolean |
is(java.lang.String columnName,
int value)
does columnName have integer value?
|
boolean |
is(java.lang.String columnName,
java.lang.String... values)
does columnName have any of these values
|
boolean |
is(java.lang.String columnName,
java.lang.String value)
does columnName have value?
|
void |
isComplete()
asserts that a tuple has its full complement of values.
|
boolean |
isNull(java.lang.String columnName)
is value of columnName "null"?
|
Tuple |
joinFirst(java.lang.String thisJoinKey,
Table otherTable,
java.lang.String otherJoinKey)
returns the first tuple of otherTable that joins with 'this', where
"this".thisJoinkey == otherTable.otherJoinKey; returns null otherwise
|
Tuple |
joinFirstEH(java.lang.String thisJoinKey,
Table otherTable,
java.lang.String otherJoinKey)
same as firstJoin, except an Error is thrown if no tuple of otherTable is
found.
|
<S> S |
map(java.util.function.Function<Tuple,S> f)
transform a Tuple to an object of type S
|
static Tuple |
parseTupleDecl(java.lang.String line,
int lineno,
TableSchema ts)
parses a line at lineno, expecting to parse a legal prolog tuple
declaration that conforms to table schema ts
|
void |
print(java.io.PrintStream out)
print tuple to PrintStream out
|
Tuple |
project(TableSchema superTableSchema)
projects 'this' tuple to the set of columns of a super table schema; if
table schemas do not match, tuple.getName() throws an Error projection
retains the first set of columns -- columns that are removed are at the
end of a tuple
|
void |
set(java.lang.String columnName,
boolean value)
sets a column with columnName to have the given boolean value
|
void |
set(java.lang.String columnName,
double value)
sets a column with columnName to have the given double value
|
void |
set(java.lang.String columnName,
float value)
sets a column with columnName to have the given float value
|
void |
set(java.lang.String columnName,
int value)
sets a column with columnName to have the given int value
|
void |
set(java.lang.String columnName,
java.lang.String value)
sets a column with columnName to have the given string value
|
void |
setNull(java.lang.String columnName)
sets a column with columnName to have null value
|
int |
size()
returns current number of (column,value) pairs in this tuple.
|
java.lang.String |
toString()
converts tuple into a string; throws error if # of columns of tuple do
not match # of columns in table schema
|
public Tuple(TableSchema schema)
schema
- tuple schema to instantiatepublic Tuple(Table table)
table
- -- table to which tuple should conformpublic java.lang.String get(java.lang.String columnName)
columnName
- -- name of column to readpublic int getInt(java.lang.String columnName)
columnName
- -- name of column to readpublic double getDouble(java.lang.String columnName)
columnName
- -- name of column to readpublic float getFloat(java.lang.String columnName)
columnName
- -- name of column to readpublic boolean getBool(java.lang.String columnName)
columnName
- -- name of column to readpublic java.lang.String getNull(java.lang.String columnName)
columnName
- -- name of column to readpublic boolean isNull(java.lang.String columnName)
columnName
- -- name of column to checkpublic boolean is(java.lang.String columnName, java.lang.String value)
columnName
- -- name of column to checkvalue
- -- value column should havepublic boolean is(java.lang.String columnName, java.lang.String... values)
columnName
- -- name of column to checkvalues
- -- set of values the column might havepublic boolean is(java.lang.String columnName, int value)
columnName
- -- name of column to checkvalue
- -- integer value column should havepublic boolean is(java.lang.String columnName, float value)
columnName
- -- name of column to checkvalue
- -- float value column should havepublic boolean is(java.lang.String columnName, double value)
columnName
- -- name of column to checkvalue
- -- double value column should havepublic boolean is(java.lang.String columnName)
columnName
- -- name of column to checkpublic void set(java.lang.String columnName, java.lang.String value)
columnName
- -- name of column to updatevalue
- -- value to replacepublic void set(java.lang.String columnName, int value)
columnName
- -- name of column to updatevalue
- -- value to replacepublic void set(java.lang.String columnName, double value)
columnName
- -- name of column to updatevalue
- -- value to replacepublic void set(java.lang.String columnName, float value)
columnName
- -- name of column to updatevalue
- -- value to replacepublic void set(java.lang.String columnName, boolean value)
columnName
- -- name of column to updatevalue
- -- value to replacepublic void setNull(java.lang.String columnName)
columnName
- -- name of column to updatepublic TableSchema getSchema()
public int size()
public java.util.List<Column> getColumns()
public Tuple project(TableSchema superTableSchema)
superTableSchema
- -- schema of supertable to project topublic void isComplete()
public Tuple copy(TableSchema newSchema)
newSchema
- -- returned tuple copy must be instance of this schemapublic void addColumnValuesEH(java.lang.String... vals)
vals
- is list of values to add to an empty tuplepublic void addColumnValue(java.lang.String name, java.lang.String value)
name
- of columnvalue
- value of columnpublic static Tuple parseTupleDecl(java.lang.String line, int lineno, TableSchema ts)
line
- to parselineno
- line number of the linets
- table schema for tuple to conformpublic void print(java.io.PrintStream out)
out
- where to printpublic java.lang.String toString()
toString
in class java.lang.Object
public Tuple joinFirst(java.lang.String thisJoinKey, Table otherTable, java.lang.String otherJoinKey)
otherTable
- -- the other table to which 'this' is to be joinedthisJoinKey
- -- the join key of 'this' tableotherJoinKey
- -- the join key of otherTablepublic Tuple joinFirstEH(java.lang.String thisJoinKey, Table otherTable, java.lang.String otherJoinKey)
otherTable
- -- the other table to which 'this' is to be joinedthisJoinKey
- -- the join key of 'this' tableotherJoinKey
- -- the join key of otherTablepublic <S> S map(java.util.function.Function<Tuple,S> f)
S
- -- return type, should not be Tuple or subclass of Tuplef
- -- a function that maps a Table to S