Package com.asakusafw.runtime.value

Examples of com.asakusafw.runtime.value.DateOption


    static final class FromDateOption extends AbstractWriter {

        @Override
        protected String toString(Object value) {
            DateOption option = (DateOption) value;
            return TemporalUtil.toDateString(option.get().getElapsedDays());
        }
View Full Code Here


    static class TimestampDateOptionInspector extends AbstractTimestampInspector {

        @Override
        protected ValueOption<?> newObject() {
            return new DateOption();
        }
View Full Code Here

        super(TypeInfoFactory.dateTypeInfo);
    }

    @Override
    protected ValueOption<?> newObject() {
        return new DateOption();
    }
View Full Code Here

        return new DateOption();
    }

    @Override
    public java.sql.Date getPrimitiveJavaObject(Object o) {
        DateOption object = (DateOption) o;
        if (object == null || object.isNull()) {
            return null;
        }
        Date value = object.get();

        // FIXME for optimization
        @SuppressWarnings("deprecation")
        java.sql.Date result = new java.sql.Date(value.getYear() - 1900, value.getMonth() - 1, value.getDay());
        return result;
View Full Code Here

        return result;
    }

    @Override
    public DateWritable getPrimitiveWritableObject(Object o) {
        DateOption object = (DateOption) o;
        if (object == null || object.isNull()) {
            return null;
        }
        Date value = object.get();
        return new DateWritable(value.getElapsedDays() - EPOCH_OFFSET);
    }
View Full Code Here

    @Test
    public void date_by_string() {
        ValueSerde serde = StringValueSerdeFactory.DATE;
        StringObjectInspector inspector = (StringObjectInspector) serde.getInspector();

        DateOption option = new DateOption(new Date(2014, 7, 1));
        String value = "2014-07-01";

        assertThat(inspector.copyObject(option), is((Object) option));
        assertThat(inspector.copyObject(option), is(not(sameInstance((Object) option))));
        assertThat(inspector.copyObject(null), is(nullValue()));
        assertThat(inspector.getPrimitiveJavaObject(option), is(value));
        assertThat(inspector.getPrimitiveJavaObject(null), is(nullValue()));
        assertThat(inspector.getPrimitiveWritableObject(option), is(new Text(value)));
        assertThat(inspector.getPrimitiveWritableObject(null), is(nullValue()));

        ValueDriver driver = serde.getDriver(inspector);
        DateOption copy = new DateOption();

        driver.set(copy, option);
        assertThat(copy, is(option));
        driver.set(copy, null);
        assertThat(copy.isNull(), is(true));
    }
View Full Code Here

    static class StringDateOptionInspector extends AbstractStringInspector {

        @Override
        protected ValueOption<?> newObject() {
            return new DateOption();
        }
View Full Code Here

    @Test
    public void date_by_timestamp() {
        ValueSerde serde = TimestampValueSerdeFactory.DATE;
        TimestampObjectInspector inspector = (TimestampObjectInspector) serde.getInspector();

        DateOption option = new DateOption(new Date(2014, 7, 1));
        Timestamp value = new Timestamp(2014 - 1900, 7 - 1, 1, 0, 0, 0, 0);

        assertThat(inspector.copyObject(option), is((Object) option));
        assertThat(inspector.copyObject(option), is(not(sameInstance((Object) option))));
        assertThat(inspector.copyObject(null), is(nullValue()));
        assertThat(inspector.getPrimitiveJavaObject(option), is(value));
        assertThat(inspector.getPrimitiveJavaObject(null), is(nullValue()));
        assertThat(inspector.getPrimitiveWritableObject(option), is(new TimestampWritable(value)));
        assertThat(inspector.getPrimitiveWritableObject(null), is(nullValue()));

        ValueDriver driver = serde.getDriver(inspector);
        DateOption copy = new DateOption();

        driver.set(copy, option);
        assertThat(copy, is(option));
        driver.set(copy, null);
        assertThat(copy.isNull(), is(true));
    }
View Full Code Here

        dateFormat = "yyyy/MM/dd";
        CsvParser parser = create(
                "2011/03/31,"
                + "1971/4/1,"
                + " 1971/4/1 ,");
        DateOption option = new DateOption();

        assertThat(parser.next(), is(true));

        parser.fill(option);
        assertThat(option.get(), is(new Date(2011, 3, 31)));

        parser.fill(option);
        assertThat(option.get(), is(new Date(1971, 4, 1)));

        parser.fill(option);
        assertThat(option.get(), is(new Date(1971, 4, 1)));

        parser.fill(option);
        assertThat(option.isNull(), is(true));

        parser.endRecord();
        assertThat(parser.next(), is(false));
    }
View Full Code Here

    public void date_values_direct() throws Exception {
        dateFormat = "yyyyMMdd";
        CsvParser parser = create(
                "20110331,"
                + "19710401,");
        DateOption option = new DateOption();

        assertThat(parser.next(), is(true));

        parser.fill(option);
        assertThat(option.get(), is(new Date(2011, 3, 31)));

        parser.fill(option);
        assertThat(option.get(), is(new Date(1971, 4, 1)));

        parser.fill(option);
        assertThat(option.isNull(), is(true));

        parser.endRecord();
        assertThat(parser.next(), is(false));
    }
View Full Code Here

TOP

Related Classes of com.asakusafw.runtime.value.DateOption

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.