public static NodeValue javaSubstring(NodeValue nvString, NodeValue nvStart, NodeValue nvFinish) { try { String string = nvString.getString() ; int start = nvStart.getInteger().intValue() ; if ( nvFinish == null ) return NodeValue.makeString(string.substring(start)) ; int finish = nvFinish.getInteger().intValue() ; return NodeValue.makeString(string.substring(start, finish)) ; } catch (IndexOutOfBoundsException ex) { throw new ExprEvalException("IndexOutOfBounds", ex) ; } }
public static NodeValue javaSubstring(NodeValue nvString, NodeValue nvStart, NodeValue nvFinish) { try { String string = nvString.getString() ; int start = nvStart.getInteger().intValue() ; if ( nvFinish == null ) return NodeValue.makeString(string.substring(start)) ; int finish = nvFinish.getInteger().intValue() ; return NodeValue.makeString(string.substring(start, finish)) ; } catch (IndexOutOfBoundsException ex) { throw new ExprEvalException("IndexOutOfBounds", ex) ; } }
@Override public NodeValue exec(NodeValue nv) { if ( ! nv.isInteger() ) throw new ExprEvalException("Not an integer") ; int x = nv.getInteger().intValue() ; Lib.sleep(x) ; return NodeValue.TRUE ; } }
@Override public NodeValue exec(NodeValue v1, NodeValue v2) { switch (XSDFuncOp.classifyNumeric("pow", v1)) { case OP_INTEGER: BigInteger i = v1.getInteger(); return NodeValue.makeInteger( i.pow(v2.getInteger().intValue()) ); case OP_DECIMAL: double dec = v1.getDecimal().doubleValue() ; return NodeValue.makeDecimal( Math.pow(dec, v2.getDouble())) ; case OP_FLOAT: // TODO Should raising a float to a power keep it a float? case OP_DOUBLE: return NodeValue.makeDouble( Math.pow(v1.getDouble(), v2.getDouble()) ) ; default: throw new ARQInternalErrorException("Unrecognized numeric operation : "+ v1) ; } }
private static int intValueStr(NodeValue nv, int valueNan) { if ( nv.isInteger() ) return nv.getInteger().intValue() ; if ( nv.isDecimal() ) // No decimal round in Java 1.4 return (int)Math.round(nv.getDecimal().doubleValue()) ; if ( nv.isFloat() ) { float f = nv.getFloat() ; if ( Float.isNaN(f)) return valueNan ; return Math.round(f) ; } if ( nv.isDouble() ) { double d = nv.getDouble() ; if ( Double.isNaN(d)) return valueNan ; return (int)Math.round(d) ; } throw new ExprEvalException("Not a number:"+nv) ; }
@Override public NodeValue exec(NodeValue v) { switch (XSDFuncOp.classifyNumeric("sq", v)) { case OP_INTEGER: BigInteger i = v.getInteger(); return NodeValue.makeInteger( i.pow(2) ); case OP_DECIMAL: double dec = v.getDecimal().doubleValue() ; return NodeValue.makeDecimal( Math.pow(dec, 2d)) ; case OP_FLOAT: // TODO Should squaring a float keep it a float? case OP_DOUBLE: return NodeValue.makeDouble( Math.pow(v.getDouble(), 2d) ) ; default: throw new ARQInternalErrorException("Unrecognized numeric operation : "+v) ; } }
@Override public NodeValue exec(NodeValue v) { switch (XSDFuncOp.classifyNumeric("cube", v)) { case OP_INTEGER: BigInteger i = v.getInteger(); return NodeValue.makeInteger( i.pow(3) ); case OP_DECIMAL: double dec = v.getDecimal().doubleValue() ; return NodeValue.makeDecimal( Math.pow(dec, 3d)) ; case OP_FLOAT: // TODO Should squaring a float keep it a float? case OP_DOUBLE: return NodeValue.makeDouble( Math.pow(v.getDouble(), 3d) ) ; default: throw new ARQInternalErrorException("Unrecognized numeric operation : "+v) ; } }
@Override public NodeValue exec(NodeValue x) { if ( ! x.isInteger() ) throw new ExprEvalException("evenInteger: Not an intger: "+x) ; int i = x.getInteger().getLowestSetBit() ; boolean b = (i == -1) || ( i != 0 ) ; return NodeValue.makeNodeBoolean( b ) ; }
public static int compareNumeric(NodeValue nv1, NodeValue nv2) { NumericType opType = classifyNumeric("compareNumeric", nv1, nv2) ; switch (opType) { case OP_INTEGER: return calcReturn(nv1.getInteger().compareTo(nv2.getInteger())) ; case OP_DECIMAL: return calcReturn(nv1.getDecimal().compareTo(nv2.getDecimal())) ; case OP_FLOAT: return calcReturn(Float.compare(nv1.getFloat(), nv2.getFloat())) ; case OP_DOUBLE: return calcReturn(Double.compare(nv1.getDouble(), nv2.getDouble())) ; default: throw new ARQInternalErrorException("Unrecognized numeric operation : ("+nv1+" ," +nv2+")") ; } }
public static NodeValue abs(NodeValue nv) { switch (classifyNumeric("abs", nv)) { case OP_INTEGER: return NodeValue.makeInteger(nv.getInteger().abs()) ; case OP_DECIMAL: return NodeValue.makeDecimal(nv.getDecimal().abs()) ; case OP_FLOAT: return NodeValue.makeFloat( Math.abs(nv.getFloat()) ) ; case OP_DOUBLE: return NodeValue.makeDouble( Math.abs(nv.getDouble()) ) ; default: throw new ARQInternalErrorException("Unrecognized numeric operation : "+nv) ; } }
@Override public NodeValue exec(NodeValue x) { if ( ! x.isInteger() ) throw new ExprEvalException("evenInteger: Not an intger: "+x) ; int i = x.getInteger().getLowestSetBit() ; boolean b = (i == -1) || ( i != 0 ) ; return NodeValue.makeNodeBoolean( b ) ; }
public static int compareNumeric(NodeValue nv1, NodeValue nv2) { NumericType opType = classifyNumeric("compareNumeric", nv1, nv2) ; switch (opType) { case OP_INTEGER: return calcReturn(nv1.getInteger().compareTo(nv2.getInteger())) ; case OP_DECIMAL: return calcReturn(nv1.getDecimal().compareTo(nv2.getDecimal())) ; case OP_FLOAT: return calcReturn(Float.compare(nv1.getFloat(), nv2.getFloat())) ; case OP_DOUBLE: return calcReturn(Double.compare(nv1.getDouble(), nv2.getDouble())) ; default: throw new ARQInternalErrorException("Unrecognized numeric operation : ("+nv1+" ," +nv2+")") ; } }
public static NodeValue abs(NodeValue nv) { switch (classifyNumeric("abs", nv)) { case OP_INTEGER: return NodeValue.makeInteger(nv.getInteger().abs()) ; case OP_DECIMAL: return NodeValue.makeDecimal(nv.getDecimal().abs()) ; case OP_FLOAT: return NodeValue.makeFloat( Math.abs(nv.getFloat()) ) ; case OP_DOUBLE: return NodeValue.makeDouble( Math.abs(nv.getDouble()) ) ; default: throw new ARQInternalErrorException("Unrecognized numeric operation : "+nv) ; } }
public static NodeValue add(NodeValue nv1, NodeValue nv2) // F&O numeric-add { switch (classifyNumeric("add", nv1, nv2)) { case OP_INTEGER: return NodeValue.makeInteger(nv1.getInteger().add(nv2.getInteger())) ; case OP_DECIMAL: return NodeValue.makeDecimal(nv1.getDecimal().add(nv2.getDecimal())) ; case OP_FLOAT: return NodeValue.makeFloat(nv1.getFloat() + nv2.getFloat()) ; case OP_DOUBLE: return NodeValue.makeDouble(nv1.getDouble() + nv2.getDouble()) ; default: throw new ARQInternalErrorException("Unrecognized numeric operation : ("+nv1+" ," +nv2+")") ; } }
public static NodeValue numMultiply(NodeValue nv1, NodeValue nv2) // F&O numeric-multiply { switch (classifyNumeric("multiply", nv1, nv2)) { case OP_INTEGER: return NodeValue.makeInteger(nv1.getInteger().multiply(nv2.getInteger())) ; case OP_DECIMAL: return NodeValue.makeDecimal(nv1.getDecimal().multiply(nv2.getDecimal())) ; case OP_FLOAT: return NodeValue.makeFloat(nv1.getFloat() * nv2.getFloat()) ; case OP_DOUBLE: return NodeValue.makeDouble(nv1.getDouble() * nv2.getDouble()) ; default: throw new ARQInternalErrorException("Unrecognized numeric operation : ("+nv1+" ," +nv2+")") ; } }
public static NodeValue subtract(NodeValue nv1, NodeValue nv2) // F&O numeric-subtract { switch (classifyNumeric("subtract", nv1, nv2)) { case OP_INTEGER: return NodeValue.makeInteger(nv1.getInteger().subtract(nv2.getInteger())) ; case OP_DECIMAL: return NodeValue.makeDecimal(nv1.getDecimal().subtract(nv2.getDecimal())) ; case OP_FLOAT: return NodeValue.makeFloat(nv1.getFloat() - nv2.getFloat()) ; case OP_DOUBLE: return NodeValue.makeDouble(nv1.getDouble() - nv2.getDouble()) ; default: throw new ARQInternalErrorException("Unrecognized numeric operation : ("+nv1+" ," +nv2+")") ; } }
public static NodeValue multiply(NodeValue nv1, NodeValue nv2) // F&O numeric-multiply { switch (classifyNumeric("multiply", nv1, nv2)) { case OP_INTEGER: return NodeValue.makeInteger(nv1.getInteger().multiply(nv2.getInteger())) ; case OP_DECIMAL: return NodeValue.makeDecimal(nv1.getDecimal().multiply(nv2.getDecimal())) ; case OP_FLOAT: return NodeValue.makeFloat(nv1.getFloat() * nv2.getFloat()) ; case OP_DOUBLE: return NodeValue.makeDouble(nv1.getDouble() * nv2.getDouble()) ; default: throw new ARQInternalErrorException("Unrecognized numeric operation : ("+nv1+" ," +nv2+")") ; } }
public static NodeValue unaryMinus(NodeValue nv) // F&O numeric-unary-minus { switch (classifyNumeric("unaryMinus", nv)) { case OP_INTEGER: return NodeValue.makeInteger( nv.getInteger().negate() ) ; case OP_DECIMAL: return NodeValue.makeDecimal( nv.getDecimal().negate() ) ; case OP_FLOAT: return NodeValue.makeFloat( - nv.getFloat() ) ; case OP_DOUBLE: return NodeValue.makeDouble( - nv.getDouble() ) ; default: throw new ARQInternalErrorException("Unrecognized numeric operation : "+nv) ; } }
private static BigInteger buildInteger(Item item, boolean allowDefault) { //Item item = list.get(idx) ; if ( allowDefault && item.equals(Item.defaultItem) ) return null ; if ( !item.isNode() ) BuilderLib.broken(item, "Not an integer: "+item) ; Node node = item.getNode() ; if ( ! node.isLiteral() ) BuilderLib.broken(item, "Not an integer: "+item) ; NodeValue nv = NodeValue.makeNode(node) ; if ( ! nv.isInteger() ) BuilderLib.broken(item, "Not an integer: "+item) ; return nv.getInteger() ; }
private static BigInteger buildInteger(Item item, boolean allowDefault) { //Item item = list.get(idx) ; if ( allowDefault && item.equals(Item.defaultItem) ) return null ; if ( !item.isNode() ) BuilderLib.broken(item, "Not an integer: "+item) ; Node node = item.getNode() ; if ( ! node.isLiteral() ) BuilderLib.broken(item, "Not an integer: "+item) ; NodeValue nv = NodeValue.makeNode(node) ; if ( ! nv.isInteger() ) BuilderLib.broken(item, "Not an integer: "+item) ; return nv.getInteger() ; }