use of io.realm.entities.Owner in project realm-java by realm.
the class RealmLinkTests method populate.
private void populate() {
testRealm.beginTransaction();
testRealm.delete(Dog.class);
testRealm.delete(Cat.class);
testRealm.delete(Owner.class);
Dog dog1 = testRealm.createObject(Dog.class);
dog1.setName("Pluto");
dog1.setAge(5);
dog1.setHeight(1.2f);
dog1.setWeight(9.9);
dog1.setHasTail(true);
dog1.setBirthday(new Date(2000));
Dog dog2 = testRealm.createObject(Dog.class);
dog2.setName("Fido");
dog2.setAge(10);
dog2.setHeight(0.7f);
dog2.setWeight(11.3);
dog2.setHasTail(true);
dog2.setBirthday(new Date(4000));
Cat cat = testRealm.createObject(Cat.class);
cat.setName("Blackie");
cat.setAge(12);
cat.setHeight(0.3f);
cat.setWeight(1.1);
cat.setHasTail(true);
cat.setBirthday(new Date(6000));
Owner owner = testRealm.createObject(Owner.class);
owner.setName("Tim");
owner.getDogs().add(dog1);
owner.getDogs().add(dog2);
owner.setCat(cat);
cat.setOwner(owner);
dog1.setOwner(owner);
dog2.setOwner(owner);
testRealm.commitTransaction();
}
use of io.realm.entities.Owner in project realm-java by realm.
the class RealmResultsTests method populateRealmResultsOnLinkView.
private RealmResults<Dog> populateRealmResultsOnLinkView(Realm realm) {
realm.beginTransaction();
Owner owner = realm.createObject(Owner.class);
for (int i = 0; i < 10; i++) {
Dog dog = new Dog();
dog.setName("name_" + i);
dog.setOwner(owner);
dog.setAge(i);
dog.setBirthday(new Date(i));
owner.getDogs().add(dog);
}
realm.commitTransaction();
return owner.getDogs().where().lessThan(Dog.FIELD_AGE, 5).findAll();
}
use of io.realm.entities.Owner in project realm-java by realm.
the class RealmLinkTests method objects.
@Test
public void objects() {
RealmResults<Owner> owners = testRealm.where(Owner.class).findAll();
assertEquals(1, owners.size());
assertEquals(2, owners.first().getDogs().size());
assertEquals("Pluto", owners.first().getDogs().first().getName());
assertEquals("Fido", owners.first().getDogs().last().getName());
assertEquals("Blackie", owners.first().getCat().getName());
assertEquals(12, owners.first().getCat().getAge());
RealmResults<Dog> dogs = testRealm.where(Dog.class).findAll();
assertEquals(2, dogs.size());
for (Dog dog : dogs) {
assertEquals("Tim", dog.getOwner().getName());
}
RealmResults<Cat> cats = testRealm.where(Cat.class).findAll();
assertEquals(1, cats.size());
assertEquals("Tim", cats.first().getOwner().getName());
}
use of io.realm.entities.Owner in project realm-java by realm.
the class OrderedCollectionChangeSetTests method createObjects.
// Creates Dogs objects with columnLong set to the value elements in indices array.
private void createObjects(Realm realm, int... indices) {
for (int index : indices) {
Dog dog = realm.createObject(Dog.class);
dog.setAge(index);
if (type == ObservablesType.REALM_LIST) {
Owner owner = realm.where(Owner.class).findFirst();
assertNotNull(owner);
RealmList<Dog> dogs = owner.getDogs();
boolean added = false;
// Insert the newly created dog to the RealmList by the order of age.
for (int i = 0; i < dogs.size(); i++) {
if (dog.getAge() <= dogs.get(i).getAge()) {
dogs.add(i, dog);
added = true;
break;
}
}
if (!added) {
dogs.add(dog);
}
}
}
}
use of io.realm.entities.Owner in project realm-java by realm.
the class OrderedCollectionChangeSetTests method populateData.
private void populateData(Realm realm, int testSize) {
Owner owner = null;
realm.beginTransaction();
if (type == ObservablesType.REALM_LIST) {
owner = realm.createObject(Owner.class);
}
for (int i = 0; i < testSize; i++) {
Dog dog = realm.createObject(Dog.class);
dog.setAge(i);
if (type == ObservablesType.REALM_LIST) {
owner.getDogs().add(dog);
}
}
realm.commitTransaction();
}
Aggregations