Make Mappings extendable

This commit is contained in:
Nassim Jahnke 2021-11-16 13:15:27 +01:00
parent 3051ddb6c0
commit 390155e03b
No known key found for this signature in database
GPG Key ID: 6BE3B555EBC5982B
2 changed files with 9 additions and 5 deletions

View File

@ -32,11 +32,15 @@ public class IntArrayMappings implements Mappings {
private final int[] oldToNew; private final int[] oldToNew;
private final int mappedIds; private final int mappedIds;
private IntArrayMappings(int[] oldToNew, int mappedIds) { protected IntArrayMappings(final int[] oldToNew, final int mappedIds) {
this.oldToNew = oldToNew; this.oldToNew = oldToNew;
this.mappedIds = mappedIds; this.mappedIds = mappedIds;
} }
public static IntArrayMappings of(final int[] oldToNew, final int mappedIds) {
return new IntArrayMappings(oldToNew, mappedIds);
}
public static Builder<IntArrayMappings> builder() { public static Builder<IntArrayMappings> builder() {
return Mappings.builder(IntArrayMappings::new); return Mappings.builder(IntArrayMappings::new);
} }

View File

@ -70,7 +70,7 @@ public interface Mappings {
T supply(int[] mappings, int mappedIds); T supply(int[] mappings, int mappedIds);
} }
final class Builder<T extends Mappings> { class Builder<T extends Mappings> {
private final MappingsSupplier<T> supplier; private final MappingsSupplier<T> supplier;
private JsonElement unmapped; private JsonElement unmapped;
@ -80,7 +80,7 @@ public interface Mappings {
private int size = -1; private int size = -1;
private boolean warnOnMissing = true; private boolean warnOnMissing = true;
private Builder(final MappingsSupplier<T> supplier) { protected Builder(final MappingsSupplier<T> supplier) {
this.supplier = supplier; this.supplier = supplier;
} }
@ -163,11 +163,11 @@ public interface Mappings {
return supplier.supply(mappings, mappedSize); return supplier.supply(mappings, mappedSize);
} }
private int size(final JsonElement element) { protected int size(final JsonElement element) {
return element.isJsonObject() ? element.getAsJsonObject().size() : element.getAsJsonArray().size(); return element.isJsonObject() ? element.getAsJsonObject().size() : element.getAsJsonArray().size();
} }
private JsonObject toJsonObject(final JsonArray array) { protected JsonObject toJsonObject(final JsonArray array) {
final JsonObject object = new JsonObject(); final JsonObject object = new JsonObject();
for (int i = 0; i < array.size(); i++) { for (int i = 0; i < array.size(); i++) {
final JsonElement element = array.get(i); final JsonElement element = array.get(i);