Package org.pentaho.di.compatibility
Class Row
- java.lang.Object
-
- org.pentaho.di.compatibility.Row
-
- All Implemented Interfaces:
Serializable
,Comparable<Row>
,XMLInterface
public class Row extends Object implements XMLInterface, Comparable<Row>, Serializable
This class describes a single row in a stream of data. A row is a array/list of Value objects. Note that most methods in this class assume that a value with a certain name only occurs once in the Row.- Since:
- Beginning 2003.
- Author:
- Matt
- See Also:
Value
, Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static long
serialVersionUID
static String
XML_TAG
-
Constructor Summary
Constructors Constructor Description Row()
Create a new empty row (with 0 values)Row(DataInputStream dis)
Read a row of Values from an input-stream.Row(DataInputStream dis, int size, Row meta)
Read a number of Values without meta-data into a row.Row(DataInputStream dis, Row meta)
Read a number of Values without meta-data into a row.Row(Row r)
Creates a new row as a duplicate of the given row.Row(Node rowNode)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
add(Object obj)
Deprecated.void
addRow(Row r)
Add all the values of row r to the Row.void
addValue(int idx, Value v)
Add a value on a certain location in the row.void
addValue(Value v)
Add a value after the last value of the rowvoid
clear()
Removes all values from the row.Row
Clone()
Returns an exact copy of this row.int
compare(Row r)
Compare 2 complete rows of values with each other.int
compare(Row r, boolean caseInsensitive)
Compare 2 complete rows of values with each otherint
compare(Row r, int[] fieldnrs, boolean[] ascending)
Compare 2 rows with each other using certain values in the rows and also considering an ascending clause.int
compare(Row r, int[] fieldnrs, boolean[] ascending, boolean[] caseInsensitive)
int
compare(Row r, int[] fieldnrs1, int[] fieldnrs2, boolean[] ascending, boolean[] caseInsensitive)
Compare 2 rows with each other using certain values in the rows and also considering an ascending clause.int
compare(Row r, int fieldnr, boolean sort_desc)
Compare 2 rows with each other using one value in the rows and also considering an ascending clause.int
compareTo(Row obj)
boolean
equals(Object r)
static byte[]
extractData(Row row)
Object
get(int idx)
Deprecated.boolean
getBoolean(String valuename, boolean def)
Search for a value, if it doesn't occur in the row, return the default value.Date
getDate(String valuename, Date def)
Search for a value, if it doesn't occur in the row, return the default value.String[]
getFieldNames()
Get an array of the names of all the Values in the Row.String[]
getFieldNamesAndTypes(int maxlen)
Get an array of strings showing the name of the values in the row padded to a maximum length, followed by the types of the values.long
getInteger(String valuename, long def)
Search for a value, if it doesn't occur in the row, return the default value.double
getNumber(String valuename, double def)
Search for a value, if it doesn't occur in the row, return the default value.static Row
getRow(byte[] data, Row metadata)
long
getShort(String valuename, int def)
Search for a value, if it doesn't occur in the row, return the default value.String
getString(String valuename, String def)
Search for a value, if it doesn't occur in the row, return the default value.List<ValueUsedListener>
getUsedValueListeners()
Value
getValue(int index)
Get the value on a given position in the row.String
getXML()
Return the XML representation of a row.int
hashCode()
boolean
isEmpty()
Checks whether or not the row is empty A row is empty if all the values in the row are null A row is empty if there are no values in the row.boolean
isIgnored()
Check wether or not this row should be ignored...void
mergeData(Row r)
Merge the data of row r to this Row.void
mergeRow(Row r)
Merge the values of row r to this Row.void
print()
Print the names and the String representations of the values of the Values in row to stdout.void
remove(int idx)
Deprecated.void
removeValue(int idx)
Remove a value on a certain index.boolean
removeValue(String valname)
Remove a value with a given name from the row.Value
searchValue(String name)
Search the Value by name in the row.int
searchValueIndex(String name)
Search the Value by name in the row, return the Values index.void
setIgnore()
Marks this row as to be ignored by the next steps.void
setIgnore(boolean i)
Marks this row as to be ignored or not by the next steps.void
setUsedValueListeners(List<ValueUsedListener> usedValueListeners)
void
setValue(int idx, Value v)
Set the value on index idx.int
size()
Return number of Values in Row.static void
sortRows(List<Row> rows, int[] fieldNrs, boolean[] ascDesc)
String
toString()
Convert the row to a String representation.String
toStringMeta()
Return the meta-data of a row as a String.void
write(DataOutputStream dos)
Write the content of the row to a DataOutputStream.boolean
writeData(DataOutputStream dos)
Write a row of Values to a DataOutputStream, without saving the meta-data.
-
-
-
Field Detail
-
XML_TAG
public static final String XML_TAG
- See Also:
- Constant Field Values
-
serialVersionUID
public static final long serialVersionUID
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
Row
public Row()
Create a new empty row (with 0 values)
-
Row
public Row(Row r)
Creates a new row as a duplicate of the given row. The values are copied one by one into new values.- Parameters:
r
- The row to be copied.
-
Row
public Row(DataInputStream dis) throws KettleFileException
Read a row of Values from an input-stream.- Parameters:
dis
- The DataInputStream to read from- Throws:
KettleFileException
-
Row
public Row(DataInputStream dis, Row meta) throws KettleFileException
Read a number of Values without meta-data into a row.- Parameters:
dis
- The DataInputStream to read frommeta
- The description (name, type, length, precision) of the values to be read (the same number of values are read)- Throws:
KettleFileException
- if the row couldn't be created by reading from the data input stream.
-
Row
public Row(DataInputStream dis, int size, Row meta) throws KettleFileException
Read a number of Values without meta-data into a row.- Parameters:
dis
- The DataInputStream to read fromsize
- the number or values to readmeta
- The description (name, type, length, precision) of the values to be read- Throws:
KettleFileException
- if the row couldn't be created by reading from the data input stream.
-
Row
public Row(Node rowNode)
-
-
Method Detail
-
getValue
public Value getValue(int index)
Get the value on a given position in the row.- Parameters:
index
- The position to look for- Returns:
- The Value on in the given index
-
addValue
public void addValue(Value v)
Add a value after the last value of the row- Parameters:
v
- The value to add to the row
-
setValue
public void setValue(int idx, Value v)
Set the value on index idx.- Parameters:
idx
- The indexv
- The value to set
-
addValue
public void addValue(int idx, Value v)
Add a value on a certain location in the row.- Parameters:
idx
- The index where the value needs to be put in the rowv
- The value to add to the row
-
add
@Deprecated public void add(Object obj)
Deprecated.Add an object to the row.- Parameters:
obj
- the object to add
-
get
@Deprecated public Object get(int idx)
Deprecated.Get an object from the row.- Parameters:
idx
- the index to get the object from- Returns:
- the object
-
remove
@Deprecated public void remove(int idx)
Deprecated.Remove an object in the row on index idx.- Parameters:
idx
- The object to remove
-
removeValue
public boolean removeValue(String valname)
Remove a value with a given name from the row.- Parameters:
valname
- The value name to remove from this row- Returns:
- true if the value was found and removed, false if the value wasn't found.
-
removeValue
public void removeValue(int idx)
Remove a value on a certain index.- Parameters:
idx
- the index to remove in the row
-
clear
public void clear()
Removes all values from the row.
-
addRow
public void addRow(Row r)
Add all the values of row r to the Row.- Parameters:
r
- The row to be added to this row.
-
mergeRow
public void mergeRow(Row r)
Merge the values of row r to this Row. Merge means: only the values that are not yet in the row are added (comparing on the value name).- Parameters:
r
- The row to be merged with this row
-
mergeData
public void mergeData(Row r)
Merge the data of row r to this Row. That means: All fields in row r that do exist in this row (same name and same type) and have non-empty values will have their values written into this row, if the value of that field is empty in this row.- Parameters:
r
- The row to be merged with this row
-
searchValueIndex
public int searchValueIndex(String name)
Search the Value by name in the row, return the Values index.- Parameters:
name
- the value name to search for.- Returns:
- the index of the value with the given name, -1 is nothing was found.
-
searchValue
public Value searchValue(String name)
Search the Value by name in the row.- Parameters:
name
- the value name to search for- Returns:
- the Value with the given name, null if nothing was found.
-
size
public int size()
Return number of Values in Row.- Returns:
- number of Values.
-
print
public void print()
Print the names and the String representations of the values of the Values in row to stdout.
-
toString
public String toString()
Convert the row to a String representation.
-
toStringMeta
public String toStringMeta()
Return the meta-data of a row as a String.- Returns:
- the meta-data of a row as a String
-
setIgnore
public void setIgnore()
Marks this row as to be ignored by the next steps.
-
setIgnore
public void setIgnore(boolean i)
Marks this row as to be ignored or not by the next steps.- Parameters:
i
- true: ignore this row, false: don't ignore.
-
isIgnored
public boolean isIgnored()
Check wether or not this row should be ignored...- Returns:
- true if the row should be ignored.
-
write
public void write(DataOutputStream dos) throws KettleFileException
Write the content of the row to a DataOutputStream.- Parameters:
dos
- The DataOutputStream to write to- Throws:
KettleFileException
- if an error occurs.
-
writeData
public boolean writeData(DataOutputStream dos) throws KettleFileException
Write a row of Values to a DataOutputStream, without saving the meta-data.- Parameters:
dos
- The DataOutputStream to write to- Returns:
- true if the row was written successfuly, false if something went wrong.
- Throws:
KettleFileException
-
compare
public int compare(Row r, int[] fieldnrs, boolean[] ascending)
Compare 2 rows with each other using certain values in the rows and also considering an ascending clause.- Parameters:
r
- The row to compare withfieldnrs
- The indexes of the values to compareascending
- an entry for each value to compare where true means and normal compare, false the reverse.- Returns:
- -1 if the row is smaller, 0 if they are equal and 1 if the row is larger.
-
compare
public int compare(Row r, int[] fieldnrs, boolean[] ascending, boolean[] caseInsensitive)
-
compare
public int compare(Row r, int[] fieldnrs1, int[] fieldnrs2, boolean[] ascending, boolean[] caseInsensitive)
Compare 2 rows with each other using certain values in the rows and also considering an ascending clause.- Parameters:
r
- The row to compare withfieldnrs
- The indexes of the values to compare in the source row (this)fieldnrs2
- The indexes of the values to compare with.ascending
- an entry for each value to compare where true means and normal compare, false the reverse.- Returns:
- -1 if the row is smaller, 0 if they are equal and 1 if the row is larger.
-
compare
public int compare(Row r, int fieldnr, boolean sort_desc)
Compare 2 rows with each other using one value in the rows and also considering an ascending clause.- Parameters:
r
- The row to compare withfieldnr
- The indexe of the values to comparesort_desc
- true means and normal compare, false the reverse.- Returns:
- -1 if the row is smaller, 0 if they are equal and 1 if the row is larger.
-
compare
public int compare(Row r)
Compare 2 complete rows of values with each other. Strings are compared in a case insensitive way- Parameters:
r
- the row to compare with- Returns:
- -1 if the row is smaller, 0 if both rows are equal, 1 if the row is larger.
-
compare
public int compare(Row r, boolean caseInsensitive)
Compare 2 complete rows of values with each other- Parameters:
r
- the row to compare with- Returns:
- -1 if the row is smaller, 0 if both rows are equal, 1 if the row is larger.
-
compareTo
public int compareTo(Row obj)
- Specified by:
compareTo
in interfaceComparable<Row>
-
Clone
public Row Clone()
Returns an exact copy of this row. On purpose not the real clone() method (notice the uppercase 'C') because of (rhino) javascript problems with it.- Returns:
- an exact copy of this row
-
isEmpty
public boolean isEmpty()
Checks whether or not the row is empty A row is empty if all the values in the row are null A row is empty if there are no values in the row.- Returns:
- true if the row is considered empty, false if the row is not empty.
-
getFieldNames
public String[] getFieldNames()
Get an array of the names of all the Values in the Row.- Returns:
- an array of Strings: the names of all the Values in the Row.
-
getFieldNamesAndTypes
public String[] getFieldNamesAndTypes(int maxlen)
Get an array of strings showing the name of the values in the row padded to a maximum length, followed by the types of the values.- Parameters:
maxlen
- The length to which the name will be padded.- Returns:
- an array of strings: the names and the types of the fieldnames in the row.
-
getBoolean
public boolean getBoolean(String valuename, boolean def)
Search for a value, if it doesn't occur in the row, return the default value.- Parameters:
valuename
- The valuename to look fordef
- The default value to return- Returns:
- The boolean representation of the value found or the default
-
getString
public String getString(String valuename, String def)
Search for a value, if it doesn't occur in the row, return the default value.- Parameters:
valuename
- The valuename to look fordef
- The default value to return- Returns:
- The String representation of the value found or the default
-
getDate
public Date getDate(String valuename, Date def)
Search for a value, if it doesn't occur in the row, return the default value.- Parameters:
valuename
- The valuename to look fordef
- The default value to return- Returns:
- The Date representation of the value found or the default
-
getNumber
public double getNumber(String valuename, double def)
Search for a value, if it doesn't occur in the row, return the default value.- Parameters:
valuename
- The valuename to look fordef
- The default value to return- Returns:
- The double representation of the value found or the default
-
getInteger
public long getInteger(String valuename, long def)
Search for a value, if it doesn't occur in the row, return the default value.- Parameters:
valuename
- The valuename to look fordef
- The default value to return- Returns:
- The long integer representation of the value found or the default
-
getShort
public long getShort(String valuename, int def)
Search for a value, if it doesn't occur in the row, return the default value.- Parameters:
valuename
- The valuename to look fordef
- The default value to return- Returns:
- The short integer representation of the value found or the default
-
getXML
public String getXML()
Return the XML representation of a row.- Specified by:
getXML
in interfaceXMLInterface
- Returns:
- The XML representation of this row
-
extractData
public static final byte[] extractData(Row row)
-
getUsedValueListeners
public List<ValueUsedListener> getUsedValueListeners()
- Returns:
- the usedValueListeners
-
setUsedValueListeners
public void setUsedValueListeners(List<ValueUsedListener> usedValueListeners)
- Parameters:
usedValueListeners
- the usedValueListeners to set
-
-