use of org.simpleflatmapper.util.Predicate in project SimpleFlatMapper by arnaudroger.
the class JoinJdbcMapperCustomKeyTest method test.
@Test
public void test() throws SQLException {
JdbcMapper<Person> mapper = JdbcMapperFactory.newInstance().addColumnDefinition(new Predicate<JdbcColumnKey>() {
@Override
public boolean test(JdbcColumnKey jdbcColumnKey) {
return jdbcColumnKey.getIndex() <= 2;
}
}, FieldMapperColumnDefinition.<JdbcColumnKey>key(new Predicate<PropertyMeta<?, ?>>() {
@Override
public boolean test(PropertyMeta<?, ?> propertyMeta) {
return propertyMeta.getPath().startsWith("key.");
}
})).newBuilder(Person.class).addMapping("key_tag").addMapping("key_n").addMapping("name").addMapping("phones_value").mapper();
ResultSet rs = JoinJdbcMapperOnTupleTest.setUpResultSetMock(new String[] { "key_tag", "key_n", "name", "phones_value" }, new Object[][] { { "t1", 1, "t11", "p111" }, { "t1", 1, "t11", "p112" }, { "t1", 2, "t12", "p121" } });
final List<Person> list = mapper.forEach(rs, new ListCollector<Person>()).getList();
assertEquals(2, list.size());
assertEquals("t1", list.get(0).key.tag);
assertEquals(1, list.get(0).key.n);
assertEquals("t11", list.get(0).name);
assertEquals(Arrays.asList("p111", "p112"), list.get(0).phones);
assertEquals("t1", list.get(1).key.tag);
assertEquals(2, list.get(1).key.n);
assertEquals("t12", list.get(1).name);
assertEquals(Arrays.asList("p121"), list.get(1).phones);
}
use of org.simpleflatmapper.util.Predicate in project SimpleFlatMapper by arnaudroger.
the class ArrayClassMetaTest method testArrayObject.
@Test
public void testArrayObject() throws Exception {
ClassMeta<?> classMeta = ReflectionService.newInstance().getClassMeta(Object[].class);
assertTrue(classMeta instanceof ArrayClassMeta);
PropertyMeta p = classMeta.newPropertyFinder(new Predicate() {
@Override
public boolean test(Object propertyMeta) {
return true;
}
}).findProperty(DefaultPropertyNameMatcher.of("3"), new Object[0]);
Object[] array = new Object[10];
p.getSetter().set(array, "aaa");
assertEquals("aaa", p.getGetter().get(array));
assertEquals("aaa", array[3]);
}
use of org.simpleflatmapper.util.Predicate in project SimpleFlatMapper by arnaudroger.
the class CsvParserTest method testDSLIgnoreField.
@Test
public void testDSLIgnoreField() throws Exception {
Iterator<Tuple2<String, String>> iterator = CsvParser.mapTo(String.class, String.class).columnDefinition(new Predicate<CsvColumnKey>() {
@Override
public boolean test(CsvColumnKey csvColumnKey) {
return csvColumnKey.getIndex() != 1 && csvColumnKey.getIndex() != 2;
}
}, CsvColumnDefinition.ignoreDefinition()).iterator(new StringReader("-1,0,1,2\nv0,v1,v2,v3"));
Tuple2<String, String> tuple = iterator.next();
assertEquals("v1", tuple.first());
assertEquals("v2", tuple.second());
}
use of org.simpleflatmapper.util.Predicate in project SimpleFlatMapper by arnaudroger.
the class ConstantSourceMapperBuilderTest method testIssue495.
@Test
public void testIssue495() throws Exception {
TypeReference<Tuple2<TableA, List<Tuple3<TableB, List<TableC>, List<Tuple2<TableD, List<TableE>>>>>>> typeReference = new TypeReference<Tuple2<TableA, List<Tuple3<TableB, List<TableC>, List<Tuple2<TableD, List<TableE>>>>>>>() {
};
ClassMeta<Tuple2<TableA, List<Tuple3<TableB, List<TableC>, List<Tuple2<TableD, List<TableE>>>>>>> classMeta = this.classMeta.getReflectionService().getClassMeta(typeReference.getType());
Predicate<PropertyMeta<?, ?>> propertyFilter = new Predicate<PropertyMeta<?, ?>>() {
@Override
public boolean test(PropertyMeta<?, ?> propertyMeta) {
return true;
}
};
PropertyFinder<Tuple2<TableA, List<Tuple3<TableB, List<TableC>, List<Tuple2<TableD, List<TableE>>>>>>> propertyFinder = classMeta.newPropertyFinder(propertyFilter);
PropertyMeta<Tuple2<TableA, List<Tuple3<TableB, List<TableC>, List<Tuple2<TableD, List<TableE>>>>>>, Object> p1 = propertyFinder.findProperty(new DefaultPropertyNameMatcher("variableName", 0, false, false), new Object[0]);
PropertyMeta<Tuple2<TableA, List<Tuple3<TableB, List<TableC>, List<Tuple2<TableD, List<TableE>>>>>>, Object> p2 = propertyFinder.findProperty(new DefaultPropertyNameMatcher("variableName", 0, false, false), new Object[0]);
System.out.println("p1.getPath() = " + p1.getPath());
System.out.println("p2.getPath() = " + p2.getPath());
}
use of org.simpleflatmapper.util.Predicate in project SimpleFlatMapper by arnaudroger.
the class AbstractMapperFactoryTest method testDefaultMapperConfig.
@Test
public void testDefaultMapperConfig() {
MapperFactory mapperFactory = new MapperFactory();
MapperConfig<SampleFieldKey, FieldMapperColumnDefinition<SampleFieldKey>> mapperConfig = mapperFactory.mapperConfig();
final ArrayList<Object> properties = new ArrayList<Object>();
mapperConfig.columnDefinitions().forEach(Object.class, new BiConsumer<Predicate<? super SampleFieldKey>, Object>() {
@Override
public void accept(Predicate<? super SampleFieldKey> predicate, Object o) {
properties.add(o);
}
});
assertTrue(properties.isEmpty());
assertFalse(mapperConfig.failOnAsm());
assertEquals(NO_ASM_MAPPER_THRESHOLD, mapperConfig.asmMapperNbFieldsLimit());
assertNull(mapperConfig.fieldMapperErrorHandler());
assertFalse(mapperConfig.hasFieldMapperErrorHandler());
assertTrue(mapperConfig.mapperBuilderErrorHandler() instanceof RethrowMapperBuilderErrorHandler);
assertTrue(mapperConfig.consumerErrorHandler() instanceof RethrowConsumerErrorHandler);
assertEquals(MapperConfig.MAX_METHOD_SIZE, mapperConfig.maxMethodSize());
assertTrue(mapperConfig.propertyNameMatcherFactory() instanceof DefaultPropertyNameMatcherFactory);
assertTrue(mapperFactory.getReflectionService().isAsmActivated());
}
Aggregations