Sha256: 1d2d3ef0c868420523384717b03a0e10f8b1fdbf8d91b1923d54b8f480f6523c

Contents?: true

Size: 1.54 KB

Versions: 2

Compression:

Stored size: 1.54 KB

Contents

package org.embulk.spi.util.dynamic;

import com.google.common.collect.ImmutableSet;
import org.embulk.spi.Column;
import org.embulk.spi.PageBuilder;
import org.embulk.spi.time.Timestamp;
import org.msgpack.value.Value;

public class BooleanColumnSetter
        extends AbstractDynamicColumnSetter
{
    private static final ImmutableSet<String> TRUE_STRINGS =
        ImmutableSet.of(
                "true", "True", "TRUE",
                "yes", "Yes", "YES",
                "t", "T", "y", "Y",
                "on", "On", "ON",
                "1");

    public BooleanColumnSetter(PageBuilder pageBuilder, Column column,
            DefaultValueSetter defaultValue)
    {
        super(pageBuilder, column, defaultValue);
    }

    @Override
    public void setNull()
    {
        pageBuilder.setNull(column);
    }

    @Override
    public void set(boolean v)
    {
        pageBuilder.setBoolean(column, v);
    }

    @Override
    public void set(long v)
    {
        pageBuilder.setBoolean(column, v > 0);
    }

    @Override
    public void set(double v)
    {
        pageBuilder.setBoolean(column, v > 0.0);
    }

    @Override
    public void set(String v)
    {
        if (TRUE_STRINGS.contains(v)) {
            pageBuilder.setBoolean(column, true);
        } else {
            defaultValue.setDouble(pageBuilder, column);
        }
    }

    @Override
    public void set(Timestamp v)
    {
        defaultValue.setBoolean(pageBuilder, column);
    }

    @Override
    public void set(Value v)
    {
        pageBuilder.setJson(column, v);
    }
}

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
embulk-0.8.0 embulk-core/src/main/java/org/embulk/spi/util/dynamic/BooleanColumnSetter.java
embulk-0.8.0-java embulk-core/src/main/java/org/embulk/spi/util/dynamic/BooleanColumnSetter.java