public static DecimalNode valueOf(long binValue, int scale) { if ( scale < MIN_SCALE || scale > MAX_SCALE ) { //log.warn("Scale out of range: ("+binValue+","+scale+")") ; return null ; } if ( binValue < MIN_VALUE || binValue > MAX_VALUE ) { //log.warn("Value out of range: ("+binValue+","+scale+")") ; return null ; } return new DecimalNode(binValue, scale) ; }
@Override public String toString() { return get().toPlainString() ; }
public static DecimalNode valueOf(BigDecimal decimal) { int scale = decimal.scale() ; BigInteger bigInt = decimal.unscaledValue() ; if ( bigInt.compareTo(MAX_I) > 0 || bigInt.compareTo(MIN_I) < 0 ) // This check makes sure that bigInt.longValue() is safe return null ; return valueOf(bigInt.longValue(), scale) ; }
public static long pack(long value, int scale) { // pack : DECIMAL , sign, scale, value long v = BitsLong.pack(0, NodeId.DECIMAL, ENC_LEN, Long.SIZE) ; v = BitsLong.pack(v, scale, SCALE_LO, SCALE_HI) ; v = BitsLong.pack(v, value, VALUE_LO, VALUE_HI) ; // No need to do something about negative numbers return v ; }
BigDecimal d = DecimalNode.unpackAsBigDecimal(v) ; String x = d.toPlainString() ; return NodeFactory.createLiteral(x, XSDDatatype.XSDdecimal) ;
public static DecimalNode unpack(long v) { //assert BitsLong.unpack(v, 56, 64) == NodeId.DECIMAL ; int scale = (int)BitsLong.unpack(v, SCALE_LO, SCALE_HI) ; long value = BitsLong.unpack(v, VALUE_LO, VALUE_HI) ; return new DecimalNode(value, scale) ; }