Example usage for org.apache.commons.collections BeanMap keySet

List of usage examples for org.apache.commons.collections BeanMap keySet

Introduction

In this page you can find the example usage for org.apache.commons.collections BeanMap keySet.

Prototype

public Set keySet() 

Source Link

Document

Get the keys for this BeanMap.

Usage

From source file:se.vgregion.portal.innovatinosslussen.domain.TypesBeanTest.java

void doGetterSetterValuesMatch(Object o) throws IllegalAccessException, InstantiationException {
    BeanMap bm = new BeanMap(o);

    final String javaLangPackageName = String.class.getPackage().getName();

    for (Object key : bm.keySet()) {
        String name = (String) key;

        if ("ideaContentPrivate".equals(name) || "ideaPerson".equals(name)
                || "ideaContentPublic".equals(name)) {
            continue;
        }//  ww  w  . ja v a 2s . c  om

        if (bm.getWriteMethod(name) != null) {
            if (bm.getType(name).equals(String.class)) {
                bm.put(name, name);
                Assert.assertTrue(name == bm.get(name));
            } else {
                Class clazz = bm.getType(name);

                if (!clazz.getName().startsWith(javaLangPackageName) && !clazz.isEnum()) {
                    Object value = defaultPrim.get(clazz);
                    if (value == null) {
                        value = clazz.newInstance();
                    }
                    bm.put(name, value);
                    Assert.assertTrue("1, " + o.getClass() + "." + key, value.equals(bm.get(name)));
                    Assert.assertTrue("2, " + o.getClass() + "." + key,
                            value.hashCode() == bm.get(name).hashCode());
                }
            }
        }

    }
}

From source file:se.vgregion.service.barium.BariumRestClientIT.java

License:asdf

/**
 * After this 'test' go to Barium and check the data. Did this seem to be thread safe?
 * @throws BariumException/* w w w . ja va  2 s  .c o  m*/
 */
@Ignore
@Test
public void toCreateConcurrent() throws BariumException {
    BariumRestClientImpl client = createBariumRestClient();
    client.connect();
    for (int i = 0; i < 3; i++) {
        IdeaObjectFields fields = new IdeaObjectFields();
        BeanMap bm = new BeanMap(fields);
        for (Object key : bm.keySet()) {
            String name = (String) key;
            if (bm.getWriteMethod(name) != null && String.class.equals(bm.getType(name))) {
                bm.put(name, name + " " + i);
            }
        }
        fields.setInstanceName("instanceName (async) " + i + " " + System.currentTimeMillis());
        createAsync(client, fields);
    }

    try {
        do {
            System.out.println("Delaying some to make the threads finish.");
            Thread.sleep(1000);
        } while (asyncCount != 0);
        System.exit(0);
    } catch (InterruptedException ie) {
        System.out.println("Child thread interrupted! " + ie);
    }

}

From source file:se.vgregion.service.innovationsslussen.idea.IdeaServiceImplTest.java

private void initDefaultStringValues(Object o) {
    BeanMap bm = new BeanMap(o);
    for (Object key : bm.keySet()) {
        String name = (String) key;
        if (bm.getWriteMethod(name) != null) {
            if (bm.getType(name).equals(String.class)) {
                bm.put(name, name);//from  w  w w.  j a v a  2  s  .c o  m
            }
        }
    }
}

From source file:se.vgregion.service.innovationsslussen.ldap.PersonTest.java

@Test
public void beanStringPropertiesGetterSetters() {
    KivPerson person = new KivPerson();
    BeanMap bm = new BeanMap(person);
    int i = 0;/*from  w  w  w  .j  a v  a 2 s.co m*/
    for (Object key : bm.keySet()) {
        String name = (String) key;
        if (bm.getWriteMethod(name) != null) {
            if (bm.getType(name).equals(String.class)) {
                String setterValue = "" + i++;
                bm.put(key, setterValue);
                String getterValue = (String) bm.get(key);
                Assert.assertEquals(setterValue, getterValue);
            }
        }
    }
}