/** * 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. * * @return an exact copy of this row */ public synchronized Row Clone() { return new Row( this ); }
/** * Creates a new row as a duplicate of the given row. The values are copied one by one into new values. * * @param r * The row to be copied. */ // Copy values in row! public Row( Row r ) { this(); for ( int i = 0; i < r.size(); i++ ) { addValue( new Value( r.getValue( i ) ) ); } setIgnore( r.isIgnored() ); }
/** * Compare 2 complete rows of values with each other. Strings are compared in a case insensitive way * * @param r * the row to compare with * @return -1 if the row is smaller, 0 if both rows are equal, 1 if the row is larger. */ public int compare( Row r ) { return compare( r, true ); }
/** * Get an array of the names of all the Values in the Row. * * @return an array of Strings: the names of all the Values in the Row. */ public String[] getFieldNames() { String[] retval = new String[size()]; for ( int i = 0; i < size(); i++ ) { retval[i] = getValue( i ).getName(); } return retval; }
/** * 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). * * @param r * The row to be merged with this row */ public void mergeRow( Row r ) { if ( r == null ) { return; } for ( int x = 0; x < r.size(); x++ ) { Value field = r.getValue( x ); if ( searchValue( field.getName() ) == null ) { addValue( field ); // Not in list yet: add } } }
/** * 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. * * @param r * The row to be merged with this row */ public void mergeData( Row r ) { if ( r == null ) { return; } for ( int x = 0; x < r.size(); x++ ) { Value other = r.getValue( x ); Value value = searchValue( other.getName() ); if ( value != null ) { value.merge( other ); } } }
public static final Row getRow( byte[] data, Row metadata ) { try { ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream( data ); DataInputStream dataInputStream = new DataInputStream( byteArrayInputStream ); return new Row( dataInputStream, metadata.size(), metadata ); } catch ( Exception e ) { throw new RuntimeException( BaseMessages.getString( PKG, "Row.ErrorDeserializing" ), e ); } }
/** * Search for a value, if it doesn't occur in the row, return the default value. * * @param valuename * The valuename to look for * @param def * The default value to return * @return The double representation of the value found or the default */ public double getNumber( String valuename, double def ) { Value v = searchValue( valuename ); if ( v == null ) { return def; } return v.getNumber(); }
public static Row createOriginalRow( RowMetaInterface rowMeta, Object[] rowData ) throws KettleValueException { Row row = new Row(); for ( int i = 0; i < rowMeta.size(); i++ ) { ValueMetaInterface valueMeta = rowMeta.getValueMeta( i ); Object valueData = rowData[ i ]; Value value = valueMeta.createOriginalValue( valueData ); row.addValue( value ); } return row; }
/** * Read a number of Values without meta-data into a row. * * @param dis * The DataInputStream to read from * @param size * the number or values to read * @param meta * 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. */ public Row( DataInputStream dis, int size, Row meta ) throws KettleFileException { try { // get all values in the row for ( int i = 0; i < size; i++ ) { addValue( new Value( meta.getValue( i ), dis ) ); } } catch ( KettleEOFException e ) { throw new KettleEOFException( BaseMessages.getString( PKG, "Row.EndOfFileReadingRow" ), e ); } catch ( Exception e ) { throw new KettleFileException( BaseMessages.getString( PKG, "Row.RowError" ), e ); } }
private void readObj( DataInputStream dis ) throws IOException { // First handle the number of fields in a row int size = dis.readInt(); // get all values in the row for ( int i = 0; i < size; i++ ) { Value v = new Value(); v.readObj( dis ); addValue( v ); } }
private void readObject( java.io.ObjectInputStream in ) throws IOException { readObj( new DataInputStream( in ) ); }
/** * Compare 2 rows with each other using one value in the rows and also considering an ascending clause. * * @param r * The row to compare with * @param fieldnr * The indexe of the values to compare * @param sort_desc * true means and normal compare, false the reverse. * @return -1 if the row is smaller, 0 if they are equal and 1 if the row is larger. */ public int compare( Row r, int fieldnr, boolean sort_desc ) { int retval = 0; Value v1, v2; v1 = getValue( fieldnr ); v2 = r.getValue( fieldnr ); retval = v1.compare( v2 ); if ( sort_desc ) { retval = -retval; } return retval; }
/** * Remove a value with a given name from the row. * * @param valname * The value name to remove from this row * * @return true if the value was found and removed, false if the value wasn't found. */ public boolean removeValue( String valname ) { int idx = searchValueIndex( valname ); if ( idx < 0 ) { return false; } list.remove( idx ); return true; }
Scriptable jsV2Row = Context.toObject( v2Row, data.scope ); data.scope.put( "row", data.scope, jsV2Row ); v2Row.getUsedValueListeners().add( new ValueUsedListener() { public void valueIsUsed( int index, Value value ) { usedRowValues.put( index, value );
/** * Search for a value, if it doesn't occur in the row, return the default value. * * @param valuename * The valuename to look for * @param def * The default value to return * @return The String representation of the value found or the default */ public String getString( String valuename, String def ) { Value v = searchValue( valuename ); if ( v == null ) { return def; } return v.getString(); }
public Row( Node rowNode ) { int nrValues = XMLHandler.countNodes( rowNode, Value.XML_TAG ); for ( int i = 0; i < nrValues; i++ ) { Node valueNode = XMLHandler.getSubNodeByNr( rowNode, Value.XML_TAG, i ); addValue( new Value( valueNode ) ); } }
/** * Read a row of Values from an input-stream. * * @param dis * The DataInputStream to read from */ public Row( DataInputStream dis ) throws KettleFileException { try { readObj( dis ); } catch ( EOFException e ) { throw new KettleEOFException( BaseMessages.getString( PKG, "Row.EndOfFileReached" ), e ); } catch ( Exception e ) { throw new KettleFileException( BaseMessages.getString( PKG, "Row.ErrorReadingRowData" ), e ); } }