Search in sources :

Example 11 with TypeReference

use of org.simpleflatmapper.util.TypeReference in project SimpleFlatMapper by arnaudroger.

the class CsvMapperOptionalTest method testMapListOptionInteger.

@Test
public void testMapListOptionInteger() throws IOException {
    final CsvMapper<List<Optional<Integer>>> mapper = CsvMapperFactory.newInstance().newBuilder(new TypeReference<List<Optional<Integer>>>() {
    }).addMapping("v0").addMapping("v1").mapper();
    final Iterator<List<Optional<Integer>>> iterator = mapper.iterator(new StringReader("1,2\n3"));
    List<Optional<Integer>> optionalList = iterator.next();
    assertEquals(2, optionalList.size());
    assertEquals(1, optionalList.get(0).get().intValue());
    assertEquals(2, optionalList.get(1).get().intValue());
    optionalList = iterator.next();
    assertEquals(1, optionalList.size());
    assertEquals(3, optionalList.get(0).get().intValue());
}
Also used : Optional(java.util.Optional) StringReader(java.io.StringReader) List(java.util.List) TypeReference(org.simpleflatmapper.util.TypeReference) Test(org.junit.Test)

Example 12 with TypeReference

use of org.simpleflatmapper.util.TypeReference 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());
}
Also used : DefaultPropertyNameMatcher(org.simpleflatmapper.reflect.meta.DefaultPropertyNameMatcher) Predicate(org.simpleflatmapper.util.Predicate) Tuple2(org.simpleflatmapper.tuple.Tuple2) Tuple3(org.simpleflatmapper.tuple.Tuple3) List(java.util.List) PropertyMeta(org.simpleflatmapper.reflect.meta.PropertyMeta) TypeReference(org.simpleflatmapper.util.TypeReference) Test(org.junit.Test)

Example 13 with TypeReference

use of org.simpleflatmapper.util.TypeReference in project SimpleFlatMapper by arnaudroger.

the class AbstractMapperBuilderTest method testConversionCharacterToJodaTime.

@Test
public void testConversionCharacterToJodaTime() {
    ClassMeta<List<DateTime>> classMeta = ReflectionService.disableAsm().<List<DateTime>>getClassMeta(new TypeReference<List<DateTime>>() {
    }.getType());
    DateTimeFormatter dateTimeFormatter = DateTimeFormat.forPattern("yyyyMMdd HH:mm:ss.SSSS Z");
    Mapper<Object[], List<DateTime>> mapper = new SampleMapperBuilder<List<DateTime>>(classMeta).addMapping(new SampleFieldKey("0", 0, new Class[0], String.class), dateTimeFormatter).mapper();
    DateTime now = DateTime.now();
    Object[] objects = new Object[] { dateTimeFormatter.print(now) };
    List<DateTime> map = mapper.map(objects);
    assertEquals(now, map.get(0));
}
Also used : List(java.util.List) SampleFieldKey(org.simpleflatmapper.test.map.SampleFieldKey) DbListObject(org.simpleflatmapper.test.beans.DbListObject) DbObject(org.simpleflatmapper.test.beans.DbObject) DbFinal1DeepObject(org.simpleflatmapper.test.beans.DbFinal1DeepObject) DbPartialFinalObject(org.simpleflatmapper.test.beans.DbPartialFinalObject) DbFinalObject(org.simpleflatmapper.test.beans.DbFinalObject) TypeReference(org.simpleflatmapper.util.TypeReference) DateTimeFormatter(org.joda.time.format.DateTimeFormatter) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 14 with TypeReference

use of org.simpleflatmapper.util.TypeReference in project SimpleFlatMapper by arnaudroger.

the class Issue451 method testPropertyFinderAndAppendSetter.

@Test
public void testPropertyFinderAndAppendSetter() {
    ClassMeta<List<Foo>> classMeta = ReflectionService.newInstance().getClassMeta(new TypeReference<List<Foo>>() {
    }.getType());
    PropertyFinder<List<Foo>> finder = classMeta.newPropertyFinder(new Predicate<PropertyMeta<?, ?>>() {

        @Override
        public boolean test(PropertyMeta<?, ?> propertyMeta) {
            return true;
        }
    });
    SubPropertyMeta f = (SubPropertyMeta) finder.findProperty(DefaultPropertyNameMatcher.of("b_f"), new Object[0]);
    SubPropertyMeta n = (SubPropertyMeta) finder.findProperty(DefaultPropertyNameMatcher.of("b_n"), new Object[0]);
    assertEquals(AppendCollectionSetter.class, n.getOwnerProperty().getSetter().getClass());
}
Also used : SubPropertyMeta(org.simpleflatmapper.reflect.meta.SubPropertyMeta) List(java.util.List) SubPropertyMeta(org.simpleflatmapper.reflect.meta.SubPropertyMeta) PropertyMeta(org.simpleflatmapper.reflect.meta.PropertyMeta) TypeReference(org.simpleflatmapper.util.TypeReference) Test(org.junit.Test)

Example 15 with TypeReference

use of org.simpleflatmapper.util.TypeReference in project SimpleFlatMapper by arnaudroger.

the class TypeHelperTest method testToClass.

@Test
public void testToClass() {
    Assert.assertEquals(Map.class, TypeHelper.toClass(new TypeReference<Map<String, String>>() {
    }.getType()));
    ParameterizedType type = (ParameterizedType) new TypeReference<Map<? extends Number, String>>() {
    }.getType();
    assertEquals(Number.class, TypeHelper.toClass(type.getActualTypeArguments()[0]));
    assertEquals(Date.class, TypeHelper.toClass(MyComparable.class.getTypeParameters()[0]));
    assertEquals(Date.class, TypeHelper.toClass(Date.class));
    try {
        TypeHelper.toClass(new Type() {

            public String getTypeName() {
                return null;
            }
        });
        fail();
    } catch (UnsupportedOperationException e) {
    }
    assertEquals(String[].class, TypeHelper.toClass(new GenericArrayType() {

        @Override
        public Type getGenericComponentType() {
            return String.class;
        }
    }));
}
Also used : ParameterizedType(java.lang.reflect.ParameterizedType) GenericArrayType(java.lang.reflect.GenericArrayType) ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type) TypeReference(org.simpleflatmapper.util.TypeReference) GenericArrayType(java.lang.reflect.GenericArrayType) ConcurrentMap(java.util.concurrent.ConcurrentMap) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)15 TypeReference (org.simpleflatmapper.util.TypeReference)15 List (java.util.List)5 StringReader (java.io.StringReader)3 DefaultPropertyNameMatcher (org.simpleflatmapper.reflect.meta.DefaultPropertyNameMatcher)3 PropertyMeta (org.simpleflatmapper.reflect.meta.PropertyMeta)3 StringWriter (java.io.StringWriter)2 Type (java.lang.reflect.Type)2 Connection (java.sql.Connection)2 ResultSet (java.sql.ResultSet)2 Tuple3 (org.jooq.lambda.tuple.Tuple3)2 DbObject (org.simpleflatmapper.test.beans.DbObject)2 Tuple3 (org.simpleflatmapper.tuple.Tuple3)2 Predicate (org.simpleflatmapper.util.Predicate)2 GenericArrayType (java.lang.reflect.GenericArrayType)1 ParameterizedType (java.lang.reflect.ParameterizedType)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Set (java.util.Set)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1