/** * Compares this BSONDecimal with the specified BSONDecimal. * Two BSONDecimal objects that are * equal in value(this method does not consider precision and scale, * so 2.0 and 2.00 are considered equal by this method). * This method is provided in preference to individual * methods for each of the six boolean * comparison operators (<, ==, >, >=, !=, <=). * The suggested idiom for performing these comparisons is: * (x.compareTo(y) <<i>op</i>> 0), where <<i>op</i>> is * one of the six comparison operators. * @param other BSONDecimal to which this BSONDecimal is * to be compared. * @return -1, 0, or 1 as this BSONDecimal is numerically * less than, equal to, or greater than val. */ @Override public int compareTo(BSONDecimal other) { if (other == null) { return 1; } return _compareTo(other); }
/** * @param value * the decimal value which is in the format of string, e.g. * "3.14159265358" * @param precision * the precision of decimal number * @param scale * the total count of decimal digits in the fractional part, to * the right of the decimal point. * @throws IllegalArgumentException if null pointer or invalid value */ public BSONDecimal(String value, int precision, int scale) { _fromStringValue(value, precision, scale); _value = _getValue(); if (!_isSpecial(this)) { _precision = precision; _scale = scale; } else { _precision = -1; _scale = -1; } }
/** * Transform a BigDecimal object to a BSONDecimal object. * The meaning of "precision" and "scale" defined in BSONDecimal are * different from that defined by BigDecimal. We deprecate "precision" * and "scale" defined in BigDecimal. Actually we build BSONDecimal like * this: * <pre> * BSONDecimal(value.toString().trim()); // value is a BigDecimal object * </pre> * <p> * and set "precision" and "scale" to be -1 in the newly built BSONDecimal * object. * </p> * @param value * a BigDecimal to be transformed * @throws IllegalArgumentException if null pointer or invalid value * @see #toBigDecimal() */ public BSONDecimal(BigDecimal value) { if (value == null) { throw new IllegalArgumentException("decimal value can't be null"); } String str = value.toString(); _fromStringValue(str, -1, -1); _value = _getValue(); _precision = -1; _scale = -1; }
_init(value, precision, scale); && (cp[1] == 'a' || cp[1] == 'A') && (cp[2] == 'n' || cp[2] == 'N')) { _setNan(); _update(); return; && (cp[1] == 'i' || cp[1] == 'I') && (cp[2] == 'n' || cp[2] == 'N')) { _setMin(); _update(); return; && (cp[1] == 'a' || cp[1] == 'A') && (cp[2] == 'x' || cp[2] == 'X')) { _setMax(); _update(); return; && (cp[1] == 'n' || cp[1] == 'N') && (cp[2] == 'f' || cp[2] == 'F')) { _setMax(); _update(); return; && (cp[2] == 'n' || cp[2] == 'N') && (cp[3] == 'f' || cp[3] == 'F')) { _setMin();
String retStr = null; int expect_char_size = _getExpectCharSize(); char[] cp = new char[expect_char_size]; int cp_idx = 0; int cp_idx_end = 0; if (_isNan(this)) { cp[0] = 'N'; cp[1] = 'a'; if (_isMin(this)) { cp[0] = 'M'; cp[1] = 'I'; if (_isMax(this)) { cp[0] = 'M'; cp[1] = 'A';
public void serialize(Object obj, StringBuilder buf) { BasicBSONObject temp = new BasicBSONObject(); BSONDecimal t = null; if (obj instanceof BigDecimal) { t = new BSONDecimal((BigDecimal)obj); } else { t = (BSONDecimal)obj; } String data = t.getValue(); int precision = t.getPrecision(); int scale = t.getScale(); temp.put("$decimal", data); if (precision != -1 || scale != -1) { BSONObject arr = new BasicBSONList(); arr.put("0", precision); arr.put("1", scale); temp.put("$precision", arr); } serializer.serialize(temp, buf); }
_value = _getValue(); _precision = _getPrecision(); _scale = _getScale();
String className = value.getClass().getName(); if (className.equals("java.math.BigDecimal")) { method.invoke(object, new BSONDecimal((BigDecimal) value)); } else if (className.equals("org.bson.types.BSONDecimal")) { method.invoke(object, (BSONDecimal) value); method.invoke(object, (BigDecimal) value); } else if (className.equals("org.bson.types.BSONDecimal")) { method.invoke(object, ((BSONDecimal) value).toBigDecimal()); } else { throw new IllegalArgumentException("The method: "
protected void putNumber(String name, Number n) { if (n instanceof Integer || n instanceof Short || n instanceof Byte || n instanceof AtomicInteger) { _put(NUMBER_INT, name); _buf.writeInt(n.intValue()); } else if (n instanceof Long || n instanceof AtomicLong) { _put(NUMBER_LONG, name); _buf.writeLong(n.longValue()); } else if (n instanceof Float || n instanceof Double) { _put(NUMBER, name); _buf.writeDouble(n.doubleValue()); } else if (n instanceof BigDecimal) { putDecimal(name, new BSONDecimal((BigDecimal)n)); } else { throw new IllegalArgumentException("can't serialize " + n.getClass()); } }
o = new BSONDecimal(str, precision, scale); if (!isStackEmpty()) { cur().put(name, o);
BSONDecimal decimal = new BSONDecimal(size, typeMod, signScale, weight, digits); _callback.gotDecimal(name, decimal); return true;
BSONDecimal decimal = new BSONDecimal(size, typeMod, signScale, weight, digits); _callback.gotDecimal( name, decimal ); break;