use of org.bson.types.Decimal128 in project realm-java by realm.
the class RealmResultsTests method populateMappedAllJavaTypes.
private void populateMappedAllJavaTypes(int objects) {
realm.beginTransaction();
realm.deleteAll();
for (int i = 0; i < objects; ++i) {
MappedAllJavaTypes obj = realm.createObject(MappedAllJavaTypes.class, i);
obj.fieldBoolean = ((i % 2) == 0);
obj.fieldBinary = (new byte[] { 1, 2, 3 });
obj.fieldDate = (new Date(YEAR_MILLIS * (i - objects / 2)));
obj.fieldDouble = (Math.PI + i);
obj.fieldFloat = (1.234567f + i);
obj.fieldString = ("test data " + i);
obj.fieldLong = i;
obj.fieldObject = obj;
obj.fieldDecimal128 = new Decimal128(i);
obj.fieldObjectId = new ObjectId(TestHelper.generateObjectIdHexString(i));
obj.fieldUUID = UUID.fromString(TestHelper.generateUUIDString(i));
obj.fieldList.add(obj);
}
realm.commitTransaction();
}
use of org.bson.types.Decimal128 in project realm-java by realm.
the class RealmResultsTests method populateAllJavaTypes.
private void populateAllJavaTypes(int objects) {
realm.beginTransaction();
realm.deleteAll();
for (int i = 0; i < objects; ++i) {
AllJavaTypes obj = realm.createObject(AllJavaTypes.class, i);
obj.setFieldBoolean((i % 2) == 0);
obj.setFieldBinary(new byte[] { 1, 2, 3 });
obj.setFieldDate(new Date(YEAR_MILLIS * (i - objects / 2)));
obj.setFieldDouble(Math.PI + i);
obj.setFieldFloat(1.234567f + i);
obj.setFieldString("test data " + i);
obj.setFieldLong(i);
obj.setFieldObject(obj);
obj.setFieldDecimal128(new Decimal128(new BigDecimal(i + ".23456789")));
obj.setFieldObjectId(new ObjectId(TestHelper.generateObjectIdHexString(i)));
obj.setFieldUUID(UUID.fromString(TestHelper.generateUUIDString(i)));
obj.getFieldList().add(obj);
}
realm.commitTransaction();
}
use of org.bson.types.Decimal128 in project realm-java by realm.
the class RealmResultsTests method asJSON.
@Test
public void asJSON() throws JSONException {
Date date = Calendar.getInstance().getTime();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
// Core return dates in UTC time
sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
String now = sdf.format(date);
realm.beginTransaction();
AllTypes allTypes = realm.createObject(AllTypes.class);
Dog dog1 = realm.createObject(Dog.class);
Dog dog2 = realm.createObject(Dog.class);
Dog dog3 = realm.createObject(Dog.class);
dog1.setName("dog1");
dog1.setAge(1);
dog1.setBirthday(date);
dog1.setHasTail(true);
dog1.setHeight(1.1f);
dog1.setWeight(10.1f);
dog2.setName("dog2");
dog2.setAge(2);
dog2.setBirthday(date);
dog2.setHasTail(false);
dog2.setHeight(2.1f);
dog2.setWeight(20.1f);
dog3.setName("dog3");
dog3.setAge(3);
dog3.setBirthday(date);
dog3.setHasTail(true);
dog3.setHeight(3.1f);
dog3.setWeight(30.1f);
Owner owner = realm.createObject(Owner.class);
owner.setName("Dog owner 1");
dog3.setOwner(owner);
allTypes.setColumnString("alltypes1");
allTypes.setColumnLong(1337L);
allTypes.setColumnFloat(3.14f);
allTypes.setColumnDouble(0.89123);
allTypes.setColumnBoolean(false);
allTypes.setColumnDate(date);
allTypes.setColumnDecimal128(new Decimal128(new BigDecimal("0.123456789")));
allTypes.setColumnObjectId(new ObjectId(TestHelper.generateObjectIdHexString(7)));
allTypes.setColumnUUID(UUID.fromString(uuid1));
allTypes.setColumnBinary(new byte[] { 1, 2, 3 });
allTypes.setColumnMutableRealmInteger(0);
allTypes.setColumnRealmObject(dog1);
allTypes.getColumnRealmList().add(dog2);
allTypes.getColumnRealmList().add(dog3);
allTypes.getColumnStringList().add("Foo");
allTypes.getColumnStringList().add("Bar");
allTypes.getColumnBooleanList().add(false);
allTypes.getColumnBooleanList().add(true);
allTypes.getColumnLongList().add(1000L);
allTypes.getColumnLongList().add(2000L);
allTypes.getColumnDoubleList().add(1.123);
allTypes.getColumnDoubleList().add(5.321);
allTypes.getColumnFloatList().add(0.12f);
allTypes.getColumnFloatList().add(0.13f);
allTypes.getColumnDateList().add(date);
allTypes.getColumnDateList().add(date);
allTypes.getColumnDecimal128List().add(new Decimal128(-42));
allTypes.getColumnDecimal128List().add(Decimal128.NaN);
allTypes.getColumnDecimal128List().add(Decimal128.NEGATIVE_ZERO);
allTypes.getColumnDecimal128List().add(Decimal128.POSITIVE_ZERO);
allTypes.getColumnDecimal128List().add(Decimal128.NEGATIVE_INFINITY);
allTypes.getColumnDecimal128List().add(Decimal128.POSITIVE_INFINITY);
allTypes.getColumnObjectIdList().add(new ObjectId(TestHelper.generateObjectIdHexString(1)));
allTypes.getColumnObjectIdList().add(new ObjectId(TestHelper.generateObjectIdHexString(2)));
allTypes.getColumnUUIDList().add(UUID.fromString(uuid1));
allTypes.getColumnUUIDList().add(UUID.fromString(uuid2));
AllTypes allTypes2 = realm.createObject(AllTypes.class);
allTypes2.setColumnString("alltypes2");
realm.commitTransaction();
RealmResults<AllTypes> all = realm.where(AllTypes.class).equalTo("columnString", "alltypes1").findAll();
assertEquals(1, all.size());
String json = all.asJSON();
final String expectedJSON = "[\n" + " {\n" + " \"_key\":100,\n" + " \"columnString\":\"alltypes1\",\n" + " \"columnLong\":1337,\n" + " \"columnFloat\":3.1400001e+00,\n" + " \"columnDouble\":8.9122999999999997e-01,\n" + " \"columnBoolean\":false,\n" + " \"columnDate\": \"" + now + "\",\n" + " \"columnBinary\":\"AQID\",\n" + " \"columnDecimal128\":\"1.23456789E-1\",\n" + " \"columnObjectId\":\"789abcdef0123456789abcde\",\n" + " \"columnUUID\":\"" + uuid1 + "\",\n" + " \"columnMutableRealmInteger\":0,\n" + " \"columnRealmObject\":{\n" + " \"_key\":100,\n" + " \"name\":\"dog1\",\n" + " \"age\":1,\n" + " \"height\":1.1000000e+00,\n" + " \"weight\":1.0100000381469727e+01,\n" + " \"hasTail\":true,\n" + " \"birthday\": \"" + now + "\",\n" + " \"owner\":null\n" + " },\n" + " \"columnRealmList\":[\n" + " {\n" + " \"_key\":101,\n" + " \"name\":\"dog2\",\n" + " \"age\":2,\n" + " \"height\":2.0999999e+00,\n" + " \"weight\":2.0100000381469727e+01,\n" + " \"hasTail\":false,\n" + " \"birthday\": \"" + now + "\",\n" + " \"owner\":null\n" + " },\n" + " {\n" + " \"_key\":102,\n" + " \"name\":\"dog3\",\n" + " \"age\":3,\n" + " \"height\":3.0999999e+00,\n" + " \"weight\":3.0100000381469727e+01,\n" + " \"hasTail\":true,\n" + " \"birthday\": \"" + now + "\",\n" + " \"owner\":{\n" + " \"_key\":0,\n" + " \"name\":\"Dog owner 1\",\n" + " \"dogs\":[\n" + "\n" + " ],\n" + " \"cat\":null\n" + " }\n" + " }\n" + " ],\n" + " \"columnStringList\":[\n" + " \"Foo\",\n" + " \"Bar\"\n" + " ],\n" + " \"columnBinaryList\":[\n" + "\n" + " ],\n" + " \"columnBooleanList\":[\n" + " false,\n" + " true\n" + " ],\n" + " \"columnLongList\":[\n" + " 1000,\n" + " 2000\n" + " ],\n" + " \"columnDoubleList\":[\n" + " 1.1230000000000000e+00,\n" + " 5.3209999999999997e+00\n" + " ],\n" + " \"columnFloatList\":[\n" + " 1.2000000e-01,\n" + " 1.3000000e-01\n" + " ],\n" + " \"columnDateList\":[\n" + " \"" + now + "\",\n" + " \"" + now + "\"\n" + " ],\n" + " \"columnDecimal128List\":[\n" + " \"-42\",\n" + " \"NaN\",\n" + " \"-0\",\n" + " \"0\",\n" + " \"-Inf\",\n" + " \"Inf\"\n" + " ],\n" + " \"columnObjectIdList\":[\n" + " \"123456789abcdef012345678\",\n" + " \"23456789abcdef0123456789\"\n" + " ],\n" + " \"columnUUIDList\":[\n" + " \"" + uuid1 + "\",\n" + " \"" + uuid2 + "\"\n" + " ]\n" + " }\n" + "]";
JSONAssert.assertEquals(expectedJSON, json, false);
}
use of org.bson.types.Decimal128 in project realm-java by realm.
the class RealmQueryTests method notEqualTo_decimal128.
@Test
public void notEqualTo_decimal128() {
populateTestRealm(realm, 10);
RealmResults<AllTypes> resultList = realm.where(AllTypes.class).notEqualTo(AllTypes.FIELD_DECIMAL128, new Decimal128(new BigDecimal("0.23456789"))).sort(AllTypes.FIELD_UUID, Sort.ASCENDING).findAll();
assertEquals(9, resultList.size());
for (int i = 1; i < 10; i++) {
assertNotEquals(new Decimal128(new BigDecimal("0.23456789")), resultList.get(0).getColumnDecimal128());
}
}
use of org.bson.types.Decimal128 in project realm-java by realm.
the class RealmQueryTests method equalTo_decimal128.
@Test
public void equalTo_decimal128() {
populateTestRealm(realm, 10);
for (int i = 0; i < 10; i++) {
RealmResults<AllTypes> resultList = realm.where(AllTypes.class).equalTo(AllTypes.FIELD_DECIMAL128, new Decimal128(new BigDecimal(i + ".23456789"))).sort(AllTypes.FIELD_DECIMAL128, Sort.ASCENDING).findAll();
assertEquals(1, resultList.size());
assertEquals(new Decimal128(new BigDecimal(i + ".23456789")), resultList.get(0).getColumnDecimal128());
}
}
Aggregations