Sha256: 62c97a71558d3a1e34344ba707258694a9ae1516b75985139b1516d61c3ce867

Contents?: true

Size: 1.07 KB

Versions: 3

Compression:

Stored size: 1.07 KB

Contents

package org.embulk.parser.jsonl.cast;

import org.embulk.spi.DataException;
import org.embulk.spi.time.Timestamp;

public class LongCast
{
    private LongCast() {}

    private static String buildErrorMessage(String as, long value)
    {
        return String.format("cannot cast long to %s: \"%s\"", as, value);
    }

    public static boolean asBoolean(long value) throws DataException
    {
        if (value == 1) {
            return true;
        }
        else if (value == 0) {
            return false;
        }
        else {
            throw new DataException(buildErrorMessage("boolean", value));
        }
    }

    public static long asLong(long value) throws DataException
    {
        return value;
    }

    public static double asDouble(long value) throws DataException
    {
        return (double) value;
    }

    public static String asString(long value) throws DataException
    {
        return String.valueOf(value);
    }

    public static Timestamp asTimestamp(long value) throws DataException
    {
        return Timestamp.ofEpochSecond(value);
    }
}

Version data entries

3 entries across 3 versions & 2 rubygems

Version Path
embulk-parser-jsonl-0.2.1 src/main/java/org/embulk/parser/jsonl/cast/LongCast.java
embulk-parser-jsonline-0.2.2 src/main/java/org/embulk/parser/jsonl/cast/LongCast.java
embulk-parser-jsonl-0.2.0 src/main/java/org/embulk/parser/jsonl/cast/LongCast.java