Search in sources :

Example 1 with IdentitySet

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;
}
Also used : Field(java.lang.reflect.Field) ObservableList(com.canoo.platform.remoting.ObservableList) IdentitySet(com.canoo.dp.impl.platform.core.IdentitySet)

Example 2 with IdentitySet

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);
}
Also used : IdentitySet(com.canoo.dp.impl.platform.core.IdentitySet) Date(java.util.Date) Test(org.testng.annotations.Test)

Example 3 with IdentitySet

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);
}
Also used : IdentitySet(com.canoo.dp.impl.platform.core.IdentitySet) Date(java.util.Date) Test(org.testng.annotations.Test)

Example 4 with IdentitySet

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));
}
Also used : IdentitySet(com.canoo.dp.impl.platform.core.IdentitySet) Date(java.util.Date) Test(org.testng.annotations.Test)

Example 5 with IdentitySet

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());
}
Also used : IdentitySet(com.canoo.dp.impl.platform.core.IdentitySet) Date(java.util.Date) Test(org.testng.annotations.Test)

Aggregations

IdentitySet (com.canoo.dp.impl.platform.core.IdentitySet)11 Date (java.util.Date)9 Test (org.testng.annotations.Test)9 Field (java.lang.reflect.Field)2 ObservableList (com.canoo.platform.remoting.ObservableList)1 Property (com.canoo.platform.remoting.Property)1 ArrayList (java.util.ArrayList)1