Sha256: 8f2f9a31bee053b831cfdb6b8db81d203ab8e2abfc897134e1e7fa2dfa0253a5

Contents?: true

Size: 1.24 KB

Versions: 6

Compression:

Stored size: 1.24 KB

Contents

package org.embulk.filter.typecast.cast;

import org.embulk.spi.DataException;
import org.embulk.spi.time.Timestamp;
import org.msgpack.value.Value;

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 Value asJson(long value) throws DataException
    {
        throw new DataException(buildErrorMessage("json", value));
    }

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

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
embulk-filter-typecast-0.2.2 src/main/java/org/embulk/filter/typecast/cast/LongCast.java
embulk-filter-typecast-0.2.1 src/main/java/org/embulk/filter/typecast/cast/LongCast.java
embulk-filter-typecast-0.2.0 src/main/java/org/embulk/filter/typecast/cast/LongCast.java
embulk-filter-typecast-0.1.5 src/main/java/org/embulk/filter/typecast/cast/LongCast.java
embulk-filter-typecast-0.1.4 src/main/java/org/embulk/filter/typecast/cast/LongCast.java
embulk-filter-typecast-0.1.3 src/main/java/org/embulk/filter/typecast/cast/LongCast.java