public Value abs() throws KettleValueException { if ( isNull() ) { return this; } if ( isBigNumber() ) { setValue( getBigNumber().abs() ); } else if ( isNumber() ) { setValue( Math.abs( getNumber() ) ); } else if ( isInteger() ) { setValue( Math.abs( getInteger() ) ); } else { throw new KettleValueException( "Function ABS only works with a number" ); } return this; }
public Value or( Value v ) { long n1 = getInteger(); long n2 = v.getInteger(); long res = n1 | n2; setValue( res ); return this; }
/** * Constructs a new Value of Type VALUE_TYPE_BINARY, with a name, containing a bytes value * * @param name * Sets the name of the Value * @param b * The bytes to store in this Value */ public Value( String name, byte[] b ) { clearValue(); setValue( b ); setName( name ); }
res.setName( rename[i] ); res.setType( type[i] ); case ValueMetaInterface.TYPE_NUMBER: if ( classname.equalsIgnoreCase( "org.mozilla.javascript.Undefined" ) ) { res.setNull(); } else if ( classname.equalsIgnoreCase( "org.mozilla.javascript.NativeJavaObject" ) ) { res.setValue( v.getNumber() ); } else { res.setValue( ( (Double) result ).doubleValue() ); res.setValue( ( (java.lang.Byte) result ).longValue() ); } else if ( classname.equalsIgnoreCase( "java.lang.Short" ) ) { res.setValue( ( (Short) result ).longValue() ); } else if ( classname.equalsIgnoreCase( "java.lang.Integer" ) ) { res.setValue( ( (Integer) result ).longValue() ); } else if ( classname.equalsIgnoreCase( "java.lang.Long" ) ) { res.setValue( ( (Long) result ).longValue() ); } else if ( classname.equalsIgnoreCase( "org.mozilla.javascript.Undefined" ) ) { res.setNull(); } else if ( classname.equalsIgnoreCase( "org.mozilla.javascript.NativeJavaObject" ) ) { res.setValue( v.getInteger() ); } else { res.setValue( Math.round( ( (Double) result ).doubleValue() ) ); res.setValue( v.getString() ); } catch ( Exception ev ) {
if ( isNull() || v.isNull() ) { setNull(); return this; if ( ( v.isString() && isNumeric() ) || ( v.isNumeric() && isString() ) ) { StringBuilder s; String append = ""; int n; if ( v.isString() ) { s = new StringBuilder( v.getString() ); append = v.getString(); n = (int) getInteger(); } else { s = new StringBuilder( getString() ); append = getString(); n = (int) v.getInteger(); setValue( s ); } else if ( isBigNumber() || v.isBigNumber() ) { setValue( ValueDataUtil.multiplyBigDecimals( getBigNumber(), v.getBigNumber(), null ) ); } else if ( isNumber() || v.isNumber() ) { setValue( getNumber() * v.getNumber() ); } else if ( isInteger() || v.isInteger() ) { setValue( getInteger() * v.getInteger() ); } else { throw new KettleValueException( "Multiplication can only be done with numbers or a number and a string!" );
public void writeObj( DataOutputStream dos ) throws IOException { int type = getType(); dos.writeInt( getType() ); dos.writeInt( getLength() ); dos.writeInt( getPrecision() ); dos.writeBoolean( isNull() ); if ( !isNull() ) { switch ( type ) { case VALUE_TYPE_STRING: if ( getString() == null ) { dos.writeInt( -1 ); // -1 == null string } else { String string = getString(); byte[] chars = string.getBytes( Const.XML_ENCODING ); dos.writeInt( chars.length ); if ( getBigNumber() == null ) { dos.writeInt( -1 ); // -1 == null string } else { String string = getBigNumber().toString(); dos.writeInt( string.length() ); dos.writeChars( string ); dos.writeBoolean( getDate() != null ); if ( getDate() != null ) { dos.writeLong( getDate().getTime() );
public Value trunc() throws KettleValueException { if ( isNull() ) { return this; // don't do anything, leave it at NULL! } if ( isInteger() ) { // Nothing return this; } if ( isBigNumber() ) { getBigNumber().setScale( 0, BigDecimal.ROUND_FLOOR ); } else if ( isNumber() ) { setValue( Math.floor( getNumber() ) ); } else if ( isDate() ) { Calendar cal = Calendar.getInstance(); cal.setTime( getDate() ); cal.set( Calendar.MILLISECOND, 0 ); cal.set( Calendar.SECOND, 0 ); cal.set( Calendar.MINUTE, 0 ); cal.set( Calendar.HOUR_OF_DAY, 0 ); setValue( cal.getTime() ); } else { throw new KettleValueException( "Function TRUNC only works on numbers and dates" ); } return this; }
if ( other == null || !getName().equals( other.getName() ) || getType() != other.getType() ) { return; switch ( getType() ) { case VALUE_TYPE_BIGNUMBER: if ( getBigNumber() == null ) { setValue( other.getBigNumber() ); if ( getBytes() == null || getBytes().length == 0 ) { if ( other.getBytes() != null && other.getBytes().length > 0 ) { setValue( other.getBytes() ); if ( getDate() == null ) { setValue( other.getDate() ); if ( getInteger() == 0l ) { setValue( other.getInteger() ); if ( getNumber() == 0.0 ) { setValue( other.getNumber() ); if ( Utils.isEmpty( getString() ) && !Utils.isEmpty( other.getString() ) ) { setValue( other.getString() );
public Value lpad( int len, String padstr ) { if ( isNull() ) { setType( VALUE_TYPE_STRING ); } else { if ( getType() != VALUE_TYPE_STRING ) { // also lpad other types! setValue( getString() ); } if ( getString() != null ) { StringBuilder result = new StringBuilder( getString() ); int pad = len; int l = ( pad - result.length() ) / padstr.length() + 1; int i; for ( i = 0; i < l; i++ ) { result.insert( 0, padstr ); } // Maybe we added one or two too many! i = result.length(); while ( i > pad && pad > 0 ) { result.deleteCharAt( 0 ); i--; } setValue( result.toString() ); } else { setNull(); } } setLength( len ); return this; }
/** * Constructs a new Value as a copy of another value * * @param v * The Value to be copied */ public Value( Value v ) { if ( v != null ) { // setType(v.getType()); // Is this really needed??? value = v.getValueCopy(); setName( v.getName() ); setLength( v.getLength(), v.getPrecision() ); setNull( v.isNull() ); setOrigin( v.origin ); } else { clearValue(); setNull( true ); } }
newValue( theType ); setName( new String( nameBuffer ) ); setLength( dis.readInt(), dis.readInt() ); setNull( dis.readBoolean() ); if ( !isNull() ) { switch ( getType() ) { case VALUE_TYPE_STRING: setValue( (String) null ); } else { byte[] chars = new byte[stringLength]; dis.readFully( chars ); setValue( new String( chars, Const.XML_ENCODING ) ); setValue( (BigDecimal) null ); } else { StringBuilder buffer = new StringBuilder(); setValue( buffer.toString() ); try { convertString( VALUE_TYPE_BIGNUMBER ); } catch ( KettleValueException e ) { throw new IOException( "Unable to convert String to BigNumber while reading from data input stream [" + getString() + "]" );
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; }
if ( value == null || value.isNull() ) { return null; return value.getString(); case ValueMetaInterface.TYPE_NUMBER: return value.getNumber(); case ValueMetaInterface.TYPE_INTEGER: return value.getInteger(); case ValueMetaInterface.TYPE_DATE: return value.getDate(); case ValueMetaInterface.TYPE_BOOLEAN: return value.getBoolean(); case ValueMetaInterface.TYPE_BIGNUMBER: return value.getBigNumber(); case ValueMetaInterface.TYPE_BINARY: return value.getBytes(); default: throw new KettleValueException( toString() + " : We can't convert original data type " + value.getTypeDesc() + " to a primitive data type" );
public Value divide( Value v ) throws KettleValueException { if ( isNull() || v.isNull() ) { setNull(); } else { switch ( getType() ) { case VALUE_TYPE_BIGNUMBER: setValue( getBigNumber().divide( v.getBigNumber(), BigDecimal.ROUND_HALF_UP ) ); break; case VALUE_TYPE_NUMBER: setValue( getNumber() / v.getNumber() ); break; case VALUE_TYPE_INTEGER: setValue( getInteger() / v.getInteger() ); break; case VALUE_TYPE_BOOLEAN: case VALUE_TYPE_STRING: default: throw new KettleValueException( "Division can only be done with numeric data!" ); } } return this; }
public Value plus( Value v ) { switch ( getType() ) { case VALUE_TYPE_BIGNUMBER: setValue( getBigNumber().add( v.getBigNumber() ) ); break; case VALUE_TYPE_NUMBER: setValue( getNumber() + v.getNumber() ); break; case VALUE_TYPE_INTEGER: setValue( getInteger() + v.getInteger() ); break; case VALUE_TYPE_BOOLEAN: setValue( getBoolean() | v.getBoolean() ); break; case VALUE_TYPE_STRING: setValue( getString() + v.getString() ); break; default: break; } return this; }