Search in sources :

Example 11 with CsvColumnKey

use of org.simpleflatmapper.csv.CsvColumnKey in project SimpleFlatMapper by arnaudroger.

the class FieldMapperToAppendableFactoryTest method testDoubleWithFormatterAppender.

@Test
public void testDoubleWithFormatterAppender() throws Exception {
    MappingContextFactoryBuilder<DbPrimitiveObjectWithSetter, CsvColumnKey> builder = getMappingContextBuilder();
    FieldMapperColumnDefinition<CsvColumnKey> format = FieldMapperColumnDefinition.<CsvColumnKey>identity().add(new FormatProperty(new DecimalFormat("0.0")));
    FieldMapper<DbPrimitiveObjectWithSetter, Appendable> fieldMapper = defaultFieldAppenderFactory.newFieldMapper(newPropertyMapping("pDouble", dbPrimitiveObjectClassMeta, format), builder, null);
    testFieldMapper("3.1", fieldMapper, dbPrimitiveObject, builder.newFactory());
}
Also used : DbPrimitiveObjectWithSetter(org.simpleflatmapper.test.beans.DbPrimitiveObjectWithSetter) FormatProperty(org.simpleflatmapper.map.property.FormatProperty) DateFormatProperty(org.simpleflatmapper.map.property.DateFormatProperty) DecimalFormat(java.text.DecimalFormat) CsvColumnKey(org.simpleflatmapper.csv.CsvColumnKey) Test(org.junit.Test)

Example 12 with CsvColumnKey

use of org.simpleflatmapper.csv.CsvColumnKey in project SimpleFlatMapper by arnaudroger.

the class FieldMapperToAppendableFactoryTest method testJodaDateTimeWithDateFormat.

@Test
public void testJodaDateTimeWithDateFormat() throws Exception {
    MappingContextFactoryBuilder<JodaObject, CsvColumnKey> builder = getMappingContextBuilder();
    FieldMapperColumnDefinition<CsvColumnKey> format = FieldMapperColumnDefinition.<CsvColumnKey>identity().add(new DateFormatProperty("yyyyMMdd"));
    FieldMapper<JodaObject, Appendable> fieldMapper = defaultFieldAppenderFactory.newFieldMapper(newPropertyMapping("dateTime", jodaObjectClassMeta, format), builder, null);
    testFieldMapper("20140607", fieldMapper, jodaObject, builder.newFactory());
}
Also used : CsvColumnKey(org.simpleflatmapper.csv.CsvColumnKey) DateFormatProperty(org.simpleflatmapper.map.property.DateFormatProperty) Test(org.junit.Test)

Example 13 with CsvColumnKey

use of org.simpleflatmapper.csv.CsvColumnKey in project SimpleFlatMapper by arnaudroger.

the class FieldMapperToAppendableFactoryJavaTimeTest method testLocalDateTimeWithFormaterAppender.

@Test
public void testLocalDateTimeWithFormaterAppender() throws Exception {
    MappingContextFactoryBuilder<JavaTimeObject, CsvColumnKey> builder = getMappingContextBuilder();
    FieldMapper<JavaTimeObject, Appendable> fieldMapper = defaultFieldAppenderFactory.newFieldMapper(newPropertyMapping("localDateTime", javaTimeObjectClassMeta, FieldMapperColumnDefinition.<CsvColumnKey>identity().add(new JavaDateTimeFormatterProperty(DateTimeFormatter.ofPattern("dd/MM/yyyy")))), builder, null);
    testFieldMapper("03/12/2011", fieldMapper, javaTimeObject, builder.newFactory());
}
Also used : CsvColumnKey(org.simpleflatmapper.csv.CsvColumnKey) JavaDateTimeFormatterProperty(org.simpleflatmapper.map.property.time.JavaDateTimeFormatterProperty) Test(org.junit.Test)

Example 14 with CsvColumnKey

use of org.simpleflatmapper.csv.CsvColumnKey in project SimpleFlatMapper by arnaudroger.

the class CsvColumnDefinitionTest method testComposition.

