All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.jsoniter.any.LongLazyAny Maven / Gradle / Ivy

Go to download

jsoniter (json-iterator) is fast and flexible JSON parser available in Java and Go

There is a newer version: 0.9.23
Show newest version
package com.jsoniter.any;

import com.jsoniter.spi.JsonException;
import com.jsoniter.ValueType;

import java.io.IOException;

class LongLazyAny extends LazyAny {

    private boolean isCached;
    private long cache;

    public LongLazyAny(byte[] data, int head, int tail) {
        super(data, head, tail);
    }

    @Override
    public ValueType valueType() {
        return ValueType.NUMBER;
    }

    @Override
    public Object object() {
        fillCache();
        return cache;
    }

    @Override
    public boolean toBoolean() {
        fillCache();
        return cache != 0;
    }

    @Override
    public int toInt() {
        fillCache();
        return (int) cache;
    }

    @Override
    public long toLong() {
        fillCache();
        return cache;
    }

    @Override
    public float toFloat() {
        fillCache();
        return cache;
    }

    @Override
    public double toDouble() {
        fillCache();
        return cache;
    }

    private void fillCache() {
        if (!isCached) {
            try {
                cache = parse().readLong();
            } catch (IOException e) {
                throw new JsonException(e);
            }
            isCached = true;
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy