Sha256: 118f9eed593620ade14a62c4b93e9054873267c48bcd3fde86544ef15693382b

Contents?: true

Size: 1.07 KB

Versions: 7

Compression:

Stored size: 1.07 KB

Contents

package org.embulk.parser.jsonpath.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

7 entries across 7 versions & 1 rubygems

Version Path
embulk-parser-jsonpath-0.3.1 src/main/java/org/embulk/parser/jsonpath/cast/LongCast.java
embulk-parser-jsonpath-0.3.0 src/main/java/org/embulk/parser/jsonpath/cast/LongCast.java
embulk-parser-jsonpath-0.2.0 src/main/java/org/embulk/parser/jsonpath/cast/LongCast.java
embulk-parser-jsonpath-0.1.3 src/main/java/org/embulk/parser/jsonpath/cast/LongCast.java
embulk-parser-jsonpath-0.1.2 src/main/java/org/embulk/parser/jsonpath/cast/LongCast.java
embulk-parser-jsonpath-0.1.1 src/main/java/org/embulk/parser/jsonpath/cast/LongCast.java
embulk-parser-jsonpath-0.1.0 src/main/java/org/embulk/parser/jsonpath/cast/LongCast.java