/** NOTE: the connection from java to matlab */ public RCvalue java2Matlab() throws EvalException { if (rc == null) { if (poly != null) { Value[] v = new Value[poly.degree()]; for (int i = 0; i < v.length; i++) { Point pt = poly.point(i); assert pt.type() == CohoDouble.type : "The result type is not CohoDouble, it is " + pt.type(); // if(pt.type()!=CohoDouble.type){ // throw new RuntimeException("The result type is not CohoDouble, it is "+pt.type() ); // } v[i] = RCvalue.factory() .create( new Value[] { DoubleValue.factory() .create(new Double(((CohoDouble) pt.x()).doubleValue()), null), DoubleValue.factory() .create(new Double(((CohoDouble) pt.y()).doubleValue()), null) }, false); } rc = (RCvalue) (RCvalue.factory().create(v, true)); } else { // empty polygon rc = (RCvalue) (RCvalue.factory().create(new Value[0], true)); } } return (rc); }
void ckDoubleValue(Value retValue) { Field theValueField = targetClass.fieldByName("edoubleValue"); DoubleValue theValue = (DoubleValue) targetClass.getValue(theValueField); double vv = theValue.value(); double rv = ((DoubleValue) retValue).value(); if (vv != rv) { failure("failure: double: expected " + vv + ", got " + rv); } else { System.out.println("Passed: double " + rv); earlyReturns++; } }
/** * @see * com.hardcode.gdbms.engine.instruction.expression.Operations#suma(com.hardcode.gdbms.engine.instruction.expression.Value) */ public Value suma(Value v) throws IncompatibleTypesException { if (v instanceof IntValue) { try { DoubleValue ret = new DoubleValue(); ret.setValue(Double.parseDouble(this.value) + ((IntValue) v).getValue()); return ret; } catch (NumberFormatException e) { throw new IncompatibleTypesException(getValue() + " is not a number"); } } else if (v instanceof LongValue) { try { DoubleValue ret = new DoubleValue(); ret.setValue(Double.parseDouble(this.value) + ((LongValue) v).getValue()); return ret; } catch (NumberFormatException e) { throw new IncompatibleTypesException(getValue() + " is not a number"); } } else if (v instanceof FloatValue) { try { DoubleValue ret = new DoubleValue(); ret.setValue(Double.parseDouble(this.value) + ((FloatValue) v).getValue()); return ret; } catch (NumberFormatException e) { throw new IncompatibleTypesException(getValue() + " is not a number"); } } else if (v instanceof DoubleValue) { try { DoubleValue ret = new DoubleValue(); ret.setValue(Double.parseDouble(this.value) + ((DoubleValue) v).getValue()); return ret; } catch (NumberFormatException e) { throw new IncompatibleTypesException(getValue() + " is not a number"); } } else if (v instanceof StringValue) { try { DoubleValue ret = new DoubleValue(); ret.setValue( Double.parseDouble(this.value) + Double.parseDouble(((StringValue) v).getValue())); return ret; } catch (NumberFormatException e) { throw new IncompatibleTypesException(getValue() + " is not a number"); } } else { throw new IncompatibleTypesException(); } }
public synchronized boolean equals(java.lang.Object obj) { if (!(obj instanceof DoubleValue)) return false; DoubleValue other = (DoubleValue) obj; if (obj == null) return false; if (this == obj) return true; if (__equalsCalc != null) { return (__equalsCalc == obj); } __equalsCalc = obj; boolean _equals; _equals = super.equals(obj) && ((this.number == null && other.getNumber() == null) || (this.number != null && this.number.equals(other.getNumber()))); __equalsCalc = null; return _equals; }
/* (non-Javadoc) * @see org.exist.xquery.value.Item#toJavaObject(java.lang.Class) */ public Object toJavaObject(Class target) throws XPathException { if (target.isAssignableFrom(UntypedAtomicValue.class)) return this; else if (target == Object.class || target == String.class || target == CharSequence.class) return value; else if (target == double.class || target == Double.class) { DoubleValue v = (DoubleValue) convertTo(Type.DOUBLE); return new Double(v.getValue()); } else if (target == float.class || target == Float.class) { FloatValue v = (FloatValue) convertTo(Type.FLOAT); return new Float(v.value); } else if (target == long.class || target == Long.class) { IntegerValue v = (IntegerValue) convertTo(Type.LONG); return new Long(v.getInt()); } else if (target == int.class || target == Integer.class) { IntegerValue v = (IntegerValue) convertTo(Type.INT); return new Integer(v.getInt()); } else if (target == short.class || target == Short.class) { IntegerValue v = (IntegerValue) convertTo(Type.SHORT); return new Short((short) v.getInt()); } else if (target == byte.class || target == Byte.class) { IntegerValue v = (IntegerValue) convertTo(Type.BYTE); return new Byte((byte) v.getInt()); } else if (target == boolean.class || target == Boolean.class) { return Boolean.valueOf(effectiveBooleanValue()); } else if (target == char.class || target == Character.class) { if (value.length() > 1 || value.length() == 0) throw new XPathException( "cannot convert string with length = 0 or length > 1 to Java character"); return new Character(value.charAt(0)); } throw new XPathException( "cannot convert value of type " + Type.getTypeName(getType()) + " to Java object of type " + target.getName()); }
public static Value objectToValue(Object obj) { if (obj == null) { return NullValue.NULL; } else if (Byte.class.equals(obj.getClass()) || Short.class.equals(obj.getClass()) || Integer.class.equals(obj.getClass()) || Long.class.equals(obj.getClass())) { return LongValue.create(((Number) obj).longValue()); } else if (Float.class.equals(obj.getClass()) || Double.class.equals(obj.getClass())) { return DoubleValue.create(((Number) obj).doubleValue()); } else if (String.class.equals(obj.getClass())) { // TODO: i18n return new StringValue((String) obj); } else { // TODO: unknown types, e.g. Character? return null; } }
@Override public void visit(DoubleValue dv) { ValueExpression ve = new ValueSpecification(_dblConv, dv.getValue()); _exprStack.push(ve); }
public int hashCode() { return super.hashCode() ^ doubleValue.hashCode(); }