@Test
public void testComposition() {
    TimeZone tz = TimeZone.getTimeZone("Europe/Brussels");
    CellValueReaderFactory cellValueReaderFactory = new CellValueReaderFactory() {

        @Override
        public <P> CellValueReader<P> getReader(Type propertyType, int index, CsvColumnDefinition columnDefinition, ParsingContextFactoryBuilder contextFactoryBuilder) {
            return null;
        }

        @Override
        public String toString() {
            return "CellValueReaderFactory";
        }
    };
    final Predicate<PropertyMeta<?, ?>> appliesTo = ConstantPredicate.falsePredicate();
    CsvColumnDefinition compose = CsvColumnDefinition.identity().addDateFormat("yyyyMM").addRename("blop").addCustomReader(new CellValueReader<Integer>() {

        @Override
        public Integer read(char[] chars, int offset, int length, ParsingContext parsingContext) {
            return 3;
        }

        @Override
        public String toString() {
            return "CellValueReader";
        }
    }).addCustomCellValueReaderFactory(cellValueReaderFactory).addTimeZone(tz).addKey(appliesTo);
    assertEquals("blop", compose.rename(new CsvColumnKey("bar", -1)).getName());
    assertEquals("blop", CsvColumnDefinition.renameDefinition("blop").rename(new CsvColumnKey("bar", -1)).getName());
    assertArrayEquals(new String[] { "yyyyMM" }, compose.dateFormats());
    assertEquals(new Integer(3), compose.getCustomReader().read(null, 0, 0, null));
    assertEquals(cellValueReaderFactory, compose.getCustomCellValueReaderFactory());
    assertEquals(tz, compose.getTimeZone());
    assertEquals(tz, CsvColumnDefinition.timeZoneDefinition(tz).getTimeZone());
    assertTrue(compose.hasCustomSourceFrom(Object.class));
    assertFalse(compose.ignore());
    assertEquals(Integer.class, compose.getCustomSourceReturnTypeFrom(Object.class));
    assertTrue(CsvColumnDefinition.identity().addIgnore().ignore());
    assertTrue(compose.isKey());
    assertTrue(CsvColumnDefinition.key(appliesTo).isKey());
    assertSame(appliesTo, compose.keyAppliesTo());
    final String toString = compose.addIgnore().toString();
    System.out.println("toString = " + toString);
}
Also used : ParsingContext(org.simpleflatmapper.csv.ParsingContext) ParsingContextFactoryBuilder(org.simpleflatmapper.csv.ParsingContextFactoryBuilder) CellValueReader(org.simpleflatmapper.csv.CellValueReader) TimeZone(java.util.TimeZone) Type(java.lang.reflect.Type) CellValueReaderFactory(org.simpleflatmapper.csv.CellValueReaderFactory) CsvColumnKey(org.simpleflatmapper.csv.CsvColumnKey) PropertyMeta(org.simpleflatmapper.reflect.meta.PropertyMeta) CsvColumnDefinition(org.simpleflatmapper.csv.CsvColumnDefinition) Test(org.junit.Test)

Example 15 with CsvColumnKey

use of org.simpleflatmapper.csv.CsvColumnKey in project SimpleFlatMapper by arnaudroger.

the class CsvColumnKeyTest method testIsAlias.

@Test
public void testIsAlias() throws Exception {
    assertFalse(new CsvColumnKey("c", 0).isAlias());
    assertTrue(new CsvColumnKey("c", 0).alias("b").isAlias());
}
Also used : CsvColumnKey(org.simpleflatmapper.csv.CsvColumnKey) Test(org.junit.Test)

Aggregations

CsvColumnKey (org.simpleflatmapper.csv.CsvColumnKey)16 Test (org.junit.Test)10 DateFormatProperty (org.simpleflatmapper.map.property.DateFormatProperty)4 Type (java.lang.reflect.Type)3 ParsingContext (org.simpleflatmapper.csv.ParsingContext)3 StringReader (java.io.StringReader)2 CellValueReader (org.simpleflatmapper.csv.CellValueReader)2 CellValueReaderFactory (org.simpleflatmapper.csv.CellValueReaderFactory)2 CsvColumnDefinition (org.simpleflatmapper.csv.CsvColumnDefinition)2 ParsingContextFactoryBuilder (org.simpleflatmapper.csv.ParsingContextFactoryBuilder)2 EnumOrdinalFormatProperty (org.simpleflatmapper.map.property.EnumOrdinalFormatProperty)2 FieldMapperColumnDefinition (org.simpleflatmapper.map.property.FieldMapperColumnDefinition)2 BooleanGetter (org.simpleflatmapper.reflect.primitive.BooleanGetter)2 ByteGetter (org.simpleflatmapper.reflect.primitive.ByteGetter)2 CharacterGetter (org.simpleflatmapper.reflect.primitive.CharacterGetter)2 DoubleGetter (org.simpleflatmapper.reflect.primitive.DoubleGetter)2 FloatGetter (org.simpleflatmapper.reflect.primitive.FloatGetter)2 IntGetter (org.simpleflatmapper.reflect.primitive.IntGetter)2 LongGetter (org.simpleflatmapper.reflect.primitive.LongGetter)2 ShortGetter (org.simpleflatmapper.reflect.primitive.ShortGetter)2