use of com.canoo.dp.impl.platform.core.IdentitySet in project dolphin-platform by canoo.
the class GarbageCollector method getAllLists.
private IdentitySet<ObservableList> getAllLists(Object bean) {
IdentitySet<ObservableList> ret = new IdentitySet<>();
List<Field> fields = listFieldCache.get(bean.getClass());
if (fields == null) {
fields = new ArrayList<>();
for (Field field : ReflectionHelper.getInheritedDeclaredFields(bean.getClass())) {
if (ObservableList.class.isAssignableFrom(field.getType())) {
fields.add(field);
}
}
listFieldCache.put(bean.getClass(), fields);
}
for (Field field : fields) {
ret.add((ObservableList) ReflectionHelper.getPrivileged(field, bean));
}
return ret;
}
use of com.canoo.dp.impl.platform.core.IdentitySet in project dolphin-platform by canoo.
the class IdentitySetTest method testAddSame.
@Test
public void testAddSame() {
IdentitySet<Date> identitySet = new IdentitySet<>();
Date date1 = new Date();
Date date2 = date1;
Date date3 = new Date(date1.getTime());
identitySet.add(date1);
Assert.assertFalse(identitySet.isEmpty());
Assert.assertEquals(identitySet.size(), 1);
boolean added = identitySet.add(date2);
Assert.assertFalse(added);
Assert.assertEquals(identitySet.size(), 1);
added = identitySet.add(date3);
Assert.assertTrue(added);
Assert.assertEquals(identitySet.size(), 2);
}
use of com.canoo.dp.impl.platform.core.IdentitySet in project dolphin-platform by canoo.
the class IdentitySetTest method testToArray.
@Test
public void testToArray() {
IdentitySet<Date> identitySet = new IdentitySet<>();
Date date1 = new Date();
Date date2 = new Date(date1.getTime());
identitySet.add(date1);
identitySet.add(date2);
Object[] itemArray = identitySet.toArray();
Assert.assertEquals(itemArray.length, 2);
Assert.assertEquals(itemArray[0], date1);
Assert.assertEquals(itemArray[1], date2);
Date[] itemArray2 = identitySet.toArray(new Date[0]);
Assert.assertEquals(itemArray2.length, 2);
Assert.assertEquals(itemArray2[0], date1);
Assert.assertEquals(itemArray2[1], date2);
}
use of com.canoo.dp.impl.platform.core.IdentitySet in project dolphin-platform by canoo.
the class IdentitySetTest method testRemoveAll.
@Test
public void testRemoveAll() {
IdentitySet<Date> identitySet = new IdentitySet<>();
Date date1 = new Date();
Date date2 = new Date(date1.getTime());
identitySet.addAll(Arrays.asList(date1, date2));
identitySet.removeAll(Arrays.asList(date1, date2));
Assert.assertEquals(identitySet.size(), 0);
Assert.assertFalse(identitySet.contains(date1));
Assert.assertFalse(identitySet.contains(date2));
identitySet.addAll(Arrays.asList(date1, date2));
identitySet.removeAll(Arrays.asList(date1));
Assert.assertEquals(identitySet.size(), 1);
Assert.assertFalse(identitySet.contains(date1));
Assert.assertTrue(identitySet.contains(date2));
}
use of com.canoo.dp.impl.platform.core.IdentitySet in project dolphin-platform by canoo.
the class IdentitySetTest method testRemove.
@Test
public void testRemove() {
IdentitySet<Date> identitySet = new IdentitySet<>();
Date date1 = new Date();
Date date2 = new Date(date1.getTime());
identitySet.add(date1);
Assert.assertFalse(identitySet.isEmpty());
Assert.assertEquals(identitySet.size(), 1);
boolean remove = identitySet.remove(date2);
Assert.assertFalse(remove);
Assert.assertEquals(identitySet.size(), 1);
Assert.assertFalse(identitySet.isEmpty());
remove = identitySet.remove(date1);
Assert.assertTrue(remove);
Assert.assertEquals(identitySet.size(), 0);
Assert.assertTrue(identitySet.isEmpty());
}
Aggregations