Search in sources :

Example 1 with FieldMapperColumnDefinitionProviderImpl

use of org.simpleflatmapper.map.mapper.FieldMapperColumnDefinitionProviderImpl in project SimpleFlatMapper by arnaudroger.

the class FieldMapperColumnDefinitionProviderImplTest method testProvides.

@Test
public void testProvides() {
    final Object prop1 = "prop1";
    final Object prop2 = "prop2";
    final ConstantUnaryFactory<SampleFieldKey, Object> prop1Fact = ConstantUnaryFactory.<SampleFieldKey, Object>of(prop1);
    final ConstantUnaryFactory<SampleFieldKey, Object> prop2Fact = ConstantUnaryFactory.<SampleFieldKey, Object>of(prop2);
    FieldMapperColumnDefinitionProviderImpl<SampleFieldKey> provider = new FieldMapperColumnDefinitionProviderImpl<SampleFieldKey>();
    final Predicate<SampleFieldKey> prop1Predicate = new Predicate<SampleFieldKey>() {

        @Override
        public boolean test(SampleFieldKey sampleFieldKey) {
            return sampleFieldKey.getIndex() == 0;
        }
    };
    final Predicate<SampleFieldKey> prop2Predicate = new Predicate<SampleFieldKey>() {

        @Override
        public boolean test(SampleFieldKey sampleFieldKey) {
            return sampleFieldKey.getIndex() == 1;
        }
    };
    provider.addColumnProperty(prop1Predicate, prop1Fact);
    provider.addColumnProperty(prop2Predicate, prop2Fact);
    List<AbstractColumnDefinitionProvider.PredicatedColunnPropertyFactory<FieldMapperColumnDefinition<SampleFieldKey>, SampleFieldKey>> properties = provider.getProperties();
    assertEquals(2, properties.size());
    assertEquals(prop1Predicate, properties.get(0).getPredicate());
    assertEquals(prop2Predicate, properties.get(1).getPredicate());
    assertEquals(prop1Fact, properties.get(0).getColumnPropertyFactory());
    assertEquals(prop2Fact, properties.get(1).getColumnPropertyFactory());
    final ArrayList<String> props = new ArrayList<String>();
    provider.addColumnProperty(prop1Predicate, new Object());
    provider.forEach(String.class, new BiConsumer<Predicate<? super SampleFieldKey>, String>() {

        @Override
        public void accept(Predicate<? super SampleFieldKey> predicate, String s) {
            if (s == prop1) {
                assertEquals(predicate, prop1Predicate);
            }
            if (s == prop2) {
                assertEquals(predicate, prop2Predicate);
            }
            props.add(s);
        }
    });
    assertArrayEquals(new String[] { "prop1", "prop2" }, props.toArray(new String[0]));
    assertArrayEquals(new String[] { "prop1" }, provider.getColumnDefinition(new SampleFieldKey("", 0)).lookForAll(String.class));
}
Also used : ArrayList(java.util.ArrayList) Predicate(org.simpleflatmapper.util.Predicate) SampleFieldKey(org.simpleflatmapper.test.map.SampleFieldKey) FieldMapperColumnDefinitionProviderImpl(org.simpleflatmapper.map.mapper.FieldMapperColumnDefinitionProviderImpl) Test(org.junit.Test)

Example 2 with FieldMapperColumnDefinitionProviderImpl

use of org.simpleflatmapper.map.mapper.FieldMapperColumnDefinitionProviderImpl in project SimpleFlatMapper by arnaudroger.

the class Issue365Test method mapperConfig.

private MapperConfig<SampleFieldKey, FieldMapperColumnDefinition<SampleFieldKey>> mapperConfig() {
    FieldMapperColumnDefinitionProviderImpl<SampleFieldKey> provider = new FieldMapperColumnDefinitionProviderImpl<SampleFieldKey>();
    provider.addColumnDefinition("benchmark", FieldMapperColumnDefinition.<SampleFieldKey>identity().add(new SetterProperty(SETTER)).add(new GetterProperty(GETTER)));
    return MapperConfig.<SampleFieldKey>fieldMapperConfig().columnDefinitions(provider);
}
Also used : SetterProperty(org.simpleflatmapper.map.property.SetterProperty) SampleFieldKey(org.simpleflatmapper.test.map.SampleFieldKey) FieldMapperColumnDefinitionProviderImpl(org.simpleflatmapper.map.mapper.FieldMapperColumnDefinitionProviderImpl) GetterProperty(org.simpleflatmapper.map.property.GetterProperty)

Aggregations

FieldMapperColumnDefinitionProviderImpl (org.simpleflatmapper.map.mapper.FieldMapperColumnDefinitionProviderImpl)2 SampleFieldKey (org.simpleflatmapper.test.map.SampleFieldKey)2 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1 GetterProperty (org.simpleflatmapper.map.property.GetterProperty)1 SetterProperty (org.simpleflatmapper.map.property.SetterProperty)1 Predicate (org.simpleflatmapper.util.Predicate)1