/** * Get the length of the String representing this value. * * @return the length of the String representing this value. */ public int getStringLength() { String s = getString(); if ( s == null ) { return 0; } return s.length(); }
/** * Check whether this value is equal to the String supplied. * * @param string * The string to check for equality * @return true if the String representation of the value is equal to string. (ignoring case) */ public boolean isEqualTo( String string ) { return getString().equalsIgnoreCase( string ); }
public Value startsWith( Value string ) { return startsWith( string.getString() ); }
/** * 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 Value leftstr( int len ) { if ( isNull() ) { setType( VALUE_TYPE_STRING ); return this; } setValue( getString() ); int tot_len = getString() != null ? getString().length() : 0; if ( tot_len > 0 ) { int totlen = getString().length(); int f = totlen - len; if ( f > 0 ) { setValue( getString().substring( 0, len ) ); } } else { setNull(); } if ( !isString() ) { setType( VALUE_TYPE_STRING ); } return this; }
public Value rpad( Value len, Value padstr ) { return rpad( (int) len.getNumber(), padstr.getString() ); }
public Value lpad( Value len, Value padstr ) { return lpad( (int) len.getNumber(), padstr.getString() ); }
public Value upper() { if ( isNull() ) { setType( VALUE_TYPE_STRING ); return this; } setValue( getString().toUpperCase() ); return this; }
public Value lower() { if ( isNull() ) { setType( VALUE_TYPE_STRING ); } else { setValue( getString().toLowerCase() ); } return this; }
public Value substr( int from, int to ) { if ( isNull() ) { setType( VALUE_TYPE_STRING ); return this; } setValue( getString() ); if ( getString() != null ) { if ( to < 0 && from >= 0 ) { setValue( getString().substring( from ) ); } else if ( to >= 0 && from >= 0 ) { setValue( getString().substring( from, to ) ); } } else { setNull(); } if ( !isString() ) { setType( VALUE_TYPE_STRING ); } return this; }
public Value startsWith( String string ) { if ( isNull() ) { setType( VALUE_TYPE_BOOLEAN ); return this; } if ( string == null ) { setValue( false ); setNull(); return this; } setValue( getString().startsWith( string ) ); return this; }
public Value length() throws KettleValueException { if ( isNull() ) { setType( VALUE_TYPE_INTEGER ); setValue( 0L ); return this; } if ( getType() == VALUE_TYPE_STRING ) { setValue( (double) getString().length() ); } else { throw new KettleValueException( "Function LENGTH only works with a string" ); } return this; }
/** * Performs a right and left trim of spaces in the string. If the value is not a string a conversion to String is * performed first. * * @return The trimmed string value. */ public Value trim() { if ( isNull() ) { setType( VALUE_TYPE_STRING ); return this; } String str = Const.trim( getString() ); setValue( str ); return this; }
public Value rtrim() { if ( isNull() ) { setType( VALUE_TYPE_STRING ); } else { String s; if ( getType() == VALUE_TYPE_STRING ) { s = Const.rtrim( getString() ); } else { s = Const.rtrim( toString() ); } setValue( s ); } return this; }
public Value dat2num() throws KettleValueException { if ( isNull() ) { setType( VALUE_TYPE_INTEGER ); return this; } if ( getType() == VALUE_TYPE_DATE ) { if ( getString() == null ) { setNull(); setValue( 0L ); } else { setValue( getInteger() ); } } else { throw new KettleValueException( "Function DAT2NUM works only on dates" ); } return this; }