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

com.dslplatform.json.parsers.JsLongParser Maven / Gradle / Ivy

package com.dslplatform.json.parsers;

import com.dslplatform.json.JsonReader;
import com.dslplatform.json.MyNumberConverter;
import jsonvalues.JsLong;
import jsonvalues.spec.Error;

import java.io.IOException;
import java.util.Optional;
import java.util.function.LongFunction;

final class JsLongParser extends AbstractParser {

    @Override
    JsLong value(final JsonReader reader) throws JsParserException {
        try {
            return JsLong.of(MyNumberConverter.parseLong(reader));
        } catch (IOException e) {
            throw new JsParserException(e.getMessage());
        }
    }

    JsLong valueSuchThat(final JsonReader reader,
                         final LongFunction> fn
                        ) throws JsParserException {
        try {
            final long            value  = MyNumberConverter.parseLong(reader);
            final Optional result = fn.apply(value);
            if (!result.isPresent()) return JsLong.of(value);
            throw reader.newParseError(result.toString());
        } catch (IOException e) {
            throw new JsParserException(e.getMessage());

        }

    }


}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy