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

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

package com.dslplatform.json.parsers;

import com.dslplatform.json.JsonReader;
import com.dslplatform.json.ParsingException;
import jsonvalues.JsArray;
import jsonvalues.JsNull;
import jsonvalues.JsValue;
import jsonvalues.spec.Error;

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

final class JsArrayOfLongParser extends JsArrayParser {
    private final JsLongParser parser;

    JsArrayOfLongParser(final JsLongParser parser) {
        super(Objects.requireNonNull(parser));
        this.parser = parser;
    }

    JsValue nullOrArrayEachSuchThat(final JsonReader reader,
                                    final LongFunction> fn
                                   ) throws JsParserException {
        try {
            return reader.wasNull() ? JsNull.NULL : arrayEachSuchThat(reader,
                                                                      fn
                                                                     );
        } catch (ParsingException e) {
            throw new JsParserException(e.getMessage());

        }
    }


    JsArray arrayEachSuchThat(final JsonReader reader,
                              final LongFunction> fn
                             ) throws JsParserException {
        try {
            if (ifIsEmptyArray(reader)) return EMPTY;

            JsArray buffer = EMPTY.append(parser.valueSuchThat(reader,
                                                               fn
                                                              ));
            while (reader.getNextToken() == ',') {
                reader.getNextToken();
                buffer = buffer.append(parser.valueSuchThat(reader,
                                                            fn
                                                           ));
            }
            reader.checkArrayEnd();
            return buffer;
        } catch (IOException e) {
            throw new JsParserException(e.getMessage());

        }
    }


}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy