本文整理了Java中org.bson.types.Decimal128.<init>()
方法的一些代码示例,展示了Decimal128.<init>()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Decimal128.<init>()
方法的具体详情如下:
包路径:org.bson.types.Decimal128
类名称:Decimal128
方法名:<init>
[英]Constructs a Decimal128 value representing the given long.
[中]构造一个十进制128值,表示给定的long。
代码示例来源:origin: org.mongodb/mongo-java-driver
/**
* Create an instance with the given high and low order bits representing this Decimal128 as an IEEE 754-2008 128-bit decimal
* floating point using the BID encoding scheme.
*
* @param high the high-order 64 bits
* @param low the low-order 64 bits
* @return the Decimal128 value representing the given high and low order bits
*/
public static Decimal128 fromIEEE754BIDEncoding(final long high, final long low) {
return new Decimal128(high, low);
}
代码示例来源:origin: org.mongodb/mongo-java-driver
@Override
public Decimal128 decimal128Value() {
return new Decimal128(value);
}
代码示例来源:origin: org.mongodb/mongo-java-driver
@Override
public Decimal128 decimal128Value() {
return new Decimal128(value);
}
代码示例来源:origin: org.mongodb/mongo-java-driver
@Override
public Decimal128 decimal128Value() {
if (Double.isNaN(value)) {
return Decimal128.NaN;
}
if (Double.isInfinite(value)) {
return value > 0 ? Decimal128.POSITIVE_INFINITY : Decimal128.NEGATIVE_INFINITY;
}
return new Decimal128(new BigDecimal(value));
}
代码示例来源:origin: MorphiaOrg/morphia
@Override
public Object encode(final Object value, final MappedField optionalExtraInfo) {
if (value instanceof BigDecimal) {
return new Decimal128((BigDecimal) value);
}
return super.encode(value, optionalExtraInfo);
}
}
代码示例来源:origin: org.mongodb/mongo-java-driver
@Override
public void encode(final BsonWriter writer, final BigDecimal value, final EncoderContext encoderContext) {
writer.writeDecimal128(new Decimal128(value));
}
代码示例来源:origin: immutables/immutables
@Override
public void writeNumber(BigDecimal number) throws IOException {
try {
writer.writeDecimal128(new Decimal128(number));
} catch (NumberFormatException e) {
writer.writeString(number.toString());
}
}
代码示例来源:origin: org.mongodb/mongo-java-driver
/**
* Returns a Decimal128 value representing the given String.
*
* @param value the Decimal128 value represented as a String
* @return the Decimal128 value representing the given String
* @throws NumberFormatException if the value is out of the Decimal128 range
* @see
* <a href="https://github.com/mongodb/specifications/blob/master/source/bson-decimal128/decimal128.rst#from-string-representation">
* From-String Specification</a>
*/
public static Decimal128 parse(final String value) {
String lowerCasedValue = value.toLowerCase();
if (NaN_STRINGS.contains(lowerCasedValue)) {
return NaN;
}
if (NEGATIVE_NaN_STRINGS.contains(lowerCasedValue)) {
return NEGATIVE_NaN;
}
if (POSITIVE_INFINITY_STRINGS.contains(lowerCasedValue)) {
return POSITIVE_INFINITY;
}
if (NEGATIVE_INFINITY_STRINGS.contains(lowerCasedValue)) {
return NEGATIVE_INFINITY;
}
return new Decimal128(new BigDecimal(value), value.charAt(0) == '-');
}
代码示例来源:origin: org.mongodb/mongo-java-driver
return clazz.cast(new Decimal128((Integer) value));
} else if (value instanceof Long) {
return clazz.cast(new Decimal128((Long) value));
} else if (value instanceof Double) {
return clazz.cast(new BsonDouble((Double) value).decimal128Value());
代码示例来源:origin: immutables/immutables
final BigDecimal decimal = (BigDecimal) value;
try {
return value(new Decimal128(decimal));
} catch (NumberFormatException ex) {
return value(new Decimal128(decimal));
} catch (NumberFormatException ex) {
代码示例来源:origin: org.mongodb/mongo-java-driver
try {
doubleValue = decimal128.doubleValue();
if (!decimal128.equals(new Decimal128(new BigDecimal(doubleValue)))) {
throw invalidConversion(Double.class, decimal128);
代码示例来源:origin: org.mongodb/mongo-java-driver
static long decodeLong(final BsonReader reader) {
long longValue;
BsonType bsonType = reader.getCurrentBsonType();
switch (bsonType) {
case INT32:
longValue = reader.readInt32();
break;
case INT64:
longValue = reader.readInt64();
break;
case DOUBLE:
double doubleValue = reader.readDouble();
longValue = (long) doubleValue;
if (doubleValue != (double) longValue) {
throw invalidConversion(Long.class, doubleValue);
}
break;
case DECIMAL128:
Decimal128 decimal128 = reader.readDecimal128();
longValue = decimal128.longValue();
if (!decimal128.equals(new Decimal128(longValue))) {
throw invalidConversion(Long.class, decimal128);
}
break;
default:
throw new BsonInvalidOperationException(format("Invalid numeric type, found: %s", bsonType));
}
return longValue;
}
代码示例来源:origin: org.mongodb/mongo-java-driver
Decimal128 decimal128 = reader.readDecimal128();
intValue = decimal128.intValue();
if (!decimal128.equals(new Decimal128(intValue))) {
throw invalidConversion(Integer.class, decimal128);
代码示例来源:origin: immutables/immutables
@Test
public void read() throws Exception {
BsonDocument doc = new BsonDocument();
doc.put("int", new BsonDecimal128(Decimal128.parse(Integer.toString(Integer.MAX_VALUE))));
doc.put("long", new BsonDecimal128(new Decimal128(Long.MAX_VALUE)));
doc.put("double", new BsonDecimal128(Decimal128.parse("12.111")));
JsonReader reader = Jsons.asGsonReader(doc);
reader.beginObject();
check(reader.nextName()).is("int");
check(reader.peek()).is(JsonToken.NUMBER);
check(reader.nextInt()).is(Integer.MAX_VALUE);
check(reader.nextName()).is("long");
check(reader.peek()).is(JsonToken.NUMBER);
check(reader.nextLong()).is(Long.MAX_VALUE);
check(reader.nextName()).is("double");
check(reader.peek()).is(JsonToken.NUMBER);
check(reader.nextDouble()).is(12.111D);
reader.endObject();
reader.close();
}
代码示例来源:origin: immutables/immutables
/**
* Serializing big numbers which can't be stored in {@link org.bson.types.Decimal128} format.
* They should be serialized as strings (or binary) in mongo.
*/
@Test
public void larger_than_decimal128() {
final AdvancedRepository repo = new AdvancedRepository(context.setup());
final ObjectId id = ObjectId.get();
final BigInteger integer = BigInteger.valueOf(Long.MAX_VALUE).pow(4);
try {
new Decimal128(new BigDecimal(integer));
fail("Should fail for " + integer);
} catch (NumberFormatException ignore) {
// expected
}
final Advanced doc = ImmutableAdvanced.builder()
.id(id)
.bigDecimal(new BigDecimal(integer)) // make number big
.bigInteger(integer) // make it also big
.atomicBoolean(new AtomicBoolean(false))
.atomicInteger(new AtomicInteger(1))
.atomicLong(new AtomicLong(2))
.build();
repo.insert(doc).getUnchecked();
final Advanced doc2 = repo.findById(id).fetchFirst().getUnchecked().get();
check(doc2.bigDecimal().unscaledValue()).is(integer);
check(doc2.bigInteger()).is(integer);
}
代码示例来源:origin: debezium/debezium
.append("_id", new Decimal128(new BigDecimal("123.45678")))
.append("name", "Sally");
event = new Document().append("o", obj)
代码示例来源:origin: org.mongodb.morphia/morphia
@Override
public Object encode(final Object value, final MappedField optionalExtraInfo) {
if (value instanceof BigDecimal) {
return new Decimal128((BigDecimal) value);
}
return super.encode(value, optionalExtraInfo);
}
}
代码示例来源:origin: ch.rasc/bsoncodec
@Override
public void encode(BsonWriter writer, BigDecimal value,
EncoderContext encoderContext) {
writer.writeDecimal128(new Decimal128(value));
}
代码示例来源:origin: hpgrahsl/kafka-connect-mongodb
@Override
public BsonValue toBson(Object data) {
if(data instanceof BigDecimal) {
if(format.equals(Format.DECIMAL128))
return new BsonDecimal128(new Decimal128((BigDecimal)data));
if(format.equals(Format.LEGACYDOUBLE))
return new BsonDouble(((BigDecimal)data).doubleValue());
}
throw new DataException("error: decimal conversion not possible when data is"
+ " of type "+data.getClass().getName() + " and format is "+format);
}
}
代码示例来源:origin: hpgrahsl/kafka-connect-mongodb
@Override
public BsonValue toBson(Object data) {
if(data instanceof BigDecimal) {
if(format.equals(Format.DECIMAL128))
return new BsonDecimal128(new Decimal128((BigDecimal)data));
if(format.equals(Format.LEGACYDOUBLE))
return new BsonDouble(((BigDecimal)data).doubleValue());
}
throw new DataException("error: decimal conversion not possible when data is"
+ " of type "+data.getClass().getName() + " and format is "+format);
}
}
内容来源于网络,如有侵权,请联系作者删除!