Utility for reading lists
ci/woodpecker/push/woodpecker Pipeline was successful
Details
ci/woodpecker/push/woodpecker Pipeline was successful
Details
This commit is contained in:
parent
780e6a7283
commit
8d50990c1a
|
@ -12,6 +12,7 @@ repositories {
|
|||
}
|
||||
|
||||
dependencies {
|
||||
implementation("io.gitlab.jfronny:commons:2022.11.1+17-58-36")
|
||||
api("io.gitlab.jfronny:commons-gson:2022.11.1+17-58-36")
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
package io.gitlab.jfronny.gson.compile.util;
|
||||
|
||||
import io.gitlab.jfronny.commons.throwable.ThrowingFunction;
|
||||
import io.gitlab.jfronny.gson.stream.JsonReader;
|
||||
import io.gitlab.jfronny.gson.stream.JsonToken;
|
||||
|
||||
import java.io.IOError;
|
||||
import java.io.IOException;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
public class GList {
|
||||
public static <T> List<T> read(JsonReader reader, ThrowingFunction<JsonReader, T, IOError> read) throws IOException {
|
||||
if (reader.isLenient() && reader.peek() != JsonToken.BEGIN_ARRAY) return List.of(read.apply(reader));
|
||||
reader.beginArray();
|
||||
List<T> res = new LinkedList<>();
|
||||
while (reader.hasNext()) {
|
||||
if (reader.peek() == JsonToken.NULL) {
|
||||
reader.nextNull();
|
||||
res.add(null);
|
||||
} else res.add(read.apply(reader));
|
||||
}
|
||||
reader.endArray();
|
||||
return res;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue