From c7aedb1cddcc63b7cb963c1a9b927a62323099ca Mon Sep 17 00:00:00 2001 From: Marja van Aken Date: Mon, 5 Feb 2024 13:45:46 +0100 Subject: [PATCH] First step to convert ImmutableList to LinkedList. ImmutableList extends LinkedList and reimplemented all the methods such that the order and usages of ImmutableList is kept the same. Co-authored-by: rdvdijk Co-authored-by: jvdb --- .../metal/data/ConcatenatedValueSource.java | 12 +- .../metal/data/DataExpressionSource.java | 8 +- .../parsingdata/metal/data/ImmutableList.java | 88 ++++--------- .../io/parsingdata/metal/data/ParseGraph.java | 8 +- .../io/parsingdata/metal/data/ParseState.java | 12 +- .../metal/data/ParseValueCache.java | 10 +- .../io/parsingdata/metal/data/Selection.java | 38 +++--- .../metal/data/callback/Callbacks.java | 8 +- .../comparison/ComparisonExpression.java | 10 +- .../value/BinaryValueExpression.java | 6 +- .../metal/expression/value/Bytes.java | 8 +- .../metal/expression/value/Cat.java | 2 +- .../metal/expression/value/Elvis.java | 6 +- .../metal/expression/value/Expand.java | 2 +- .../metal/expression/value/Fold.java | 12 +- .../metal/expression/value/Join.java | 6 +- .../metal/expression/value/Scope.java | 8 +- .../value/UnaryValueExpression.java | 2 +- .../expression/value/reference/Count.java | 4 +- .../value/reference/CurrentIteration.java | 6 +- .../expression/value/reference/First.java | 2 +- .../expression/value/reference/Last.java | 2 +- .../metal/expression/value/reference/Nth.java | 10 +- .../metal/expression/value/reference/Ref.java | 12 +- .../java/io/parsingdata/metal/token/Cho.java | 8 +- .../io/parsingdata/metal/token/DefUntil.java | 6 +- .../java/io/parsingdata/metal/token/RepN.java | 2 +- .../java/io/parsingdata/metal/token/Seq.java | 8 +- .../java/io/parsingdata/metal/token/Sub.java | 6 +- .../java/io/parsingdata/metal/token/Tie.java | 4 +- .../io/parsingdata/metal/token/TokenRef.java | 6 +- .../parsingdata/metal/AutoEqualityTest.java | 2 +- .../parsingdata/metal/CurrentOffsetTest.java | 4 +- .../io/parsingdata/metal/EqualityTest.java | 23 ++-- .../parsingdata/metal/ImmutableListTest.java | 81 ++++++------ .../metal/ImmutableObjectTest.java | 8 +- .../io/parsingdata/metal/ShorthandsTest.java | 40 +++--- .../io/parsingdata/metal/SubStructTest.java | 10 +- .../io/parsingdata/metal/ToStringTest.java | 6 +- .../java/io/parsingdata/metal/TreeTest.java | 6 +- .../io/parsingdata/metal/UtilInflateTest.java | 4 +- .../data/ConcatenatedValueSourceTest.java | 10 +- .../metal/data/ParseValueCacheTest.java | 20 +-- .../parsingdata/metal/data/SelectionTest.java | 7 +- .../metal/data/SourceAndSliceTest.java | 2 +- .../metal/data/callback/CallbackTest.java | 10 +- .../metal/data/selection/ByName.java | 14 +-- .../metal/data/selection/ByToken.java | 8 +- .../metal/data/selection/ByTokenTest.java | 118 +++++++++--------- .../metal/data/selection/ByType.java | 2 +- .../metal/expression/value/BytesTest.java | 10 +- .../expression/value/ElvisExpressionTest.java | 32 ++--- .../metal/expression/value/ExpandTest.java | 16 +-- .../metal/expression/value/FoldCatTest.java | 4 +- .../expression/value/FoldEdgeCaseTest.java | 18 +-- .../metal/expression/value/JoinTest.java | 8 +- .../expression/value/NthExpressionTest.java | 50 ++++---- .../expression/value/RefEdgeCaseTest.java | 4 +- .../metal/expression/value/ScopeTest.java | 6 +- .../value/ValueExpressionEvalEmptyTest.java | 4 +- .../value/reference/OffsetTest.java | 4 +- .../reference/RefMultiReferencesTest.java | 8 +- .../value/reference/RefToListTest.java | 8 +- .../io/parsingdata/metal/token/DefTest.java | 2 +- .../parsingdata/metal/token/DefUntilTest.java | 38 +++--- .../io/parsingdata/metal/token/TieTest.java | 22 ++-- 66 files changed, 461 insertions(+), 470 deletions(-) diff --git a/core/src/main/java/io/parsingdata/metal/data/ConcatenatedValueSource.java b/core/src/main/java/io/parsingdata/metal/data/ConcatenatedValueSource.java index cd5f0a79..3b866350 100644 --- a/core/src/main/java/io/parsingdata/metal/data/ConcatenatedValueSource.java +++ b/core/src/main/java/io/parsingdata/metal/data/ConcatenatedValueSource.java @@ -62,10 +62,10 @@ private static Trampoline calculateTotalSize(final ImmutableList size); } - if (values.head.equals(NOT_A_VALUE)) { + if (values.head().equals(NOT_A_VALUE)) { return complete(() -> ZERO); } - return intermediate(() -> calculateTotalSize(values.tail, size.add(values.head.slice().length))); + return intermediate(() -> calculateTotalSize(values.tail(), size.add(values.head().slice().length))); } @Override @@ -80,15 +80,15 @@ private Trampoline getData(final ImmutableList values, final BigI if (length.compareTo(ZERO) <= 0) { return complete(() -> output); } - final BigInteger nextOffset = currentOffset.add(values.head.slice().length); + final BigInteger nextOffset = currentOffset.add(values.head().slice().length); if (nextOffset.compareTo(offset) <= 0) { - return intermediate(() -> getData(values.tail, nextOffset, currentDest, offset, length, output)); + return intermediate(() -> getData(values.tail(), nextOffset, currentDest, offset, length, output)); } final BigInteger localOffset = offset.subtract(currentOffset).compareTo(ZERO) < 0 ? ZERO : offset.subtract(currentOffset); // The second argument in getData in Slice is a limit. It will return less if the end of slice is reached. - final byte[] data = values.head.slice().getData(localOffset, length); + final byte[] data = values.head().slice().getData(localOffset, length); System.arraycopy(data, 0, output, currentDest.intValueExact(), data.length); - return intermediate(() -> getData(values.tail, nextOffset, currentDest.add(valueOf(data.length)), offset, length.subtract(valueOf(data.length)), output)); + return intermediate(() -> getData(values.tail(), nextOffset, currentDest.add(valueOf(data.length)), offset, length.subtract(valueOf(data.length)), output)); } @Override diff --git a/core/src/main/java/io/parsingdata/metal/data/DataExpressionSource.java b/core/src/main/java/io/parsingdata/metal/data/DataExpressionSource.java index 58b836ea..29864f71 100644 --- a/core/src/main/java/io/parsingdata/metal/data/DataExpressionSource.java +++ b/core/src/main/java/io/parsingdata/metal/data/DataExpressionSource.java @@ -68,8 +68,8 @@ protected boolean isAvailable(final BigInteger offset, final BigInteger length) private synchronized byte[] getValue() { if (cache == null) { final ImmutableList results = dataExpression.eval(parseState, encoding); - if (results.size <= index) { - throw new IllegalStateException(format("ValueExpression dataExpression yields %d result(s) (expected at least %d).", results.size, index+1)); + if ((long) results.size() <= index) { + throw new IllegalStateException(format("ValueExpression dataExpression yields %d result(s) (expected at least %d).", (long) results.size(), index+1)); } final Value cacheValue = getValueAtIndex(results, index, 0).computeResult(); if (cacheValue.equals(NOT_A_VALUE)) { @@ -82,9 +82,9 @@ private synchronized byte[] getValue() { private Trampoline getValueAtIndex(final ImmutableList results, final int index, final int current) { if (index == current) { - return complete(() -> results.head); + return complete(() -> results.head()); } - return intermediate(() -> getValueAtIndex(results.tail, index, current + 1)); + return intermediate(() -> getValueAtIndex(results.tail(), index, current + 1)); } @Override diff --git a/core/src/main/java/io/parsingdata/metal/data/ImmutableList.java b/core/src/main/java/io/parsingdata/metal/data/ImmutableList.java index 5384b329..0caeabae 100644 --- a/core/src/main/java/io/parsingdata/metal/data/ImmutableList.java +++ b/core/src/main/java/io/parsingdata/metal/data/ImmutableList.java @@ -16,97 +16,59 @@ package io.parsingdata.metal.data; -import static io.parsingdata.metal.Trampoline.complete; -import static io.parsingdata.metal.Trampoline.intermediate; import static io.parsingdata.metal.Util.checkNotNull; -import static io.parsingdata.metal.data.Selection.reverse; -import java.util.Objects; +import java.util.Arrays; +import java.util.LinkedList; +import java.util.stream.Collectors; -import io.parsingdata.metal.ImmutableObject; -import io.parsingdata.metal.Trampoline; -import io.parsingdata.metal.Util; - -public class ImmutableList extends ImmutableObject { - - public final T head; - public final ImmutableList tail; - public final long size; +public class ImmutableList extends LinkedList { public ImmutableList() { - head = null; - tail = null; - size = 0; + super(); } - private ImmutableList(final T head, final ImmutableList tail) { - this.head = checkNotNull(head, "head"); - this.tail = checkNotNull(tail, "tail"); - size = tail.size + 1; + public ImmutableList(final LinkedList ts) { + super(ts); } public static ImmutableList create(final T head) { - return new ImmutableList().add(checkNotNull(head, "head")); + return new ImmutableList().addHead(checkNotNull(head, "head")); } public static ImmutableList create(final T[] array) { - return createFromArray(new ImmutableList<>(), checkNotNull(array, "array"), array.length - 1).computeResult(); + return new ImmutableList<>(new LinkedList<>(Arrays.stream(array).collect(Collectors.toList()))); } - private static Trampoline> createFromArray(final ImmutableList list, final T[] array, final int index) { - if (index < 0) { - return complete(() -> list); - } - return intermediate(() -> createFromArray(list.add(array[index]), array, index - 1)); + public ImmutableList addHead(final T head) { + final LinkedList ts = new LinkedList<>(this); + ts.addFirst(head); + return new ImmutableList<>(ts); } - public ImmutableList add(final T head) { - return new ImmutableList<>(checkNotNull(head, "head"), this); + public ImmutableList addList(final ImmutableList list) { + final LinkedList ts = new LinkedList<>(list); + ts.addAll(this); + return new ImmutableList<>(ts); } - public ImmutableList add(final ImmutableList list) { - checkNotNull(list, "list"); + public T head() { if (isEmpty()) { - return list; + return null; } - return addRecursive(reverse(list)).computeResult(); - } - - private Trampoline> addRecursive(final ImmutableList list) { - if (list.isEmpty()) { - return complete(() -> this); - } - return intermediate(() -> add(list.head).addRecursive(list.tail)); - } - - public boolean isEmpty() { - return size == 0; + return this.getFirst(); } - public boolean contains(final T value) { return containsRecursive(value).computeResult(); } - - private Trampoline containsRecursive(final T value) { - if (isEmpty()) { return complete(() -> false); } - if (head.equals(value)) { return complete(() -> true); } - return intermediate(() -> tail.containsRecursive(value)); + public ImmutableList tail() { + final LinkedList ts = new LinkedList<>(this.subList(1, size())); + return new ImmutableList<>(ts); } @Override public String toString() { - return isEmpty() ? "" : ">" + head + tail; + return isEmpty() ? "" : ">" + head() + tail(); } - @Override - public boolean equals(final Object obj) { - return Util.notNullAndSameClass(this, obj) - && Objects.equals(head, ((ImmutableList)obj).head) - && Objects.equals(tail, ((ImmutableList)obj).tail); - // The size field is excluded from equals() and hashCode() because it is cached data. - } - - @Override - public int immutableHashCode() { - return Objects.hash(getClass(), head, tail); - } + // TODO cache the hashcode like in ImmutableObject. } diff --git a/core/src/main/java/io/parsingdata/metal/data/ParseGraph.java b/core/src/main/java/io/parsingdata/metal/data/ParseGraph.java index 1ab44c22..b1e01df5 100644 --- a/core/src/main/java/io/parsingdata/metal/data/ParseGraph.java +++ b/core/src/main/java/io/parsingdata/metal/data/ParseGraph.java @@ -107,15 +107,15 @@ private Trampoline> current(final ImmutableList if (items.isEmpty()) { return complete(Optional::empty); } - final ParseItem item = items.head; + final ParseItem item = items.head(); if (item.isValue()) { return complete(() -> Optional.of(item.asValue())); } if (item.isGraph() && !item.asGraph().isEmpty()) { - return intermediate(() -> current(items.tail.add(item.asGraph().tail) - .add(item.asGraph().head))); + return intermediate(() -> current(items.tail().addHead(item.asGraph().tail) + .addHead(item.asGraph().head))); } - return intermediate(() -> current(items.tail)); + return intermediate(() -> current(items.tail())); } @Override public boolean isGraph() { return true; } diff --git a/core/src/main/java/io/parsingdata/metal/data/ParseState.java b/core/src/main/java/io/parsingdata/metal/data/ParseState.java index 41179c31..e8b7d9af 100644 --- a/core/src/main/java/io/parsingdata/metal/data/ParseState.java +++ b/core/src/main/java/io/parsingdata/metal/data/ParseState.java @@ -60,18 +60,18 @@ public static ParseState createFromByteStream(final ByteStream input) { } public ParseState addBranch(final Token token) { - return new ParseState(order.addBranch(token), cache, source, offset, token.isIterable() ? iterations.add(new ImmutablePair<>(token, ZERO)) : iterations, references); + return new ParseState(order.addBranch(token), cache, source, offset, token.isIterable() ? iterations.addHead(new ImmutablePair<>(token, ZERO)) : iterations, references); } public ParseState closeBranch(final Token token) { - if (token.isIterable() && !iterations.head.left.equals(token)) { - throw new IllegalStateException(format("Cannot close branch for iterable token %s. Current iteration state is for token %s.", token.name, iterations.head.left.name)); + if (token.isIterable() && !iterations.head().left.equals(token)) { + throw new IllegalStateException(format("Cannot close branch for iterable token %s. Current iteration state is for token %s.", token.name, iterations.head().left.name)); } - return new ParseState(order.closeBranch(), cache, source, offset, token.isIterable() ? iterations.tail : iterations, references); + return new ParseState(order.closeBranch(), cache, source, offset, token.isIterable() ? iterations.tail() : iterations, references); } public ParseState add(final ParseReference parseReference) { - return new ParseState(order, cache, source, offset, iterations, references.add(parseReference)); + return new ParseState(order, cache, source, offset, iterations, references.addHead(parseReference)); } public ParseState add(final ParseValue parseValue) { @@ -83,7 +83,7 @@ public ParseState createCycle(final ParseReference parseReference) { } public ParseState iterate() { - return new ParseState(order, cache, source, offset, iterations.tail.add(new ImmutablePair<>(iterations.head.left, iterations.head.right.add(ONE))), references); + return new ParseState(order, cache, source, offset, iterations.tail().addHead(new ImmutablePair<>(iterations.head().left, iterations.head().right.add(ONE))), references); } public Optional seek(final BigInteger newOffset) { diff --git a/core/src/main/java/io/parsingdata/metal/data/ParseValueCache.java b/core/src/main/java/io/parsingdata/metal/data/ParseValueCache.java index 50dc52b5..d68ce08a 100644 --- a/core/src/main/java/io/parsingdata/metal/data/ParseValueCache.java +++ b/core/src/main/java/io/parsingdata/metal/data/ParseValueCache.java @@ -44,14 +44,14 @@ public Optional> find(final String scopeName, int limit) { } private Trampoline> find(final ImmutableList searchList, final String scopeName, final int limit, final ImmutableList result) { - if (searchList.isEmpty() || (limit != NO_LIMIT && result.size == limit)) { + if (searchList.isEmpty() || (limit != NO_LIMIT && (long) result.size() == limit)) { return complete(() -> result); } - final ParseValue head = searchList.head; + final ParseValue head = searchList.head(); if (head.matches(scopeName)) { - return intermediate(() -> find(searchList.tail, scopeName, limit, result.add(head))); + return intermediate(() -> find(searchList.tail(), scopeName, limit, result.addHead(head))); } - return intermediate(() -> find(searchList.tail, scopeName, limit, result)); + return intermediate(() -> find(searchList.tail(), scopeName, limit, result)); } public ParseValueCache add(final ParseValue value) { @@ -61,7 +61,7 @@ public ParseValueCache add(final ParseValue value) { final String name = shortName(value.name); final Map> stringImmutableListHashMap = new HashMap<>(cache); stringImmutableListHashMap.computeIfAbsent(name, pattern -> new ImmutableList<>()); - stringImmutableListHashMap.computeIfPresent(name, (pattern, valueImmutableList) -> valueImmutableList.add(value)); + stringImmutableListHashMap.computeIfPresent(name, (pattern, valueImmutableList) -> valueImmutableList.addHead(value)); return new ParseValueCache(stringImmutableListHashMap); } diff --git a/core/src/main/java/io/parsingdata/metal/data/Selection.java b/core/src/main/java/io/parsingdata/metal/data/Selection.java index 0442deb5..4a84ee6a 100644 --- a/core/src/main/java/io/parsingdata/metal/data/Selection.java +++ b/core/src/main/java/io/parsingdata/metal/data/Selection.java @@ -39,7 +39,7 @@ public static Trampoline> findItemAtOffset(final ImmutableLi if (items.isEmpty()) { return complete(Optional::empty); } - final ParseItem head = items.head; + final ParseItem head = items.head(); if (head.isValue() && matchesLocation(head.asValue(), offset, source)) { return complete(() -> Optional.of(head)); } @@ -49,7 +49,7 @@ public static Trampoline> findItemAtOffset(final ImmutableLi return complete(() -> Optional.of(head)); } } - return intermediate(() -> findItemAtOffset(items.tail, offset, source)); + return intermediate(() -> findItemAtOffset(items.tail(), offset, source)); } private static boolean matchesLocation(final ParseValue value, final BigInteger offset, final Source source) { @@ -60,11 +60,11 @@ private static Trampoline getLowestOffsetValue(final ImmutableList

lowest); } - final ParseGraph graph = graphList.head; + final ParseGraph graph = graphList.head(); if (graph.isEmpty() || !graph.getDefinition().isLocal()) { - return intermediate(() -> getLowestOffsetValue(graphList.tail, lowest)); + return intermediate(() -> getLowestOffsetValue(graphList.tail(), lowest)); } - return intermediate(() -> getLowestOffsetValue(addIfGraph(graphList.tail.add(graph.tail), graph.head), + return intermediate(() -> getLowestOffsetValue(addIfGraph(graphList.tail().addHead(graph.tail), graph.head), compareIfValue(lowest, graph.head))); } @@ -77,7 +77,7 @@ private static ParseValue getLowest(final ParseValue lowest, final ParseValue va } private static ImmutableList addIfGraph(final ImmutableList graphList, final ParseItem head) { - return head.isGraph() ? graphList.add(head.asGraph()) : graphList; + return head.isGraph() ? graphList.addHead(head.asGraph()) : graphList; } public static ImmutableList getAllValues(final ParseGraph graph, final Predicate predicate, final int limit) { @@ -89,14 +89,14 @@ public static ImmutableList getAllValues(final ParseGraph graph, fin } private static Trampoline> getAllValues(final ImmutableList graphList, final ImmutableList valueList, final Predicate predicate, final int limit) { - if (graphList.isEmpty() || valueList.size == limit) { + if (graphList.isEmpty() || (long) valueList.size() == limit) { return complete(() -> valueList); } - final ParseGraph graph = graphList.head; + final ParseGraph graph = graphList.head(); if (graph.isEmpty()) { - return intermediate(() -> getAllValues(graphList.tail, valueList, predicate, limit)); + return intermediate(() -> getAllValues(graphList.tail(), valueList, predicate, limit)); } - return intermediate(() -> getAllValues(addIfGraph(graphList.tail.add(graph.tail), graph.head), + return intermediate(() -> getAllValues(addIfGraph(graphList.tail().addHead(graph.tail), graph.head), addIfMatchingValue(valueList, graph.head, predicate), predicate, limit)); @@ -104,7 +104,7 @@ private static Trampoline> getAllValues(final Immutabl private static ImmutableList addIfMatchingValue(final ImmutableList valueList, final ParseItem item, final Predicate predicate) { if (item.isValue() && predicate.test(item.asValue())) { - return valueList.add(item.asValue()); + return valueList.addHead(item.asValue()); } return valueList; } @@ -113,14 +113,14 @@ public static ImmutableList reverse(final ImmutableList list) { if (list.isEmpty()) { return list; } - return reverse(list.tail, ImmutableList.create(list.head)).computeResult(); + return reverse(list.tail(), ImmutableList.create(list.head())).computeResult(); } private static Trampoline> reverse(final ImmutableList oldList, final ImmutableList newList) { if (oldList.isEmpty()) { return complete(() -> newList); } - return intermediate(() -> reverse(oldList.tail, newList.add(oldList.head))); + return intermediate(() -> reverse(oldList.tail(), newList.addHead(oldList.head()))); } public static ImmutableList getAllRoots(final ParseGraph graph, final Token definition) { @@ -131,17 +131,17 @@ private static Trampoline> getAllRootsRecursive(final I if (backlog.isEmpty()) { return complete(() -> rootList); } - final ParseItem item = backlog.head.item; - final ParseGraph parent = backlog.head.parent; - final ImmutableList nextResult = item.getDefinition().equals(definition) && (parent == null || !parent.getDefinition().equals(definition)) ? rootList.add(item) : rootList; + final ParseItem item = backlog.head().item; + final ParseGraph parent = backlog.head().parent; + final ImmutableList nextResult = item.getDefinition().equals(definition) && (parent == null || !parent.getDefinition().equals(definition)) ? rootList.addHead(item) : rootList; if (item.isGraph() && !item.asGraph().isEmpty()) { final ParseGraph itemGraph = item.asGraph(); - return intermediate(() -> getAllRootsRecursive(backlog.tail.add(new Pair(itemGraph.head, itemGraph)) - .add(new Pair(itemGraph.tail, itemGraph)), + return intermediate(() -> getAllRootsRecursive(backlog.tail().addHead(new Pair(itemGraph.head, itemGraph)) + .addHead(new Pair(itemGraph.tail, itemGraph)), definition, nextResult)); } - return intermediate(() -> getAllRootsRecursive(backlog.tail, definition, nextResult)); + return intermediate(() -> getAllRootsRecursive(backlog.tail(), definition, nextResult)); } static class Pair { diff --git a/core/src/main/java/io/parsingdata/metal/data/callback/Callbacks.java b/core/src/main/java/io/parsingdata/metal/data/callback/Callbacks.java index 1c71b50b..cdae03f4 100644 --- a/core/src/main/java/io/parsingdata/metal/data/callback/Callbacks.java +++ b/core/src/main/java/io/parsingdata/metal/data/callback/Callbacks.java @@ -49,7 +49,7 @@ public Callbacks add(final Callback genericCallback) { } public Callbacks add(final Token token, final Callback callback) { - return new Callbacks(genericCallback, tokenCallbacks.add(new ImmutablePair<>(token, callback))); + return new Callbacks(genericCallback, tokenCallbacks.addHead(new ImmutablePair<>(token, callback))); } public static Consumer success(final Token token, final ParseState before, final ParseState after) { @@ -71,10 +71,10 @@ private Trampoline handleCallbacks(final ImmutableList null); } - if (callbacks.head.left.equals(token)) { - handler.accept(callbacks.head.right); + if (callbacks.head().left.equals(token)) { + handler.accept(callbacks.head().right); } - return intermediate(() -> handleCallbacks(callbacks.tail, token, handler)); + return intermediate(() -> handleCallbacks(callbacks.tail(), token, handler)); } @Override diff --git a/core/src/main/java/io/parsingdata/metal/expression/comparison/ComparisonExpression.java b/core/src/main/java/io/parsingdata/metal/expression/comparison/ComparisonExpression.java index 69cd0807..33453fec 100644 --- a/core/src/main/java/io/parsingdata/metal/expression/comparison/ComparisonExpression.java +++ b/core/src/main/java/io/parsingdata/metal/expression/comparison/ComparisonExpression.java @@ -66,21 +66,21 @@ public boolean eval(final ParseState parseState, final Encoding encoding) { return false; } final ImmutableList predicates = predicate.eval(parseState, encoding); - if (values.size != predicates.size) { + if ((long) values.size() != (long) predicates.size()) { return false; } return compare(values, predicates).computeResult(); } private Trampoline compare(final ImmutableList currents, final ImmutableList predicates) { - if (currents.head.equals(NOT_A_VALUE) || predicates.head.equals(NOT_A_VALUE)) { + if (currents.head().equals(NOT_A_VALUE) || predicates.head().equals(NOT_A_VALUE)) { return complete(() -> false); } - final boolean headResult = compare(currents.head, predicates.head); - if (!headResult || currents.tail.isEmpty()) { + final boolean headResult = compare(currents.head(), predicates.head()); + if (!headResult || currents.tail().isEmpty()) { return complete(() -> headResult); } - return intermediate(() -> compare(currents.tail, predicates.tail)); + return intermediate(() -> compare(currents.tail(), predicates.tail())); } public abstract boolean compare(final Value left, final Value right); diff --git a/core/src/main/java/io/parsingdata/metal/expression/value/BinaryValueExpression.java b/core/src/main/java/io/parsingdata/metal/expression/value/BinaryValueExpression.java index ad04e470..31290224 100644 --- a/core/src/main/java/io/parsingdata/metal/expression/value/BinaryValueExpression.java +++ b/core/src/main/java/io/parsingdata/metal/expression/value/BinaryValueExpression.java @@ -71,21 +71,21 @@ public ImmutableList eval(final ParseState parseState, final Encoding enc } private ImmutableList evalLists(final ImmutableList leftValues, final ImmutableList rightValues, final ParseState parseState, final Encoding encoding) { - return reverse(padList(evalLists(leftValues, rightValues, parseState, encoding, new ImmutableList<>()).computeResult(), Math.abs(leftValues.size - rightValues.size)).computeResult()); + return reverse(padList(evalLists(leftValues, rightValues, parseState, encoding, new ImmutableList<>()).computeResult(), Math.abs((long) leftValues.size() - (long) rightValues.size())).computeResult()); } private Trampoline> evalLists(final ImmutableList leftValues, final ImmutableList rightValues, final ParseState parseState, final Encoding encoding, final ImmutableList result) { if (leftValues.isEmpty() || rightValues.isEmpty()) { return complete(() -> result); } - return intermediate(() -> evalLists(leftValues.tail, rightValues.tail, parseState, encoding, result.add(safeEval(leftValues.head, rightValues.head, parseState, encoding)))); + return intermediate(() -> evalLists(leftValues.tail(), rightValues.tail(), parseState, encoding, result.addHead(safeEval(leftValues.head(), rightValues.head(), parseState, encoding)))); } private Trampoline> padList(final ImmutableList list, final long size) { if (size <= 0) { return complete(() -> list); } - return intermediate(() -> padList(list.add(NOT_A_VALUE), size - 1)); + return intermediate(() -> padList(list.addHead(NOT_A_VALUE), size - 1)); } private Value safeEval(final Value leftValue, final Value rightValue, final ParseState parseState, final Encoding encoding) { diff --git a/core/src/main/java/io/parsingdata/metal/expression/value/Bytes.java b/core/src/main/java/io/parsingdata/metal/expression/value/Bytes.java index 2399d7fe..e4d84308 100644 --- a/core/src/main/java/io/parsingdata/metal/expression/value/Bytes.java +++ b/core/src/main/java/io/parsingdata/metal/expression/value/Bytes.java @@ -59,15 +59,15 @@ public Bytes(final ValueExpression operand) { @Override public ImmutableList eval(final ParseState parseState, final Encoding encoding) { final ImmutableList values = operand.eval(parseState, encoding); - return values.isEmpty() ? values : toByteValues(new ImmutableList<>(), values.head, values.tail, encoding).computeResult(); + return values.isEmpty() ? values : toByteValues(new ImmutableList<>(), values.head(), values.tail(), encoding).computeResult(); } private Trampoline> toByteValues(final ImmutableList output, final Value head, final ImmutableList tail, final Encoding encoding) { - final ImmutableList result = output.add(extractByteValues(new ImmutableList<>(), head, 0, encoding).computeResult()); + final ImmutableList result = output.addList(extractByteValues(new ImmutableList<>(), head, 0, encoding).computeResult()); if (tail.isEmpty()) { return complete(() -> result); } else { - return intermediate(() -> toByteValues(result, tail.head, tail.tail, encoding)); + return intermediate(() -> toByteValues(result, tail.head(), tail.tail(), encoding)); } } @@ -75,7 +75,7 @@ private Trampoline> extractByteValues(final ImmutableList= 0) { return complete(() -> output); } - return intermediate(() -> extractByteValues(output.add(new CoreValue(createFromSource(value.slice().source, value.slice().offset.add(BigInteger.valueOf(i)), ONE).get(), encoding)), value, i + 1, encoding)); + return intermediate(() -> extractByteValues(output.addHead(new CoreValue(createFromSource(value.slice().source, value.slice().offset.add(BigInteger.valueOf(i)), ONE).get(), encoding)), value, i + 1, encoding)); } @Override diff --git a/core/src/main/java/io/parsingdata/metal/expression/value/Cat.java b/core/src/main/java/io/parsingdata/metal/expression/value/Cat.java index 768b3728..9b356115 100644 --- a/core/src/main/java/io/parsingdata/metal/expression/value/Cat.java +++ b/core/src/main/java/io/parsingdata/metal/expression/value/Cat.java @@ -38,7 +38,7 @@ public Cat(final ValueExpression left, final ValueExpression right) { @Override public Optional eval(final Value leftValue, final Value rightValue, final ParseState parseState, final Encoding encoding) { - return ConcatenatedValueSource.create(ImmutableList.create(leftValue).add(rightValue)) + return ConcatenatedValueSource.create(ImmutableList.create(leftValue).addHead(rightValue)) .flatMap(source -> createFromSource(source, ZERO, leftValue.length().add(rightValue.length()))) .map(source -> new CoreValue(source, encoding)); } diff --git a/core/src/main/java/io/parsingdata/metal/expression/value/Elvis.java b/core/src/main/java/io/parsingdata/metal/expression/value/Elvis.java index 7c09ea64..7a6b9db5 100644 --- a/core/src/main/java/io/parsingdata/metal/expression/value/Elvis.java +++ b/core/src/main/java/io/parsingdata/metal/expression/value/Elvis.java @@ -61,12 +61,12 @@ public ImmutableList eval(final ParseState parseState, final Encoding enc private Trampoline> eval(final ImmutableList result, final ImmutableList leftValues, final ImmutableList rightValues) { if (leftValues.isEmpty()) { - return complete(() -> result.add(reverse(rightValues))); + return complete(() -> result.addList(reverse(rightValues))); } if (rightValues.isEmpty()) { - return complete(() -> result.add(reverse(leftValues))); + return complete(() -> result.addList(reverse(leftValues))); } - return intermediate(() -> eval(result.add(leftValues.head.equals(NOT_A_VALUE) ? rightValues.head : leftValues.head), leftValues.tail, rightValues.tail)); + return intermediate(() -> eval(result.addHead(leftValues.head().equals(NOT_A_VALUE) ? rightValues.head() : leftValues.head()), leftValues.tail(), rightValues.tail())); } @Override diff --git a/core/src/main/java/io/parsingdata/metal/expression/value/Expand.java b/core/src/main/java/io/parsingdata/metal/expression/value/Expand.java index 41d4e772..dc84afb5 100644 --- a/core/src/main/java/io/parsingdata/metal/expression/value/Expand.java +++ b/core/src/main/java/io/parsingdata/metal/expression/value/Expand.java @@ -68,7 +68,7 @@ private Trampoline> expand(final ImmutableList baseL if (countValue < 1) { return complete(() -> aggregate); } - return intermediate(() -> expand(baseList, countValue - 1, aggregate.add(baseList))); + return intermediate(() -> expand(baseList, countValue - 1, aggregate.addList(baseList))); } @Override diff --git a/core/src/main/java/io/parsingdata/metal/expression/value/Fold.java b/core/src/main/java/io/parsingdata/metal/expression/value/Fold.java index 7cc1cbae..86216db7 100644 --- a/core/src/main/java/io/parsingdata/metal/expression/value/Fold.java +++ b/core/src/main/java/io/parsingdata/metal/expression/value/Fold.java @@ -71,17 +71,17 @@ public Optional evalSingle(final ParseState parseState, final Encoding en if (containsNotAValue(unpreparedValues).computeResult()) { return Optional.of(NOT_A_VALUE); } - final ImmutableList valueList = initialValue.map(value -> prepareValues(unpreparedValues).add(value)) + final ImmutableList valueList = initialValue.map(value -> prepareValues(unpreparedValues).addHead(value)) .orElseGet(() -> prepareValues(unpreparedValues)); - return Optional.of(fold(parseState, encoding, reducer, valueList.head, valueList.tail).computeResult()); + return Optional.of(fold(parseState, encoding, reducer, valueList.head(), valueList.tail()).computeResult()); } private Trampoline fold(final ParseState parseState, final Encoding encoding, final BinaryOperator reducer, final Value head, final ImmutableList tail) { if (head.equals(NOT_A_VALUE) || tail.isEmpty()) { return complete(() -> head); } - return reduce(reducer, head, tail.head).evalSingle(parseState, encoding) - .map(reducedValue -> intermediate(() -> fold(parseState, encoding, reducer, reducedValue, tail.tail))) + return reduce(reducer, head, tail.head()).evalSingle(parseState, encoding) + .map(reducedValue -> intermediate(() -> fold(parseState, encoding, reducer, reducedValue, tail.tail()))) .orElseThrow(() -> new IllegalArgumentException("Reducer must evaluate to a value.")); } @@ -89,10 +89,10 @@ private Trampoline containsNotAValue(final ImmutableList list) { if (list.isEmpty()) { return complete(() -> false); } - if (list.head.equals(NOT_A_VALUE)) { + if (list.head().equals(NOT_A_VALUE)) { return complete(() -> true); } - return intermediate(() -> containsNotAValue(list.tail)); + return intermediate(() -> containsNotAValue(list.tail())); } protected abstract ImmutableList prepareValues(ImmutableList valueList); diff --git a/core/src/main/java/io/parsingdata/metal/expression/value/Join.java b/core/src/main/java/io/parsingdata/metal/expression/value/Join.java index fa2dbcab..5ae7600a 100644 --- a/core/src/main/java/io/parsingdata/metal/expression/value/Join.java +++ b/core/src/main/java/io/parsingdata/metal/expression/value/Join.java @@ -46,8 +46,10 @@ public Join(final ValueExpression... expressions) { @Override public ImmutableList eval(final ParseState parseState, final Encoding encoding) { return Arrays.stream(expressions) - .map(e -> e.eval(parseState, encoding)) - .reduce(new ImmutableList<>(), ImmutableList::add, ImmutableList::add); + .map(e -> { + return e.eval(parseState, encoding); + }) + .reduce(new ImmutableList<>(), ImmutableList::addList, ImmutableList::addList); } @Override diff --git a/core/src/main/java/io/parsingdata/metal/expression/value/Scope.java b/core/src/main/java/io/parsingdata/metal/expression/value/Scope.java index 52c8fb4b..19ba5999 100644 --- a/core/src/main/java/io/parsingdata/metal/expression/value/Scope.java +++ b/core/src/main/java/io/parsingdata/metal/expression/value/Scope.java @@ -71,19 +71,19 @@ public ImmutableList eval(final ParseState parseState, final Encoding enc private ParseGraph calculateScope(final ParseGraph order, final int size) { final ImmutableList scopeList = createScopeList(order, new ImmutableList<>()).computeResult(); - if (size >= scopeList.size) { return order; } + if (size >= (long) scopeList.size()) { return order; } return findScope(scopeList, size).computeResult(); } private Trampoline> createScopeList(final ParseGraph order, final ImmutableList list) { - final ImmutableList newList = order.getDefinition().isScopeDelimiter() ? list.add(order) : list; + final ImmutableList newList = order.getDefinition().isScopeDelimiter() ? list.addHead(order) : list; if (order.isEmpty() || !order.head.isGraph()) { return complete(() -> list); } return intermediate(() -> createScopeList(order.head.asGraph(), newList)); } private Trampoline findScope(final ImmutableList scopeList, final int size) { - if (size == 0) { return complete(() -> scopeList.head); } - return intermediate(() -> findScope(scopeList.tail, size - 1)); + if (size == 0) { return complete(() -> scopeList.head()); } + return intermediate(() -> findScope(scopeList.tail(), size - 1)); } @Override diff --git a/core/src/main/java/io/parsingdata/metal/expression/value/UnaryValueExpression.java b/core/src/main/java/io/parsingdata/metal/expression/value/UnaryValueExpression.java index 702b3033..fbe39c3b 100644 --- a/core/src/main/java/io/parsingdata/metal/expression/value/UnaryValueExpression.java +++ b/core/src/main/java/io/parsingdata/metal/expression/value/UnaryValueExpression.java @@ -64,7 +64,7 @@ private Trampoline> eval(final ImmutableList values, if (values.isEmpty()) { return complete(() -> result); } - return intermediate(() -> eval(values.tail, parseState, encoding, result.add(safeEval(values.head, parseState, encoding)))); + return intermediate(() -> eval(values.tail(), parseState, encoding, result.addHead(safeEval(values.head(), parseState, encoding)))); } public abstract Optional eval(final Value value, final ParseState parseState, final Encoding encoding); diff --git a/core/src/main/java/io/parsingdata/metal/expression/value/reference/Count.java b/core/src/main/java/io/parsingdata/metal/expression/value/reference/Count.java index 4fcf6a69..75299567 100644 --- a/core/src/main/java/io/parsingdata/metal/expression/value/reference/Count.java +++ b/core/src/main/java/io/parsingdata/metal/expression/value/reference/Count.java @@ -23,6 +23,7 @@ import io.parsingdata.metal.ImmutableObject; import io.parsingdata.metal.Util; +import io.parsingdata.metal.data.ImmutableList; import io.parsingdata.metal.data.ParseState; import io.parsingdata.metal.encoding.Encoding; import io.parsingdata.metal.encoding.Sign; @@ -45,7 +46,8 @@ public Count(final ValueExpression operand) { @Override public Optional evalSingle(final ParseState parseState, final Encoding encoding) { - return Optional.of(fromNumeric(operand.eval(parseState, encoding).size)); + ImmutableList values = operand.eval(parseState, encoding); + return Optional.of(fromNumeric(values.size())); } private static Value fromNumeric(final long length) { diff --git a/core/src/main/java/io/parsingdata/metal/expression/value/reference/CurrentIteration.java b/core/src/main/java/io/parsingdata/metal/expression/value/reference/CurrentIteration.java index 84e17f1c..0978f0f8 100644 --- a/core/src/main/java/io/parsingdata/metal/expression/value/reference/CurrentIteration.java +++ b/core/src/main/java/io/parsingdata/metal/expression/value/reference/CurrentIteration.java @@ -68,7 +68,7 @@ public Optional evalSingle(final ParseState parseState, final Encoding en if (levelValue.isEmpty() || levelValue.get().equals(NOT_A_VALUE) || levelValue.get().asNumeric().compareTo(ZERO) < 0) { return Optional.of(NOT_A_VALUE); } - if (parseState.iterations.size <= levelValue.get().asNumeric().longValueExact()) { + if ((long) parseState.iterations.size() <= levelValue.get().asNumeric().longValueExact()) { return Optional.empty(); } return getIterationRecursive(parseState.iterations, levelValue.get().asNumeric()).computeResult(); @@ -76,9 +76,9 @@ public Optional evalSingle(final ParseState parseState, final Encoding en private Trampoline> getIterationRecursive(final ImmutableList> iterations, final BigInteger levelValue) { if (levelValue.compareTo(ZERO) == 0) { - return complete(() -> Optional.of(createFromNumeric(iterations.head.right, DEFAULT_ENCODING))); + return complete(() -> Optional.of(createFromNumeric(iterations.head().right, DEFAULT_ENCODING))); } - return intermediate(() -> getIterationRecursive(iterations.tail, levelValue.subtract(ONE))); + return intermediate(() -> getIterationRecursive(iterations.tail(), levelValue.subtract(ONE))); } @Override diff --git a/core/src/main/java/io/parsingdata/metal/expression/value/reference/First.java b/core/src/main/java/io/parsingdata/metal/expression/value/reference/First.java index a44ce7e2..2eb559d8 100644 --- a/core/src/main/java/io/parsingdata/metal/expression/value/reference/First.java +++ b/core/src/main/java/io/parsingdata/metal/expression/value/reference/First.java @@ -52,7 +52,7 @@ public Optional evalSingle(final ParseState parseState, final Encoding en } private Trampoline getFirst(final ImmutableList values) { - return values.tail.isEmpty() ? complete(() -> values.head) : intermediate(() -> getFirst(values.tail)); + return values.tail().isEmpty() ? complete(() -> values.head()) : intermediate(() -> getFirst(values.tail())); } @Override diff --git a/core/src/main/java/io/parsingdata/metal/expression/value/reference/Last.java b/core/src/main/java/io/parsingdata/metal/expression/value/reference/Last.java index 5ad3fe78..57de3979 100644 --- a/core/src/main/java/io/parsingdata/metal/expression/value/reference/Last.java +++ b/core/src/main/java/io/parsingdata/metal/expression/value/reference/Last.java @@ -45,7 +45,7 @@ public Last(final ValueExpression operand) { @Override public Optional evalSingle(final ParseState parseState, final Encoding encoding) { final ImmutableList values = operand.eval(parseState, encoding); - return values.isEmpty() ? Optional.empty() : Optional.of(values.head); + return values.isEmpty() ? Optional.empty() : Optional.of(values.head()); } @Override diff --git a/core/src/main/java/io/parsingdata/metal/expression/value/reference/Nth.java b/core/src/main/java/io/parsingdata/metal/expression/value/reference/Nth.java index 518bd7d7..de228431 100644 --- a/core/src/main/java/io/parsingdata/metal/expression/value/reference/Nth.java +++ b/core/src/main/java/io/parsingdata/metal/expression/value/reference/Nth.java @@ -68,19 +68,19 @@ private Trampoline> eval(final ImmutableList values, if (indices.isEmpty()) { return complete(() -> result); } - final BigInteger valueCount = BigInteger.valueOf(values.size); - final Value index = indices.head; + final BigInteger valueCount = BigInteger.valueOf(values.size()); + final Value index = indices.head(); final Value nextResult = !index.equals(NOT_A_VALUE) && index.asNumeric().compareTo(valueCount) < 0 && index.asNumeric().compareTo(ZERO) >= 0 ? nth(values, valueCount.subtract(index.asNumeric()).subtract(ONE)).computeResult() : NOT_A_VALUE; - return intermediate(() -> eval(values, indices.tail, result.add(nextResult))); + return intermediate(() -> eval(values, indices.tail(), result.addHead(nextResult))); } private Trampoline nth(final ImmutableList values, final BigInteger index) { if (index.equals(ZERO)) { - return complete(() -> values.head); + return complete(() -> values.head()); } - return intermediate(() -> nth(values.tail, index.subtract(ONE))); + return intermediate(() -> nth(values.tail(), index.subtract(ONE))); } @Override diff --git a/core/src/main/java/io/parsingdata/metal/expression/value/reference/Ref.java b/core/src/main/java/io/parsingdata/metal/expression/value/reference/Ref.java index f8db3d17..d6c334a1 100644 --- a/core/src/main/java/io/parsingdata/metal/expression/value/reference/Ref.java +++ b/core/src/main/java/io/parsingdata/metal/expression/value/reference/Ref.java @@ -63,7 +63,7 @@ private Ref(final BiPredicate predicate, final SingleValueExpress this.predicate = checkNotNull(predicate, "predicate"); this.limit = limit; this.references = create(checkContainsNoNulls(references, "references")) - .add(checkNotNull(reference, "reference")); + .addHead(checkNotNull(reference, "reference")); } private Ref(final BiPredicate predicate, final SingleValueExpression limit, final ImmutableList references) { @@ -80,8 +80,8 @@ public static class NameRef extends Ref { @Override ImmutableList evalImpl(final ParseState parseState, final int limit) { return Optional.of(parseState.cache) - .filter(p -> references.size == 1) - .flatMap(p -> p.find(references.head, limit)) + .filter(p -> (long) references.size() == 1) + .flatMap(p -> p.find(references.head(), limit)) .orElseGet(() -> wrap(getAllValues(parseState.order, parseValue -> toList(references).stream().anyMatch(ref -> predicate.test(parseValue, ref)), limit), new ImmutableList()).computeResult()); } @@ -122,8 +122,8 @@ static List toList(final ImmutableList allValues) { final List flatten = new ArrayList<>(); ImmutableList tail = allValues; while (!tail.isEmpty()) { - flatten.add(tail.head); - tail = tail.tail; + flatten.add(tail.head()); + tail = tail.tail(); } return flatten; } @@ -132,7 +132,7 @@ private static Trampoline> wrap(final Immutabl if (input.isEmpty()) { return complete(() -> output); } - return intermediate(() -> wrap(input.tail, output.add(input.head))); + return intermediate(() -> wrap(input.tail(), output.addHead(input.head()))); } @Override diff --git a/core/src/main/java/io/parsingdata/metal/token/Cho.java b/core/src/main/java/io/parsingdata/metal/token/Cho.java index 261cab7d..600cc7ac 100644 --- a/core/src/main/java/io/parsingdata/metal/token/Cho.java +++ b/core/src/main/java/io/parsingdata/metal/token/Cho.java @@ -47,8 +47,8 @@ public class Cho extends CycleToken { public Cho(final String name, final Encoding encoding, final Token token1, final Token token2, final Token... additionalTokens) { super(name, encoding); this.tokens = create(checkContainsNoNulls(additionalTokens, "additionalTokens")) - .add(checkNotNull(token2, "token2")) - .add(checkNotNull(token1, "token1")); + .addHead(checkNotNull(token2, "token2")) + .addHead(checkNotNull(token1, "token1")); } @Override @@ -60,10 +60,10 @@ private Trampoline> iterate(final Environment environment, if (list.isEmpty()) { return complete(Util::failure); } - return list.head + return list.head() .parse(environment) .map(result -> complete(() -> success(result.closeBranch(this)))) - .orElseGet(() -> intermediate(() -> iterate(environment, list.tail))); + .orElseGet(() -> intermediate(() -> iterate(environment, list.tail()))); } @Override diff --git a/core/src/main/java/io/parsingdata/metal/token/DefUntil.java b/core/src/main/java/io/parsingdata/metal/token/DefUntil.java index 0b758c7b..f7dffbaa 100644 --- a/core/src/main/java/io/parsingdata/metal/token/DefUntil.java +++ b/core/src/main/java/io/parsingdata/metal/token/DefUntil.java @@ -101,7 +101,7 @@ private Trampoline> handleInterval(final Environment enviro return iterate(environment, getNumeric(initialSizes), getNumeric(stepSizes), getNumeric(maxSizes)) .computeResult() .map(nextParseState -> complete(() -> success(nextParseState))) - .orElseGet(() -> intermediate(() -> handleInterval(environment, initialSizes.tail, stepSizes.tail, maxSizes.tail))); + .orElseGet(() -> intermediate(() -> handleInterval(environment, initialSizes.tail(), stepSizes.tail(), maxSizes.tail()))); } private Trampoline> iterate(final Environment environment, final BigInteger currentSize, final BigInteger stepSize, final BigInteger maxSize) { @@ -125,11 +125,11 @@ private Trampoline> parseSlice(final Environment environmen } private boolean checkNotValidList(final ImmutableList list) { - return list.isEmpty() || list.head.equals(NOT_A_VALUE); + return list.isEmpty() || list.head().equals(NOT_A_VALUE); } private BigInteger getNumeric(final ImmutableList list) { - return list.head.asNumeric(); + return list.head().asNumeric(); } @Override diff --git a/core/src/main/java/io/parsingdata/metal/token/RepN.java b/core/src/main/java/io/parsingdata/metal/token/RepN.java index c320c2c1..986dcce0 100644 --- a/core/src/main/java/io/parsingdata/metal/token/RepN.java +++ b/core/src/main/java/io/parsingdata/metal/token/RepN.java @@ -53,7 +53,7 @@ public RepN(final String name, final Token token, final SingleValueExpression n, protected Optional parseImpl(final Environment environment) { return n.evalSingle(environment.parseState, environment.encoding) .filter(count -> !count.equals(NOT_A_VALUE)) - .flatMap(count -> parse(environment, env -> env.parseState.iterations.head.right.compareTo(count.asNumeric()) >= 0, env -> failure())); + .flatMap(count -> parse(environment, env -> env.parseState.iterations.head().right.compareTo(count.asNumeric()) >= 0, env -> failure())); } @Override diff --git a/core/src/main/java/io/parsingdata/metal/token/Seq.java b/core/src/main/java/io/parsingdata/metal/token/Seq.java index 5cd3dc67..c4bfaef6 100644 --- a/core/src/main/java/io/parsingdata/metal/token/Seq.java +++ b/core/src/main/java/io/parsingdata/metal/token/Seq.java @@ -47,8 +47,8 @@ public class Seq extends CycleToken { public Seq(final String name, final Encoding encoding, final Token token1, final Token token2, final Token... additionalTokens) { super(name, encoding); this.tokens = create(checkContainsNoNulls(additionalTokens, "additionalTokens")) - .add(checkNotNull(token2, "token2")) - .add(checkNotNull(token1, "token1")); + .addHead(checkNotNull(token2, "token2")) + .addHead(checkNotNull(token1, "token1")); } @Override @@ -60,9 +60,9 @@ private Trampoline> iterate(final Environment environment, if (list.isEmpty()) { return complete(() -> success(environment.parseState.closeBranch(this))); } - return list.head + return list.head() .parse(environment) - .map(nextParseState -> intermediate(() -> iterate(environment.withParseState(nextParseState), list.tail))) + .map(nextParseState -> intermediate(() -> iterate(environment.withParseState(nextParseState), list.tail()))) .orElseGet(() -> complete(Util::failure)); } diff --git a/core/src/main/java/io/parsingdata/metal/token/Sub.java b/core/src/main/java/io/parsingdata/metal/token/Sub.java index bae098ef..9ace7f49 100644 --- a/core/src/main/java/io/parsingdata/metal/token/Sub.java +++ b/core/src/main/java/io/parsingdata/metal/token/Sub.java @@ -71,11 +71,11 @@ private Trampoline> iterate(final Environment environment, if (offsetList.isEmpty()) { return complete(() -> success(environment.parseState.closeBranch(this))); } - if (offsetList.head.equals(NOT_A_VALUE)) { + if (offsetList.head().equals(NOT_A_VALUE)) { return complete(Util::failure); } - return parse(environment, offsetList.head.asNumeric()) - .map(nextParseState -> intermediate(() -> iterate(environment.withParseState(nextParseState), offsetList.tail))) + return parse(environment, offsetList.head().asNumeric()) + .map(nextParseState -> intermediate(() -> iterate(environment.withParseState(nextParseState), offsetList.tail()))) .orElseGet(() -> complete(Util::failure)); } diff --git a/core/src/main/java/io/parsingdata/metal/token/Tie.java b/core/src/main/java/io/parsingdata/metal/token/Tie.java index 219bf091..31ea354d 100644 --- a/core/src/main/java/io/parsingdata/metal/token/Tie.java +++ b/core/src/main/java/io/parsingdata/metal/token/Tie.java @@ -69,11 +69,11 @@ private Trampoline> iterate(final Environment environment, if (values.isEmpty()) { return complete(() -> success(new ParseState(environment.parseState.closeBranch(this).order, environment.parseState.cache, returnParseState.source, returnParseState.offset, returnParseState.iterations, returnParseState.references))); } - if (values.head.equals(NOT_A_VALUE)) { + if (values.head().equals(NOT_A_VALUE)) { return complete(Util::failure); } return token.parse(environment.withParseState(environment.parseState.withSource(new DataExpressionSource(dataExpression, index, environment.parseState, environment.encoding)))) - .map(nextParseState -> intermediate(() -> iterate(environment.withParseState(nextParseState), values.tail, index + 1, returnParseState))) + .map(nextParseState -> intermediate(() -> iterate(environment.withParseState(nextParseState), values.tail(), index + 1, returnParseState))) .orElseGet(() -> complete(Util::failure)); } diff --git a/core/src/main/java/io/parsingdata/metal/token/TokenRef.java b/core/src/main/java/io/parsingdata/metal/token/TokenRef.java index c4dee892..17d53e91 100644 --- a/core/src/main/java/io/parsingdata/metal/token/TokenRef.java +++ b/core/src/main/java/io/parsingdata/metal/token/TokenRef.java @@ -70,14 +70,14 @@ private Trampoline lookup(final ImmutableList items, final Str if (items.isEmpty()) { return complete(() -> LOOKUP_FAILED); } - final ParseItem item = items.head; + final ParseItem item = items.head(); if (item.getDefinition().name.equals(referenceName)) { return complete(item::getDefinition); } if (item.isGraph() && !item.asGraph().isEmpty()) { - return intermediate(() -> lookup(items.tail.add(item.asGraph().tail).add(item.asGraph().head), referenceName)); + return intermediate(() -> lookup(items.tail().addHead(item.asGraph().tail).addHead(item.asGraph().head), referenceName)); } - return intermediate(() -> lookup(items.tail, referenceName)); + return intermediate(() -> lookup(items.tail(), referenceName)); } @Override diff --git a/core/src/test/java/io/parsingdata/metal/AutoEqualityTest.java b/core/src/test/java/io/parsingdata/metal/AutoEqualityTest.java index 2c40a13a..d5a333db 100644 --- a/core/src/test/java/io/parsingdata/metal/AutoEqualityTest.java +++ b/core/src/test/java/io/parsingdata/metal/AutoEqualityTest.java @@ -221,7 +221,7 @@ public class AutoEqualityTest { private static final List> BIG_INTEGERS = List.of(() -> ONE, () -> BigInteger.valueOf(3)); private static final List> PARSE_STATES = List.of(() -> createFromByteStream(DUMMY_STREAM), () -> createFromByteStream(DUMMY_STREAM, ONE), () -> new ParseState(GRAPH_WITH_REFERENCE, NO_CACHE, DUMMY_BYTE_STREAM_SOURCE, TEN, new ImmutableList<>(), new ImmutableList<>())); private static final List> PARSE_VALUE_CACHES = List.of(() -> NO_CACHE, () -> new ParseValueCache(), () -> new ParseValueCache().add(PARSE_VALUE), () -> new ParseValueCache().add(PARSE_VALUE).add(PARSE_VALUE)); - private static final List> IMMUTABLE_LISTS = List.of(ImmutableList::new, () -> ImmutableList.create("TEST"), () -> ImmutableList.create(1), () -> ImmutableList.create(1).add(2)); + private static final List> IMMUTABLE_LISTS = List.of(ImmutableList::new, () -> ImmutableList.create("TEST"), () -> ImmutableList.create(1), () -> ImmutableList.create(1).addHead(2)); private static final List> BOOLEANS = List.of(() -> true, () -> false); private static final List> BIPREDICATES = List.of(() -> (BiPredicate) (o, o2) -> false); private static final Map, List>> mapping = buildMap(); diff --git a/core/src/test/java/io/parsingdata/metal/CurrentOffsetTest.java b/core/src/test/java/io/parsingdata/metal/CurrentOffsetTest.java index 876352a3..6c1e6a18 100644 --- a/core/src/test/java/io/parsingdata/metal/CurrentOffsetTest.java +++ b/core/src/test/java/io/parsingdata/metal/CurrentOffsetTest.java @@ -53,8 +53,8 @@ private void checkCurrentOffset(final int size) { final ImmutableList offset = CURRENT_OFFSET.eval(result.get(), enc()); assertNotNull(offset); - assertEquals(1, offset.size); - assertEquals(size, offset.head.asNumeric().longValueExact()); + assertEquals(1, (long) offset.size()); + assertEquals(size, offset.head().asNumeric().longValueExact()); } @Test diff --git a/core/src/test/java/io/parsingdata/metal/EqualityTest.java b/core/src/test/java/io/parsingdata/metal/EqualityTest.java index e55b392e..6571187a 100644 --- a/core/src/test/java/io/parsingdata/metal/EqualityTest.java +++ b/core/src/test/java/io/parsingdata/metal/EqualityTest.java @@ -57,6 +57,7 @@ import io.parsingdata.metal.data.ImmutableList; import io.parsingdata.metal.data.ImmutablePair; import io.parsingdata.metal.data.ParseGraph; +import io.parsingdata.metal.data.ParseItem; import io.parsingdata.metal.data.ParseState; import io.parsingdata.metal.data.ParseValue; import io.parsingdata.metal.data.Slice; @@ -99,16 +100,20 @@ public class EqualityTest { public void cycleWithIdenticalTokens() { final Optional result = LINKED_LIST_COMPOSED_IDENTICAL.parse(env(stream(0, 0, 1))); assertTrue(result.isPresent()); - assertEquals(1, getAllValues(result.get().order, "header").size); - assertEquals(2, getReferences(result.get().order).size); + ImmutableList parseValues = getAllValues(result.get().order, "header"); + assertEquals(1, (long) parseValues.size()); + ImmutableList> optionals = getReferences(result.get().order); + assertEquals(2, (long) optionals.size()); } @Test public void cycleWithEqualTokens() { final Optional result = LINKED_LIST_COMPOSED_EQUAL.parse(env(stream(0, 0, 1))); assertTrue(result.isPresent()); - assertEquals(1, getAllValues(result.get().order, "header").size); - assertEquals(2, getReferences(result.get().order).size); + ImmutableList parseValues = getAllValues(result.get().order, "header"); + assertEquals(1, (long) parseValues.size()); + ImmutableList> optionals = getReferences(result.get().order); + assertEquals(2, (long) optionals.size()); } @Test @@ -159,12 +164,12 @@ public void immutableList() { final ImmutableList object = ImmutableList.create("a"); assertFalse(object.equals(null)); assertEquals(object, ImmutableList.create("a")); - assertEquals(object, new ImmutableList<>().add("a")); + assertEquals(object, new ImmutableList<>().addHead("a")); assertNotEquals("a", object); - assertEquals(object.add("b"), ImmutableList.create("a").add("b")); - assertEquals(object.add("b").add("c"), ImmutableList.create("a").add("b").add("c")); - assertNotEquals(object.add("b"), ImmutableList.create("a").add("c")); - assertNotEquals(object.add("b").add("c"), ImmutableList.create("a").add("c").add("c")); + assertEquals(object.addHead("b"), ImmutableList.create("a").addHead("b")); + assertEquals(object.addHead("b").addHead("c"), ImmutableList.create("a").addHead("b").addHead("c")); + assertNotEquals(object.addHead("b"), ImmutableList.create("a").addHead("c")); + assertNotEquals(object.addHead("b").addHead("c"), ImmutableList.create("a").addHead("c").addHead("c")); } @Test diff --git a/core/src/test/java/io/parsingdata/metal/ImmutableListTest.java b/core/src/test/java/io/parsingdata/metal/ImmutableListTest.java index da6678f5..ad01029e 100644 --- a/core/src/test/java/io/parsingdata/metal/ImmutableListTest.java +++ b/core/src/test/java/io/parsingdata/metal/ImmutableListTest.java @@ -49,43 +49,43 @@ public ImmutableListTest() { v1 = val('a'); l1 = ImmutableList.create(v1); v2 = val('b'); - l2 = l1.add(v2); + l2 = l1.addHead(v2); v3 = val('a'); - l3 = l2.add(v3); + l3 = l2.addHead(v3); v4 = val('d'); - l4 = l3.add(v4); + l4 = l3.addHead(v4); v5 = val('e'); - l5 = l4.add(v5); + l5 = l4.addHead(v5); } @Test public void addList() { - final ImmutableList l6 = l5.add(l5); - assertEquals(v5, l6.head); - assertEquals(v4, l6.tail.head); - assertEquals(v3, l6.tail.tail.head); - assertEquals(v2, l6.tail.tail.tail.head); - assertEquals(v1, l6.tail.tail.tail.tail.head); - assertEquals(v5, l6.tail.tail.tail.tail.tail.head); - assertEquals(v4, l6.tail.tail.tail.tail.tail.tail.head); - assertEquals(v3, l6.tail.tail.tail.tail.tail.tail.tail.head); - assertEquals(v2, l6.tail.tail.tail.tail.tail.tail.tail.tail.head); - assertEquals(v1, l6.tail.tail.tail.tail.tail.tail.tail.tail.tail.head); - assertTrue(l6.tail.tail.tail.tail.tail.tail.tail.tail.tail.tail.isEmpty()); + final ImmutableList l6 = l5.addList(l5); + assertEquals(v5, l6.head()); + assertEquals(v4, l6.tail().head()); + assertEquals(v3, l6.tail().tail().head()); + assertEquals(v2, l6.tail().tail().tail().head()); + assertEquals(v1, l6.tail().tail().tail().tail().head()); + assertEquals(v5, l6.tail().tail().tail().tail().tail().head()); + assertEquals(v4, l6.tail().tail().tail().tail().tail().tail().head()); + assertEquals(v3, l6.tail().tail().tail().tail().tail().tail().tail().head()); + assertEquals(v2, l6.tail().tail().tail().tail().tail().tail().tail().tail().head()); + assertEquals(v1, l6.tail().tail().tail().tail().tail().tail().tail().tail().tail().head()); + assertTrue(l6.tail().tail().tail().tail().tail().tail().tail().tail().tail().tail().isEmpty()); } @Test public void traverse() { - assertEquals(l5.head, v5); - assertEquals(l5.tail, l4); - assertEquals(l4.head, v4); - assertEquals(l4.tail, l3); - assertEquals(l3.head, v3); - assertEquals(l3.tail, l2); - assertEquals(l2.head, v2); - assertEquals(l2.tail, l1); - assertEquals(l1.head, v1); - assertTrue(l1.tail.isEmpty()); + assertEquals(l5.head(), v5); + assertEquals(l5.tail(), l4); + assertEquals(l4.head(), v4); + assertEquals(l4.tail(), l3); + assertEquals(l3.head(), v3); + assertEquals(l3.tail(), l2); + assertEquals(l2.head(), v2); + assertEquals(l2.tail(), l1); + assertEquals(l1.head(), v1); + assertTrue(l1.tail().isEmpty()); } @Test @@ -101,16 +101,16 @@ public void getSingleNoMatch() { @Test public void getMultiMultiMatch() { final ImmutableList res = getAll(l5, "a"); - assertEquals(res.head, v3); - assertEquals(res.tail.head, v1); - assertTrue(res.tail.tail.isEmpty()); + assertEquals(res.head(), v3); + assertEquals(res.tail().head(), v1); + assertTrue(res.tail().tail().isEmpty()); } @Test public void getMultiSingleMatch() { final ImmutableList res = getAll(l5, "d"); - assertEquals(res.head, v4); - assertTrue(res.tail.isEmpty()); + assertEquals(res.head(), v4); + assertTrue(res.tail().isEmpty()); } @Test @@ -122,12 +122,12 @@ public void getMultiNoMatch() { @Test public void reverseRegular() { final ImmutableList rev = reverse(l5); - assertEquals(rev.head, v1); - assertEquals(rev.tail.head, v2); - assertEquals(rev.tail.tail.head, v3); - assertEquals(rev.tail.tail.tail.head, v4); - assertEquals(rev.tail.tail.tail.tail.head, v5); - assertTrue(rev.tail.tail.tail.tail.tail.isEmpty()); + assertEquals(rev.head(), v1); + assertEquals(rev.tail().head(), v2); + assertEquals(rev.tail().tail().head(), v3); + assertEquals(rev.tail().tail().tail().head(), v4); + assertEquals(rev.tail().tail().tail().tail().head(), v5); + assertTrue(rev.tail().tail().tail().tail().tail().isEmpty()); } @Test @@ -137,13 +137,14 @@ public void reverseEmpty() { @Test public void size() { - assertEquals(1, l1.size); - assertEquals(5, l5.size); + assertEquals(1, (long) l1.size()); + assertEquals(5, (long) l5.size()); } @Test public void sizeEmpty() { - assertEquals(0, new ImmutableList().size); + ImmutableList parseValues = new ImmutableList(); + assertEquals(0, (long) parseValues.size()); } private ParseValue val(final char c) { diff --git a/core/src/test/java/io/parsingdata/metal/ImmutableObjectTest.java b/core/src/test/java/io/parsingdata/metal/ImmutableObjectTest.java index 56879d50..3e419c95 100644 --- a/core/src/test/java/io/parsingdata/metal/ImmutableObjectTest.java +++ b/core/src/test/java/io/parsingdata/metal/ImmutableObjectTest.java @@ -102,12 +102,12 @@ void performanceTest() { assertTrue(result.isPresent()); ImmutableList allValues = Selection.getAllValues(result.get().order, x -> true); - assertThat(allValues.size, equalTo(66L)); + assertThat((long) allValues.size(), equalTo(66L)); final Map values = new HashMap<>(); - while (allValues != null && allValues.head != null) { - values.put(allValues.head, allValues.head); - allValues = allValues.tail; + while (allValues != null && allValues.head() != null) { + values.put(allValues.head(), allValues.head()); + allValues = allValues.tail(); } assertThat(values.size(), equalTo(66)); } diff --git a/core/src/test/java/io/parsingdata/metal/ShorthandsTest.java b/core/src/test/java/io/parsingdata/metal/ShorthandsTest.java index 48199199..93eb1527 100644 --- a/core/src/test/java/io/parsingdata/metal/ShorthandsTest.java +++ b/core/src/test/java/io/parsingdata/metal/ShorthandsTest.java @@ -165,15 +165,15 @@ public void allTokensNamed() { private void checkNameAndValue(final String name, final int value, final ParseState parseState) { ImmutableList optionalValues = ref(name).eval(parseState, enc()); - assertEquals(1, optionalValues.size); - assertEquals(value, optionalValues.head.asNumeric().intValueExact()); + assertEquals(1, (long) optionalValues.size()); + assertEquals(value, optionalValues.head().asNumeric().intValueExact()); ImmutableList values = optionalValues; while (!values.isEmpty()) { - final Value current = values.head; + final Value current = values.head(); assertThat(current, is(instanceOf(ParseValue.class))); - assertEquals(name, ((ParseValue)values.head).name); - values = values.tail; + assertEquals(name, ((ParseValue) values.head()).name); + values = values.tail(); } } @@ -184,18 +184,18 @@ private void checkNameAndValue(final String name, final int value, final ParseSt public void checkChoTokens() { final Token choToken = cho(DEF_A, DEF_B); final Cho cho = (Cho)choToken; - assertEquals(2, cho.tokens.size); - assertEquals(DEF_A, cho.tokens.head); - assertEquals(DEF_B, cho.tokens.tail.head); + assertEquals(2, (long) cho.tokens.size()); + assertEquals(DEF_A, cho.tokens.head()); + assertEquals(DEF_B, cho.tokens.tail().head()); } @Test public void checkSeqTokens() { final Token seqToken = seq(DEF_A, DEF_B); final Seq seq = (Seq)seqToken; - assertEquals(2, seq.tokens.size); - assertEquals(DEF_A, seq.tokens.head); - assertEquals(DEF_B, seq.tokens.tail.head); + assertEquals(2, (long) seq.tokens.size()); + assertEquals(DEF_A, seq.tokens.head()); + assertEquals(DEF_B, seq.tokens.tail().head()); } private final ParseState PARSE_STATE = createFromByteStream(DUMMY_STREAM).add(createParseValue("a", 126)).add(createParseValue("a", 84)).add(createParseValue("a", 42)); @@ -203,20 +203,20 @@ public void checkSeqTokens() { @Test public void mapLeftWithSub() { ImmutableList result = mapLeft(Shorthand::sub, ref("a"), con(2)).eval(PARSE_STATE, enc()); - assertEquals(3, result.size); + assertEquals(3, (long) result.size()); for (int i = 0; i < 3; i++) { - assertEquals((i * 42) + 40, result.head.asNumeric().intValueExact()); - result = result.tail; + assertEquals((i * 42) + 40, result.head().asNumeric().intValueExact()); + result = result.tail(); } } @Test public void mapRightWithSub() { ImmutableList result = mapRight(Shorthand::sub, con(126), ref("a")).eval(PARSE_STATE, enc()); - assertEquals(3, result.size); + assertEquals(3, (long) result.size()); for (int i = 0; i < 3; i++) { - assertEquals(((3 - i) * 42) - 42, result.head.asNumeric().intValueExact()); - result = result.tail; + assertEquals(((3 - i) * 42) - 42, result.head().asNumeric().intValueExact()); + result = result.tail(); } } @@ -225,7 +225,8 @@ public void whenTrue() { Optional result = when(def("name", con(1), eq(con(1))), TRUE).parse(env(stream(1))); assertTrue(result.isPresent()); assertEquals(1, result.get().offset.intValueExact()); - assertEquals(1, Selection.getAllValues(result.get().order, parseValue -> parseValue.matches("name") && parseValue.value().length == 1 && parseValue.value()[0] == 1).size); + ImmutableList parseValues = Selection.getAllValues(result.get().order, parseValue -> parseValue.matches("name") && parseValue.value().length == 1 && parseValue.value()[0] == 1); + assertEquals(1, (long) parseValues.size()); } @Test @@ -236,7 +237,8 @@ public void whenFalse() { def("name2", con(1), eq(con(2)))).parse(env(stream(2))); assertTrue(result.isPresent()); assertEquals(1, result.get().offset.intValueExact()); - assertEquals(1, Selection.getAllValues(result.get().order, parseValue -> parseValue.matches("name2") && parseValue.value().length == 1 && parseValue.value()[0] == 2).size); + ImmutableList parseValues = Selection.getAllValues(result.get().order, parseValue -> parseValue.matches("name2") && parseValue.value().length == 1 && parseValue.value()[0] == 2); + assertEquals(1, (long) parseValues.size()); } } diff --git a/core/src/test/java/io/parsingdata/metal/SubStructTest.java b/core/src/test/java/io/parsingdata/metal/SubStructTest.java index a888bb66..a479016f 100644 --- a/core/src/test/java/io/parsingdata/metal/SubStructTest.java +++ b/core/src/test/java/io/parsingdata/metal/SubStructTest.java @@ -42,6 +42,7 @@ import org.junit.jupiter.api.Test; +import io.parsingdata.metal.data.ImmutableList; import io.parsingdata.metal.data.ParseGraph; import io.parsingdata.metal.data.ParseItem; import io.parsingdata.metal.data.ParseReference; @@ -70,7 +71,8 @@ public void linkedList() { final Optional result = LINKED_LIST.parse(env(parseState, enc())); assertTrue(result.isPresent()); final ParseGraph graph = result.get().order; - assertEquals(0, getReferences(graph).size); // No cycles + ImmutableList> optionals = getReferences(graph); + assertEquals(0, (long) optionals.size()); // No cycles final ParseGraph first = graph.head.asGraph(); checkBranch(first, 0, 8); @@ -88,7 +90,8 @@ public void linkedListWithSelfReference() { final Optional result = LINKED_LIST.parse(env(parseState, enc())); assertTrue(result.isPresent()); final ParseGraph graph = result.get().order; - assertEquals(1, getReferences(graph).size); + ImmutableList> optionals = getReferences(graph); + assertEquals(1, (long) optionals.size()); final ParseGraph first = graph.head.asGraph(); checkBranch(first, 0, 0); @@ -101,7 +104,8 @@ private ParseGraph startCycle(final int offset) { final ParseState parseState = stream(0, 4, 1, 21, 0, 0, 1).seek(BigInteger.valueOf(offset)).get(); final Optional result = LINKED_LIST.parse(env(parseState, enc())); assertTrue(result.isPresent()); - assertEquals(1, getReferences(result.get().order).size); + ImmutableList> optionals = getReferences(result.get().order); + assertEquals(1, (long) optionals.size()); return result.get().order; } diff --git a/core/src/test/java/io/parsingdata/metal/ToStringTest.java b/core/src/test/java/io/parsingdata/metal/ToStringTest.java index 69e478dc..8d6a20c6 100644 --- a/core/src/test/java/io/parsingdata/metal/ToStringTest.java +++ b/core/src/test/java/io/parsingdata/metal/ToStringTest.java @@ -191,12 +191,12 @@ public void data() { final String pv1String = "pval(name:0x0102)"; final Optional ov1 = Optional.of(pv1); final Optional ov2 = Optional.of(new CoreValue(createFromBytes(new byte[]{3}), enc())); - assertEquals(">Optional[0x03]>Optional[" + pv1String + "]", ImmutableList.create(ov1).add(ov2).toString()); + assertEquals(">Optional[0x03]>Optional[" + pv1String + "]", ImmutableList.create(ov1).addHead(ov2).toString()); final ParseValue pv2 = new ParseValue("two", NONE, createFromBytes(new byte[]{3, 4}), enc()); final String pv2String = "pval(two:0x0304)"; - assertEquals(">" + pv2String + ">" + pv1String, ImmutableList.create(pv1).add(pv2).toString()); - assertEquals(">" + pv2String + ">" + pv1String, ImmutableList.create(pv1).add(pv2).toString()); + assertEquals(">" + pv2String + ">" + pv1String, ImmutableList.create(pv1).addHead(pv2).toString()); + assertEquals(">" + pv2String + ">" + pv1String, ImmutableList.create(pv1).addHead(pv2).toString()); } @Test diff --git a/core/src/test/java/io/parsingdata/metal/TreeTest.java b/core/src/test/java/io/parsingdata/metal/TreeTest.java index 215bd54c..b0684320 100644 --- a/core/src/test/java/io/parsingdata/metal/TreeTest.java +++ b/core/src/test/java/io/parsingdata/metal/TreeTest.java @@ -150,11 +150,11 @@ private boolean contains(final ImmutableList nrs, final int i) { if (nrs.isEmpty()) { return false; } - if (nrs.head.asNumeric().intValueExact() == i) { + if (nrs.head().asNumeric().intValueExact() == i) { return true; } - if (nrs.tail != null) { - return contains(nrs.tail, i); + if (nrs.tail() != null) { + return contains(nrs.tail(), i); } return false; } diff --git a/core/src/test/java/io/parsingdata/metal/UtilInflateTest.java b/core/src/test/java/io/parsingdata/metal/UtilInflateTest.java index 212dc7c5..ba2d9af3 100644 --- a/core/src/test/java/io/parsingdata/metal/UtilInflateTest.java +++ b/core/src/test/java/io/parsingdata/metal/UtilInflateTest.java @@ -34,8 +34,8 @@ public class UtilInflateTest { @Test public void inflateDataFormatError() { final ImmutableList result = inflate(con(0xff)).eval(stream(), enc()); - assertEquals(1, result.size); - assertEquals(NOT_A_VALUE, result.head); + assertEquals(1, (long) result.size()); + assertEquals(NOT_A_VALUE, result.head()); } } diff --git a/core/src/test/java/io/parsingdata/metal/data/ConcatenatedValueSourceTest.java b/core/src/test/java/io/parsingdata/metal/data/ConcatenatedValueSourceTest.java index 6f80daaf..e351525d 100644 --- a/core/src/test/java/io/parsingdata/metal/data/ConcatenatedValueSourceTest.java +++ b/core/src/test/java/io/parsingdata/metal/data/ConcatenatedValueSourceTest.java @@ -50,10 +50,10 @@ public static void setup() { final byte[] twoSliceSource = new byte[] { -1, -1, 5, 6, 7, 8, 9, -1, -1, 10, 11, 12, 13, 14, -1, -1 }; final ImmutableList list = ImmutableList .create(createFromBytes(new byte[]{0, 1, 2, 3, 4}, enc())) - .add(new CoreValue(createFromSource(new ConstantSource(twoSliceSource), BigInteger.valueOf(2), BigInteger.valueOf(5)).get(), enc())) - .add(new CoreValue(createFromSource(new ConstantSource(twoSliceSource), BigInteger.valueOf(9), BigInteger.valueOf(5)).get(), enc())) - .add(createFromBytes(new byte[]{15, 16, 17, 18, 19}, enc())) - .add(createFromBytes(new byte[]{20, 21, 22, 23, 24}, enc())); + .addHead(new CoreValue(createFromSource(new ConstantSource(twoSliceSource), BigInteger.valueOf(2), BigInteger.valueOf(5)).get(), enc())) + .addHead(new CoreValue(createFromSource(new ConstantSource(twoSliceSource), BigInteger.valueOf(9), BigInteger.valueOf(5)).get(), enc())) + .addHead(createFromBytes(new byte[]{15, 16, 17, 18, 19}, enc())) + .addHead(createFromBytes(new byte[]{20, 21, 22, 23, 24}, enc())); cvs = ConcatenatedValueSource.create(list).orElseThrow(); } @@ -110,7 +110,7 @@ public void concatenatedValueSourceRead() { int parts = 4; ImmutableList values = new ImmutableList<>(); for (int part = 0; part < parts; part++) { - values = values.add(new CoreValue(Slice.createFromBytes(Arrays.copyOfRange(bytes, (arraySize / parts) * part, (arraySize / parts) * (part + 1))), Encoding.DEFAULT_ENCODING)); + values = values.addHead(new CoreValue(Slice.createFromBytes(Arrays.copyOfRange(bytes, (arraySize / parts) * part, (arraySize / parts) * (part + 1))), Encoding.DEFAULT_ENCODING)); } // Create a ConcatenatedValueSource to read from. diff --git a/core/src/test/java/io/parsingdata/metal/data/ParseValueCacheTest.java b/core/src/test/java/io/parsingdata/metal/data/ParseValueCacheTest.java index 629185d3..09bddbff 100644 --- a/core/src/test/java/io/parsingdata/metal/data/ParseValueCacheTest.java +++ b/core/src/test/java/io/parsingdata/metal/data/ParseValueCacheTest.java @@ -73,12 +73,12 @@ public void findTest(final String scopeName, final List values) { final Optional> nameValues = parseValueCache.find(scopeName, NO_LIMIT); assertTrue(nameValues.isPresent()); nameValues.ifPresent(result -> { - assertEquals(values.size(), result.size); + assertEquals(values.size(), (long) result.size()); ImmutableList tail = result; for (int i = 0; i < values.size(); i++) { assertNotNull(tail); - assertEquals(values.get(i), tail.head); - tail = tail.tail; + assertEquals(values.get(i), tail.head()); + tail = tail.tail(); } }); } @@ -89,10 +89,10 @@ public void limitTest(final int limit) { final Optional> nameValues = parseValueCache.find("name", limit); assertTrue(nameValues.isPresent()); nameValues.ifPresent(result -> { - assertEquals(Math.min(limit, 3), result.size); - if (limit > 0) assertEquals(pv3, result.head); - if (limit > 1) assertEquals(pv2, result.tail.head); - if (limit > 2) assertEquals(pv1, result.tail.tail.head); + assertEquals(Math.min(limit, 3), (long) result.size()); + if (limit > 0) assertEquals(pv3, result.head()); + if (limit > 1) assertEquals(pv2, result.tail().head()); + if (limit > 2) assertEquals(pv1, result.tail().tail().head()); }); } @@ -122,13 +122,13 @@ public void addTest() { final Optional> nameValues = parseValueCache.find("name", NO_LIMIT); assertTrue(nameValues.isPresent()); - nameValues.ifPresent(result -> assertEquals(0, result.size)); + nameValues.ifPresent(result -> assertEquals(0, (long) result.size())); final Optional> nameValues2 = parseValueCache2.find("name", NO_LIMIT); assertTrue(nameValues2.isPresent()); nameValues2.ifPresent(result -> { - assertEquals(1, result.size); - assertEquals(pv, result.head); + assertEquals(1, (long) result.size()); + assertEquals(pv, result.head()); }); } diff --git a/core/src/test/java/io/parsingdata/metal/data/SelectionTest.java b/core/src/test/java/io/parsingdata/metal/data/SelectionTest.java index cf6b61d3..1c68b883 100644 --- a/core/src/test/java/io/parsingdata/metal/data/SelectionTest.java +++ b/core/src/test/java/io/parsingdata/metal/data/SelectionTest.java @@ -58,8 +58,8 @@ public void findItemAtOffsetTest() { .add(new ParseValue("the_one", any("a"), Slice.createFromSource(source, ONE, BigInteger.valueOf(2)).get(), enc()))), ZERO, source).computeResult().get().asGraph().head.asValue().name); assertEquals("zero", findItemAtOffset(ImmutableList.create(new ParseValue("zero", any("a"), Slice.createFromSource(source, ZERO, BigInteger.valueOf(2)).get(), enc())) - .add(new ParseValue("offsetMatchOtherSource", any("a"), Slice.createFromSource(otherSource, ZERO, BigInteger.valueOf(2)).get(), enc())) - .add(new ParseValue("otherOffsetMatchSource", any("a"), Slice.createFromSource(source, ONE, BigInteger.valueOf(2)).get(), enc())), ZERO, source).computeResult().get().asValue().name); + .addHead(new ParseValue("offsetMatchOtherSource", any("a"), Slice.createFromSource(otherSource, ZERO, BigInteger.valueOf(2)).get(), enc())) + .addHead(new ParseValue("otherOffsetMatchSource", any("a"), Slice.createFromSource(source, ONE, BigInteger.valueOf(2)).get(), enc())), ZERO, source).computeResult().get().asValue().name); } @Test @@ -67,7 +67,8 @@ public void limit() { Optional parseState = rep(any("a")).parse(env(stream(1, 2, 3, 4, 5))); assertTrue(parseState.isPresent()); for (int i = 0; i < 7; i++) { - assertEquals(Math.min(5, i), getAllValues(parseState.get().order, (value) -> value.matches("a"), i).size); + ImmutableList parseValues = getAllValues(parseState.get().order, (value) -> value.matches("a"), i); + assertEquals(Math.min(5, i), (long) parseValues.size()); } } diff --git a/core/src/test/java/io/parsingdata/metal/data/SourceAndSliceTest.java b/core/src/test/java/io/parsingdata/metal/data/SourceAndSliceTest.java index 91834008..fbaa96bf 100644 --- a/core/src/test/java/io/parsingdata/metal/data/SourceAndSliceTest.java +++ b/core/src/test/java/io/parsingdata/metal/data/SourceAndSliceTest.java @@ -48,7 +48,7 @@ public static Collection data() { { new ConstantSource(DATA) }, { new DataExpressionSource(con(DATA), 0, EMPTY_PARSE_STATE, enc()) }, { new ByteStreamSource(new InMemoryByteStream(DATA)) }, - { ConcatenatedValueSource.create(ImmutableList.create(new CoreValue(createFromSource(new ConstantSource(DATA), ZERO, BigInteger.valueOf(2)).get(), enc())).add(new CoreValue(createFromSource(new ConstantSource(DATA), BigInteger.valueOf(2), BigInteger.valueOf(2)).get(), enc()))).get() } + { ConcatenatedValueSource.create(ImmutableList.create(new CoreValue(createFromSource(new ConstantSource(DATA), ZERO, BigInteger.valueOf(2)).get(), enc())).addHead(new CoreValue(createFromSource(new ConstantSource(DATA), BigInteger.valueOf(2), BigInteger.valueOf(2)).get(), enc()))).get() } }); } diff --git a/core/src/test/java/io/parsingdata/metal/data/callback/CallbackTest.java b/core/src/test/java/io/parsingdata/metal/data/callback/CallbackTest.java index 24618a20..f10e7458 100644 --- a/core/src/test/java/io/parsingdata/metal/data/callback/CallbackTest.java +++ b/core/src/test/java/io/parsingdata/metal/data/callback/CallbackTest.java @@ -93,7 +93,7 @@ private Callbacks createCallbackList(Token token, final long... offsets) { @Override public void handleSuccess(Token token, ParseState before, ParseState after) { final ImmutableList roots = getAllRoots(after.order, token); - assertEquals(offsets[count++], roots.head.asGraph().tail.head.asValue().slice().offset.longValueExact()); + assertEquals(offsets[count++], roots.head().asGraph().tail.head.asValue().slice().offset.longValueExact()); } @Override @@ -123,15 +123,15 @@ public void seqAndRepCallbacks() { @Override public void handleSuccess(Token token, ParseState before, ParseState after) { final ImmutableList repRoots = getAllRoots(after.order, token); - assertEquals(1, repRoots.size); + assertEquals(1, (long) repRoots.size()); // verify that two Seq tokens were parsed: final ImmutableList seqRoots = getAllRoots(after.order, SIMPLE_SEQ); - assertEquals(2, seqRoots.size); + assertEquals(2, (long) seqRoots.size()); // verify order of the two Seq graphs: - assertEquals(2, getValue(seqRoots.head.asGraph(), "a").slice().offset.intValueExact()); - assertEquals(0, getValue(seqRoots.tail.head.asGraph(), "a").slice().offset.intValueExact()); + assertEquals(2, getValue(seqRoots.head().asGraph(), "a").slice().offset.intValueExact()); + assertEquals(0, getValue(seqRoots.tail().head().asGraph(), "a").slice().offset.intValueExact()); } @Override diff --git a/core/src/test/java/io/parsingdata/metal/data/selection/ByName.java b/core/src/test/java/io/parsingdata/metal/data/selection/ByName.java index e6a73f8a..bda12058 100644 --- a/core/src/test/java/io/parsingdata/metal/data/selection/ByName.java +++ b/core/src/test/java/io/parsingdata/metal/data/selection/ByName.java @@ -34,7 +34,7 @@ private ByName() {} * @return The first value (bottom-up) with the provided name in the provided graph */ public static ParseValue getValue(final ParseGraph graph, final String name) { - return Selection.getAllValues(graph, (value) -> value.matches(name), 1).head; + return Selection.getAllValues(graph, (value) -> value.matches(name), 1).head(); } /** @@ -52,11 +52,11 @@ public static ParseValue get(final ImmutableList list, final String if (list.isEmpty()) { return null; } - if (list.head.matches(name)) { - return list.head; + if (list.head().matches(name)) { + return list.head(); } else { - return get(list.tail, name); + return get(list.tail(), name); } } @@ -64,9 +64,9 @@ public static ImmutableList getAll(final ImmutableList l if (list.isEmpty()) { return list; } - final ImmutableList tailList = getAll(list.tail, name); - if (list.head.matches(name)) { - return tailList.add(list.head); + final ImmutableList tailList = getAll(list.tail(), name); + if (list.head().matches(name)) { + return tailList.addHead(list.head()); } else { return tailList; } diff --git a/core/src/test/java/io/parsingdata/metal/data/selection/ByToken.java b/core/src/test/java/io/parsingdata/metal/data/selection/ByToken.java index 91c1f670..64b1fde1 100644 --- a/core/src/test/java/io/parsingdata/metal/data/selection/ByToken.java +++ b/core/src/test/java/io/parsingdata/metal/data/selection/ByToken.java @@ -60,16 +60,16 @@ private static ImmutableList getAllRecursive(final ParseGraph graph, return new ImmutableList<>(); } final ImmutableList tailResults = getAllRecursive(graph.tail, definition); - final ImmutableList results = graph.definition.equals(definition) ? tailResults.add(graph) : tailResults; + final ImmutableList results = graph.definition.equals(definition) ? tailResults.addHead(graph) : tailResults; final ParseItem head = graph.head; if (head.isValue() && head.asValue().definition.equals(definition)) { - return results.add(head); + return results.addHead(head); } if (head.isReference() && head.asReference().definition.equals(definition)) { - return results.add(head); + return results.addHead(head); } if (head.isGraph()) { - return results.add(getAllRecursive(head.asGraph(), definition)); + return results.addList(getAllRecursive(head.asGraph(), definition)); } return results; } diff --git a/core/src/test/java/io/parsingdata/metal/data/selection/ByTokenTest.java b/core/src/test/java/io/parsingdata/metal/data/selection/ByTokenTest.java index 0186aa4b..bdc31139 100644 --- a/core/src/test/java/io/parsingdata/metal/data/selection/ByTokenTest.java +++ b/core/src/test/java/io/parsingdata/metal/data/selection/ByTokenTest.java @@ -132,7 +132,7 @@ public void getAllUnusedToken() { final ParseGraph graph = parseResultGraph(stream(0), SEQ_REP); final ImmutableList items = getAll(graph, UNUSED_DEF); - assertThat(items.size, is(equalTo(0L))); + assertThat((long) items.size(), is(equalTo(0L))); } @Test @@ -140,7 +140,7 @@ public void getAllNonePresent() { final ParseGraph graph = parseResultGraph(stream(0), SEQ_REP); final ImmutableList items = getAll(graph, DEF2); - assertThat(items.size, is(equalTo(0L))); + assertThat((long) items.size(), is(equalTo(0L))); } @Test @@ -148,8 +148,8 @@ public void getAllSingleDef() { final ParseGraph graph = parseResultGraph(stream(0, 1, 2, 3, 4, 5), SEQ_REP); final ImmutableList items = getAll(graph, DEF1); - assertThat(items.size, is(equalTo(1L))); - assertThat(items.head.getDefinition(), is(equalTo(DEF1))); + assertThat((long) items.size(), is(equalTo(1L))); + assertThat(items.head().getDefinition(), is(equalTo(DEF1))); } @Test @@ -157,8 +157,8 @@ public void getAllRepDef() { final ParseGraph graph = parseResultGraph(stream(0, 1, 2, 3, 4, 5), SEQ_REP); final ImmutableList items = getAll(graph, DEF2); - assertThat(items.size, is(equalTo(5L))); - assertThat(items.head.getDefinition(), is(equalTo(DEF2))); + assertThat((long) items.size(), is(equalTo(5L))); + assertThat(items.head().getDefinition(), is(equalTo(DEF2))); } @Test @@ -167,14 +167,14 @@ public void getAllRepSeq() { final ImmutableList def1Items = getAll(graph, DEF1); final ImmutableList def2Items = getAll(graph, DEF2); - assertThat(def1Items.size, is(equalTo(3L))); - assertThat(def2Items.size, is(equalTo(3L))); + assertThat((long) def1Items.size(), is(equalTo(3L))); + assertThat((long) def2Items.size(), is(equalTo(3L))); - assertThat(def1Items.head.getDefinition(), is(equalTo(DEF1))); - assertThat(def2Items.head.getDefinition(), is(equalTo(DEF2))); + assertThat(def1Items.head().getDefinition(), is(equalTo(DEF1))); + assertThat(def2Items.head().getDefinition(), is(equalTo(DEF2))); - assertThat(def1Items.tail.head.asValue().asNumeric().intValueExact(), is(equalTo(2))); - assertThat(def2Items.tail.head.asValue().asNumeric().intValueExact(), is(equalTo(3))); + assertThat(def1Items.tail().head().asValue().asNumeric().intValueExact(), is(equalTo(2))); + assertThat(def2Items.tail().head().asValue().asNumeric().intValueExact(), is(equalTo(3))); } @Test @@ -182,9 +182,9 @@ public void getAllSub() { final ParseGraph graph = parseResultGraph(stream(4, 2, 2, 3, 4, 5), SEQ_SUB); final ImmutableList items = getAll(graph, TWO_BYTES); - assertThat(items.size, is(equalTo(2L))); - assertThat(items.head.getDefinition(), is(equalTo(TWO_BYTES))); - assertThat(items.head.asValue().value(), is(equalTo(new byte[]{2, 3}))); + assertThat((long) items.size(), is(equalTo(2L))); + assertThat(items.head().getDefinition(), is(equalTo(TWO_BYTES))); + assertThat(items.head().asValue().value(), is(equalTo(new byte[]{2, 3}))); } @Test @@ -192,16 +192,16 @@ public void getAllMutualRecursive() { final ParseGraph graph = parseResultGraph(stream(0, 1, 2, 3, 4, 5), MUT_REC_1); final ImmutableList repItems = getAll(graph, REPN_DEF2); - assertThat(repItems.size, is(equalTo(4L))); + assertThat((long) repItems.size(), is(equalTo(4L))); final ImmutableList repRootItems = getAllRoots(graph, REPN_DEF2); - assertThat(repRootItems.size, is(equalTo(2L))); + assertThat((long) repRootItems.size(), is(equalTo(2L))); final ImmutableList recursiveItems = getAll(graph, MUT_REC_1); - assertThat(recursiveItems.size, is(equalTo(4L))); + assertThat((long) recursiveItems.size(), is(equalTo(4L))); final ImmutableList recursiveRootItems = getAllRoots(graph, MUT_REC_1); - assertThat(recursiveRootItems.size, is(equalTo(2L))); + assertThat((long) recursiveRootItems.size(), is(equalTo(2L))); } @Test @@ -211,11 +211,11 @@ public void compareGetAllNameWithGetAllToken() { ImmutableList values = getAllValues(graph, "value2"); ImmutableList items = getAll(graph, DEF2); - while (values.head != null) { - assertThat(values.head, is(equalTo(items.head.asValue()))); + while (values.head() != null) { + assertThat(values.head(), is(equalTo(items.head().asValue()))); - values = values.tail; - items = items.tail; + values = values.tail(); + items = items.tail(); } } @@ -232,9 +232,9 @@ public void getSubRef() { assertTrue(result.isPresent()); final ImmutableList items = getAll(result.get().order, DEF2); // should return two values created by the Sub, no ParseReference because a Def cannot create a cycle - assertEquals(2, items.size); - assertTrue(items.head.isValue()); - assertTrue(items.tail.head.isValue()); + assertEquals(2, (long) items.size()); + assertTrue(items.head().isValue()); + assertTrue(items.tail().head().isValue()); } @Test @@ -243,9 +243,9 @@ public void getAllRootsSingle() { final Optional result = topSeq.parse(env(stream(1, 2, 3))); assertTrue(result.isPresent()); final ImmutableList seqItems = getAllRoots(result.get().order, SMALL_SEQ); - assertEquals(1, seqItems.size); - assertEquals(SMALL_SEQ, seqItems.head.getDefinition()); - final ParseValue c = seqItems.head.asGraph().head.asValue(); + assertEquals(1, (long) seqItems.size()); + assertEquals(SMALL_SEQ, seqItems.head().getDefinition()); + final ParseValue c = seqItems.head().asGraph().head.asValue(); assertEquals(3, c.asNumeric().intValueExact()); assertEquals(2, c.slice().offset.intValueExact()); } @@ -256,20 +256,20 @@ public void getAllRootsMulti() { final Optional result = topSeq.parse(env(stream(1, 2, 3, 2, 3))); assertTrue(result.isPresent()); final ImmutableList seqItems = getAllRoots(result.get().order, SMALL_SEQ); - assertEquals(2, seqItems.size); - assertEquals(SMALL_SEQ, seqItems.head.getDefinition()); - assertEquals(SMALL_SEQ, seqItems.tail.head.getDefinition()); - final ParseValue c1 = seqItems.head.asGraph().head.asValue(); + assertEquals(2, (long) seqItems.size()); + assertEquals(SMALL_SEQ, seqItems.head().getDefinition()); + assertEquals(SMALL_SEQ, seqItems.tail().head().getDefinition()); + final ParseValue c1 = seqItems.head().asGraph().head.asValue(); assertEquals(3, c1.asNumeric().intValueExact()); - final ParseValue c2 = seqItems.tail.head.asGraph().head.asValue(); + final ParseValue c2 = seqItems.tail().head().asGraph().head.asValue(); assertEquals(3, c2.asNumeric().intValueExact()); - assertNotEquals(seqItems.head.asGraph().head, seqItems.tail.head.asGraph().head); + assertNotEquals(seqItems.head().asGraph().head, seqItems.tail().head().asGraph().head); } private Set makeSet(final ImmutableList seqs) { final Set items = new HashSet<>(); - for (ImmutableList current = seqs; current != null && !current.isEmpty(); current = current.tail) { - items.add(current.head); + for (ImmutableList current = seqs; current != null && !current.isEmpty(); current = current.tail()) { + items.add(current.head()); } return items; } @@ -282,7 +282,7 @@ public void getAllRootsMultiSub() { /* 3: +--------+ */ assertTrue(result.isPresent()); final ImmutableList seqItems = getAllRoots(result.get().order, SMALL_SEQ); - assertEquals(6, seqItems.size); // Three regular and three subs. + assertEquals(6, (long) seqItems.size()); // Three regular and three subs. final Set items = makeSet(seqItems); assertEquals(4, items.size()); // Check that there are two duplicates. for (final ParseItem item : items) { @@ -313,50 +313,52 @@ public void getAllRootsMultiSelf() { final Optional result = customToken.parse(env(stream(1, 2, 3))); assertTrue(result.isPresent()); final ImmutableList seqItems = getAllRoots(result.get().order, customToken.token); - assertEquals(3, seqItems.size); + assertEquals(3, (long) seqItems.size()); final Set items = makeSet(seqItems); - assertEquals(seqItems.size, items.size()); // Check that there are no duplicate results. + assertEquals((long) seqItems.size(), items.size()); // Check that there are no duplicate results. } @Test public void getAllRootsEmpty() { - assertEquals(0, getAllRoots(ParseGraph.EMPTY, any("a")).size); - assertEquals(1, getAllRoots(ParseGraph.EMPTY, ParseGraph.NONE).size); + ImmutableList parseItems1 = getAllRoots(ParseGraph.EMPTY, any("a")); + assertEquals(0, (long) parseItems1.size()); + ImmutableList parseItems = getAllRoots(ParseGraph.EMPTY, ParseGraph.NONE); + assertEquals(1, (long) parseItems.size()); } @Test public void getAllRootsOrderRepDef() { final ParseGraph graph = parseResultGraph(stream(0, 1, 2), rep(DEF1)); final ImmutableList items = getAllRoots(graph, DEF1); - assertThat(items.size, is(equalTo(3L))); - assertThat(items.head.asValue().asNumeric().intValueExact(), is(equalTo(2))); - assertThat(items.tail.head.asValue().asNumeric().intValueExact(), is(equalTo(1))); - assertThat(items.tail.tail.head.asValue().asNumeric().intValueExact(), is(equalTo(0))); + assertThat((long) items.size(), is(equalTo(3L))); + assertThat(items.head().asValue().asNumeric().intValueExact(), is(equalTo(2))); + assertThat(items.tail().head().asValue().asNumeric().intValueExact(), is(equalTo(1))); + assertThat(items.tail().tail().head().asValue().asNumeric().intValueExact(), is(equalTo(0))); } @Test public void getAllRootsOrderSeqSub() { final ParseGraph graph = parseResultGraph(stream(4, 2, 2, 3, 4, 5), SEQ_SUB); final ImmutableList items = getAllRoots(graph, TWO_BYTES); - assertThat(items.size, is(equalTo(2L))); - assertThat(items.head.asValue().asNumeric().intValueExact(), is(equalTo(0x0203))); - assertThat(items.tail.head.asValue().asNumeric().intValueExact(), is(equalTo(0x0405))); + assertThat((long) items.size(), is(equalTo(2L))); + assertThat(items.head().asValue().asNumeric().intValueExact(), is(equalTo(0x0203))); + assertThat(items.tail().head().asValue().asNumeric().intValueExact(), is(equalTo(0x0405))); } @Test public void getAllRootsOrderMutualRecursive() { final ParseGraph graph = parseResultGraph(stream(0, 1, 2, 3, 4, 5), MUT_REC_1); final ImmutableList items = getAllRoots(graph, MUT_REC_1); - assertThat(items.size, is(equalTo(2L))); + assertThat((long) items.size(), is(equalTo(2L))); // item.head is the MUT_REC_1 graph containing [3, 4, 5], with '3' having the DEF1 definition - final ImmutableList firstMutRecValues = getAll(items.head.asGraph(), DEF1); - assertThat(firstMutRecValues.size, is(equalTo(1L))); + final ImmutableList firstMutRecValues = getAll(items.head().asGraph(), DEF1); + assertThat((long) firstMutRecValues.size(), is(equalTo(1L))); assertThat(lastItem(firstMutRecValues).asValue().asNumeric().intValueExact(), is(equalTo(3))); // item.tail.head is the MUT_REC_1 graph containing [0, 1, 2, 3, 4, 5], with '0' and '3' having the DEF1 definition - final ImmutableList secondMutRecValues = getAll(items.tail.head.asGraph(), DEF1); - assertThat(secondMutRecValues.size, is(equalTo(2L))); + final ImmutableList secondMutRecValues = getAll(items.tail().head().asGraph(), DEF1); + assertThat((long) secondMutRecValues.size(), is(equalTo(2L))); assertThat(lastItem(secondMutRecValues).asValue().asNumeric().intValueExact(), is(equalTo(0))); } @@ -364,17 +366,17 @@ public void getAllRootsOrderMutualRecursive() { public void getAllRootsSelfRecursive() { final ParseGraph graph = parseResultGraph(stream(0xA, 3, 0xB, 2, 0xC, 0, 0xD, 0, 0xE, 0, 0xF, 0), SELF_REC); ImmutableList items = getAllRoots(graph, SELF_REC); - assertThat(items.size, is(equalTo(6L))); + assertThat((long) items.size(), is(equalTo(6L))); for (int value = 0xF; value >= 0xA; value--) { - final ImmutableList values = getAll(items.head.asGraph(), DEF1); + final ImmutableList values = getAll(items.head().asGraph(), DEF1); assertThat(lastItem(values).asValue().asNumeric().intValueExact(), is(equalTo(value))); - items = items.tail; + items = items.tail(); } } private static T lastItem(final ImmutableList items) { - return Selection.reverse(items).head; + return Selection.reverse(items).head(); } } diff --git a/core/src/test/java/io/parsingdata/metal/data/selection/ByType.java b/core/src/test/java/io/parsingdata/metal/data/selection/ByType.java index 7bd5323a..240bef01 100644 --- a/core/src/test/java/io/parsingdata/metal/data/selection/ByType.java +++ b/core/src/test/java/io/parsingdata/metal/data/selection/ByType.java @@ -39,7 +39,7 @@ private static ImmutableList> getReferences(final ParseGraph } final ParseItem head = graph.head; if (head.isReference() && head.asReference().resolve(root).isEmpty()) { throw new IllegalStateException("A ParseReference must point to an existing graph."); } - return getReferences(graph.tail, root).add(head.isGraph() ? getReferences(head.asGraph(), root) : (head.isReference() ? ImmutableList.create(head.asReference().resolve(root)) : new ImmutableList<>())); + return getReferences(graph.tail, root).addList(head.isGraph() ? getReferences(head.asGraph(), root) : (head.isReference() ? ImmutableList.create(head.asReference().resolve(root)) : new ImmutableList<>())); } } diff --git a/core/src/test/java/io/parsingdata/metal/expression/value/BytesTest.java b/core/src/test/java/io/parsingdata/metal/expression/value/BytesTest.java index 8cdce173..5c2cf47a 100644 --- a/core/src/test/java/io/parsingdata/metal/expression/value/BytesTest.java +++ b/core/src/test/java/io/parsingdata/metal/expression/value/BytesTest.java @@ -50,7 +50,7 @@ public void bytesEmpty() { @Test public void bytesListContainsOnlyEmpty() { final ImmutableList result = bytes(div(con(1), con(0))).eval(EMPTY_PARSE_STATE, enc()); - assertEquals(0, result.size); + assertEquals(0, (long) result.size()); } @Test @@ -64,11 +64,11 @@ public void bytesListContainsEmpty() { def("divider", con(1))).parse(env(stream(1, 0, 127, 127, 127, 0, 255, 0, 1))); assertTrue(result.isPresent()); final ImmutableList bytesAfterDivision = bytes(div(ref("value"), ref("divider"))).eval(result.get(), enc()); - assertEquals(3, bytesAfterDivision.size); // 1 of the first division, 0 of the second, 2 of the third - assertEquals(1, bytesAfterDivision.head.asNumeric().intValueExact()); // first value (0x0100) / first divider (0xFF) + assertEquals(3, (long) bytesAfterDivision.size()); // 1 of the first division, 0 of the second, 2 of the third + assertEquals(1, bytesAfterDivision.head().asNumeric().intValueExact()); // first value (0x0100) / first divider (0xFF) // second division result is missing because of division by zero - assertEquals(0, bytesAfterDivision.tail.head.asNumeric().intValueExact()); // third value (0x7F00) / third divider (0x01), right byte - assertEquals(127, bytesAfterDivision.tail.tail.head.asNumeric().intValueExact()); // left byte + assertEquals(0, bytesAfterDivision.tail().head().asNumeric().intValueExact()); // third value (0x7F00) / third divider (0x01), right byte + assertEquals(127, bytesAfterDivision.tail().tail().head().asNumeric().intValueExact()); // left byte } } diff --git a/core/src/test/java/io/parsingdata/metal/expression/value/ElvisExpressionTest.java b/core/src/test/java/io/parsingdata/metal/expression/value/ElvisExpressionTest.java index ee341a95..ecb6206e 100644 --- a/core/src/test/java/io/parsingdata/metal/expression/value/ElvisExpressionTest.java +++ b/core/src/test/java/io/parsingdata/metal/expression/value/ElvisExpressionTest.java @@ -60,8 +60,8 @@ public void elvisLeft() { // the building final ImmutableList eval = elvisExpression.eval(result.get(), enc()); assertNotNull(eval); - assertEquals(1, eval.size); - assertThat(eval.head.asNumeric().intValueExact(), is(equalTo(1))); + assertEquals(1, (long) eval.size()); + assertThat(eval.head().asNumeric().intValueExact(), is(equalTo(1))); } @Test @@ -70,8 +70,8 @@ public void elvisRight() { final ImmutableList eval = elvisExpression.eval(result.get(), enc()); assertNotNull(eval); - assertEquals(1, eval.size); - assertThat(eval.head.asNumeric().intValueExact(), is(equalTo(2))); + assertEquals(1, (long) eval.size()); + assertThat(eval.head().asNumeric().intValueExact(), is(equalTo(2))); } @Test @@ -88,9 +88,9 @@ public void elvisList() { assertTrue(result.isPresent()); final ValueExpression elvis = elvis(ref("a"), ref("b")); final ImmutableList eval = elvis.eval(result.get(), enc()); - assertEquals(2, eval.size); - assertEquals(2, eval.head.asNumeric().intValueExact()); - assertEquals(1, eval.tail.head.asNumeric().intValueExact()); + assertEquals(2, (long) eval.size()); + assertEquals(2, eval.head().asNumeric().intValueExact()); + assertEquals(1, eval.tail().head().asNumeric().intValueExact()); } @Test @@ -99,9 +99,9 @@ public void elvisListWithEmpty() { assertTrue(result.isPresent()); final ValueExpression elvis = elvis(ref("c"), ref("b")); final ImmutableList eval = elvis.eval(result.get(), enc()); - assertEquals(2, eval.size); - assertEquals(4, eval.head.asNumeric().intValueExact()); - assertEquals(3, eval.tail.head.asNumeric().intValueExact()); + assertEquals(2, (long) eval.size()); + assertEquals(4, eval.head().asNumeric().intValueExact()); + assertEquals(3, eval.tail().head().asNumeric().intValueExact()); } @Test @@ -110,18 +110,18 @@ public void elvisListDifferentLengths() { assertTrue(result.isPresent()); final ValueExpression elvis = elvis(ref("a"), ref("b")); final ImmutableList eval = elvis.eval(result.get(), enc()); - assertEquals(3, eval.size); - assertEquals(2, eval.head.asNumeric().intValueExact()); - assertEquals(1, eval.tail.head.asNumeric().intValueExact()); - assertEquals(3, eval.tail.tail.head.asNumeric().intValueExact()); + assertEquals(3, (long) eval.size()); + assertEquals(2, eval.head().asNumeric().intValueExact()); + assertEquals(1, eval.tail().head().asNumeric().intValueExact()); + assertEquals(3, eval.tail().tail().head().asNumeric().intValueExact()); } @Test public void elvisLeftNone() { final ValueExpression elvis = elvis(div(con(1), con(0)), con(1)); final ImmutableList eval = elvis.eval(stream(0), enc()); - assertEquals(1, eval.size); - assertEquals(1, eval.head.asNumeric().intValueExact()); + assertEquals(1, (long) eval.size()); + assertEquals(1, eval.head().asNumeric().intValueExact()); } @Test diff --git a/core/src/test/java/io/parsingdata/metal/expression/value/ExpandTest.java b/core/src/test/java/io/parsingdata/metal/expression/value/ExpandTest.java index 4c10638d..c4f0a2cb 100644 --- a/core/src/test/java/io/parsingdata/metal/expression/value/ExpandTest.java +++ b/core/src/test/java/io/parsingdata/metal/expression/value/ExpandTest.java @@ -73,22 +73,22 @@ public void expandZeroTimes() { @Test public void expandValue() { ImmutableList result = exp(con(VALUE_1), con(SIZE)).eval(EMPTY_PARSE_STATE, enc()); - assertEquals(SIZE, result.size); + assertEquals(SIZE, (long) result.size()); for (int i = 0; i < SIZE; i++) { - assertEquals(VALUE_1, result.head.asNumeric().intValueExact()); - result = result.tail; + assertEquals(VALUE_1, result.head().asNumeric().intValueExact()); + result = result.tail(); } } @Test public void expandList() { ImmutableList result = exp(ref("a"), con(SIZE)).eval(createFromByteStream(DUMMY_STREAM).add(PARSEVALUE_2).add(PARSEVALUE_1), enc()); - assertEquals(2 * SIZE, result.size); + assertEquals(2 * SIZE, (long) result.size()); for (int i = 0; i < SIZE; i++) { - assertEquals(VALUE_1, result.head.asNumeric().intValueExact()); - result = result.tail; - assertEquals(VALUE_2, result.head.asNumeric().intValueExact()); - result = result.tail; + assertEquals(VALUE_1, result.head().asNumeric().intValueExact()); + result = result.tail(); + assertEquals(VALUE_2, result.head().asNumeric().intValueExact()); + result = result.tail(); } } diff --git a/core/src/test/java/io/parsingdata/metal/expression/value/FoldCatTest.java b/core/src/test/java/io/parsingdata/metal/expression/value/FoldCatTest.java index ec26bb01..1bb2a9e6 100644 --- a/core/src/test/java/io/parsingdata/metal/expression/value/FoldCatTest.java +++ b/core/src/test/java/io/parsingdata/metal/expression/value/FoldCatTest.java @@ -43,8 +43,8 @@ public class FoldCatTest { @Test public void foldCatRegular() { final ImmutableList string = foldString("any"); - assertEquals(1, string.size); - assertEquals("abc", string.head.asString()); + assertEquals(1, (long) string.size()); + assertEquals("abc", string.head().asString()); } @Test diff --git a/core/src/test/java/io/parsingdata/metal/expression/value/FoldEdgeCaseTest.java b/core/src/test/java/io/parsingdata/metal/expression/value/FoldEdgeCaseTest.java index b5de88e9..805adeba 100644 --- a/core/src/test/java/io/parsingdata/metal/expression/value/FoldEdgeCaseTest.java +++ b/core/src/test/java/io/parsingdata/metal/expression/value/FoldEdgeCaseTest.java @@ -59,31 +59,31 @@ public class FoldEdgeCaseTest { @Test public void valuesContainsEmpty() { - assertEquals(NOT_A_VALUE, foldLeft(div(con(1), con(0)), Shorthand::add).eval(stream(0), enc()).head); - assertEquals(NOT_A_VALUE, foldRight(div(con(1), con(0)), Shorthand::add).eval(stream(0), enc()).head); + assertEquals(NOT_A_VALUE, foldLeft(div(con(1), con(0)), Shorthand::add).eval(stream(0), enc()).head()); + assertEquals(NOT_A_VALUE, foldRight(div(con(1), con(0)), Shorthand::add).eval(stream(0), enc()).head()); } @Test public void foldToEmpty() { final ParseState parseState = rep(any("value")).parse(env(stream(1, 0))).get(); final ImmutableList foldLeftNan = foldLeft(ref("value"), Shorthand::div).eval(parseState, enc()); - assertEquals(1, foldLeftNan.size); - assertEquals(NOT_A_VALUE, foldLeftNan.head); + assertEquals(1, (long) foldLeftNan.size()); + assertEquals(NOT_A_VALUE, foldLeftNan.head()); final ImmutableList foldRightNan = foldRight(ref("value"), Shorthand::div).eval(parseState, enc()); - assertEquals(1, foldRightNan.size); - assertEquals(NOT_A_VALUE, foldRightNan.head); + assertEquals(1, (long) foldRightNan.size()); + assertEquals(NOT_A_VALUE, foldRightNan.head()); } @Test public void inputContainsEmptyInTail() { - assertEquals(NOT_A_VALUE, foldRight((parseState, encoding) -> ImmutableList.create(NOT_A_VALUE).add(new CoreValue(createFromBytes(new byte[] { 1, 2 }), enc())), Shorthand::add).eval(stream(0), enc()).head); + assertEquals(NOT_A_VALUE, foldRight((parseState, encoding) -> ImmutableList.create(NOT_A_VALUE).addHead(new CoreValue(createFromBytes(new byte[]{1, 2}), enc())), Shorthand::add).eval(stream(0), enc()).head()); } @Test public void notAValueInit() { final ImmutableList result = fold(exp(con(1), con(2)), Shorthand::add, con(NOT_A_VALUE)).eval(EMPTY_PARSE_STATE, DEFAULT_ENCODING); - assertEquals(1, result.size); - assertEquals(NOT_A_VALUE, result.head); + assertEquals(1, (long) result.size()); + assertEquals(NOT_A_VALUE, result.head()); } @Test diff --git a/core/src/test/java/io/parsingdata/metal/expression/value/JoinTest.java b/core/src/test/java/io/parsingdata/metal/expression/value/JoinTest.java index dcf54505..480bbb45 100644 --- a/core/src/test/java/io/parsingdata/metal/expression/value/JoinTest.java +++ b/core/src/test/java/io/parsingdata/metal/expression/value/JoinTest.java @@ -96,7 +96,7 @@ public static Stream joinExpressions() { @MethodSource("joinExpressions") public void joinWithParseState(final ValueExpression expression, final int[] expected) { ImmutableList result = expression.eval(PARSE_STATE, enc()); - assertEquals(expected.length, result.size); + assertEquals(expected.length, (long) result.size()); assertResult(expected, result); } @@ -104,12 +104,12 @@ private static void assertResult(final int[] expected, final ImmutableList result = actual; for (final int value : expected) { if (value == -1) { - assertEquals(NOT_A_VALUE, result.head); + assertEquals(NOT_A_VALUE, result.head()); } else { - assertEquals(value, result.head.asNumeric().intValueExact()); + assertEquals(value, result.head().asNumeric().intValueExact()); } - result = result.tail; + result = result.tail(); } } diff --git a/core/src/test/java/io/parsingdata/metal/expression/value/NthExpressionTest.java b/core/src/test/java/io/parsingdata/metal/expression/value/NthExpressionTest.java index bde21734..2a522349 100644 --- a/core/src/test/java/io/parsingdata/metal/expression/value/NthExpressionTest.java +++ b/core/src/test/java/io/parsingdata/metal/expression/value/NthExpressionTest.java @@ -67,80 +67,80 @@ public void testNanIndex() { // 5 values = [1, 2, 3, 4, 5], 1 index = [Nan], result = [Nan] final Optional result = format.parse(env(stream(5, 1, 2, 3, 4, 5, 0))); final ImmutableList values = nth(ref("value"), div(con(0), con(0))).eval(result.get(), enc()); - assertEquals(1, values.size); - assertEquals(NOT_A_VALUE, values.head); + assertEquals(1, (long) values.size()); + assertEquals(NOT_A_VALUE, values.head()); } @Test public void testEmptyValuesSingleIndex() { // 0 values = [], 1 index = [0], result = [Nan] final ImmutableList values = makeList(stream(0, 1, 0)); - assertEquals(1, values.size); - assertEquals(NOT_A_VALUE, values.head); + assertEquals(1, (long) values.size()); + assertEquals(NOT_A_VALUE, values.head()); } @Test public void testNonExistingValueAtIndex() { // 5 values = [1, 2, 3, 4, 5], 1 index = [42], result = [Nan] final ImmutableList values = makeList(stream(5, 1, 2, 3, 4, 5, 1, 42)); - assertEquals(1, values.size); - assertEquals(NOT_A_VALUE, values.head); + assertEquals(1, (long) values.size()); + assertEquals(NOT_A_VALUE, values.head()); } @Test public void testNegativeIndex() { // 5 values = [1, 2, 3, 4, 5], 1 index = [-1], result = [Nan] final ImmutableList values = makeList(stream(5, 1, 2, 3, 4, 5, 1, -1)); - assertEquals(1, values.size); - assertEquals(NOT_A_VALUE, values.head); + assertEquals(1, (long) values.size()); + assertEquals(NOT_A_VALUE, values.head()); } @Test public void testSingleIndex() { // 5 values = [1, 2, 3, 4, 5], 1 index = [0], result = [1] final ImmutableList values = makeList(stream(5, 1, 2, 3, 4, 5, 1, 0)); - assertEquals(1, values.size); - assertEquals(1, values.head.asNumeric().intValueExact()); + assertEquals(1, (long) values.size()); + assertEquals(1, values.head().asNumeric().intValueExact()); } @Test public void testMultipleIndices() { // 5 values = [1, 2, 3, 4, 5], 2 indices = [0, 2], result = [1, 3] final ImmutableList values = makeList(stream(5, 1, 2, 3, 4, 5, 2, 0, 2)); - assertEquals(2, values.size); - assertEquals(3, values.head.asNumeric().intValueExact()); - assertEquals(1, values.tail.head.asNumeric().intValueExact()); + assertEquals(2, (long) values.size()); + assertEquals(3, values.head().asNumeric().intValueExact()); + assertEquals(1, values.tail().head().asNumeric().intValueExact()); } @Test public void testMultipleIndicesMixedOrder() { // 5 values = [5, 6, 7, 8, 9], 4 indices = [3, 2, 0, 4], result = [8, 7, 5, 9] final ImmutableList values = makeList(stream(5, 5, 6, 7, 8, 9, 4, 3, 2, 0, 4)); - assertEquals(4, values.size); - assertEquals(9, values.head.asNumeric().intValueExact()); - assertEquals(5, values.tail.head.asNumeric().intValueExact()); - assertEquals(7, values.tail.tail.head.asNumeric().intValueExact()); - assertEquals(8, values.tail.tail.tail.head.asNumeric().intValueExact()); + assertEquals(4, (long) values.size()); + assertEquals(9, values.head().asNumeric().intValueExact()); + assertEquals(5, values.tail().head().asNumeric().intValueExact()); + assertEquals(7, values.tail().tail().head().asNumeric().intValueExact()); + assertEquals(8, values.tail().tail().tail().head().asNumeric().intValueExact()); } @Test public void testMixedExistingNonExistingIndices() { // 5 values = [1, 2, 3, 4, 5], 3 indices = [0, 42, 2], result = [1, Nan, 3] final ImmutableList values = makeList(stream(5, 1, 2, 3, 4, 5, 3, 0, 42, 2)); - assertEquals(3, values.size); - assertEquals(3, values.head.asNumeric().intValueExact()); - assertEquals(NOT_A_VALUE, values.tail.head); - assertEquals(1, values.tail.tail.head.asNumeric().intValueExact()); + assertEquals(3, (long) values.size()); + assertEquals(3, values.head().asNumeric().intValueExact()); + assertEquals(NOT_A_VALUE, values.tail().head()); + assertEquals(1, values.tail().tail().head().asNumeric().intValueExact()); } @Test public void testResultLengthEqualsIndicesLength() { // 1 value = [1], 5 indices = [1, 2, 3, 4, 5], result = [Nan, Nan, Nan, Nan, Nan] ImmutableList values = makeList(stream(1, 1, 5, 1, 2, 3, 4, 5)); - assertEquals(5, values.size); + assertEquals(5, (long) values.size()); while (!values.isEmpty()) { - assertEquals(NOT_A_VALUE, values.head); - values = values.tail; + assertEquals(NOT_A_VALUE, values.head()); + values = values.tail(); } } diff --git a/core/src/test/java/io/parsingdata/metal/expression/value/RefEdgeCaseTest.java b/core/src/test/java/io/parsingdata/metal/expression/value/RefEdgeCaseTest.java index b78ff7d3..4d7f7432 100644 --- a/core/src/test/java/io/parsingdata/metal/expression/value/RefEdgeCaseTest.java +++ b/core/src/test/java/io/parsingdata/metal/expression/value/RefEdgeCaseTest.java @@ -55,8 +55,8 @@ public void emptyLimit() { @Test public void nanLimit() { final ImmutableList result = ref(div(con(1), con(0)), "a").eval(parseState, enc()); - assertEquals(1, result.size); - assertEquals(NOT_A_VALUE, result.head); + assertEquals(1, (long) result.size()); + assertEquals(NOT_A_VALUE, result.head()); } } diff --git a/core/src/test/java/io/parsingdata/metal/expression/value/ScopeTest.java b/core/src/test/java/io/parsingdata/metal/expression/value/ScopeTest.java index 20e3715c..4df0b4a0 100644 --- a/core/src/test/java/io/parsingdata/metal/expression/value/ScopeTest.java +++ b/core/src/test/java/io/parsingdata/metal/expression/value/ScopeTest.java @@ -44,6 +44,7 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; +import io.parsingdata.metal.data.ImmutableList; import io.parsingdata.metal.data.ParseState; import io.parsingdata.metal.token.Token; @@ -98,13 +99,14 @@ public void parseGraphWithEmptyBranch() { EMPTY), tie("dx", def("dx_", con(1)), scope(ref("S.a.A.data.data"), con(0)))); final Optional result = S2.parse(env(stream(0, 0, 0, 0, 0), enc())); - assertEquals(5L, ref("dx_").eval(result.get(), enc()).size); + ImmutableList values = ref("dx_").eval(result.get(), enc()); + assertEquals(5L, (long) values.size()); } @Test public void parseGraphWithEmptyBranchSimplified() { final Optional result = def("a", first(scope(con(1), con(0)))).parse(env(stream(0))); - assertEquals(ZERO, ref("a").eval(result.get(), enc()).head.asNumeric()); + assertEquals(ZERO, ref("a").eval(result.get(), enc()).head().asNumeric()); } } diff --git a/core/src/test/java/io/parsingdata/metal/expression/value/ValueExpressionEvalEmptyTest.java b/core/src/test/java/io/parsingdata/metal/expression/value/ValueExpressionEvalEmptyTest.java index dbe33bfe..f5fcec71 100644 --- a/core/src/test/java/io/parsingdata/metal/expression/value/ValueExpressionEvalEmptyTest.java +++ b/core/src/test/java/io/parsingdata/metal/expression/value/ValueExpressionEvalEmptyTest.java @@ -49,8 +49,8 @@ public void moduloZero() { private void parse(final ValueExpression expression) { final ImmutableList result = expression.eval(stream(0), enc()); - assertEquals(1, result.size); - assertEquals(NOT_A_VALUE, result.head); + assertEquals(1, (long) result.size()); + assertEquals(NOT_A_VALUE, result.head()); } } diff --git a/core/src/test/java/io/parsingdata/metal/expression/value/reference/OffsetTest.java b/core/src/test/java/io/parsingdata/metal/expression/value/reference/OffsetTest.java index bd0728bd..df303df6 100644 --- a/core/src/test/java/io/parsingdata/metal/expression/value/reference/OffsetTest.java +++ b/core/src/test/java/io/parsingdata/metal/expression/value/reference/OffsetTest.java @@ -33,8 +33,8 @@ public class OffsetTest { @Test public void definedValueOffset() { final ImmutableList offsetCon = offset(con(1)).eval(stream(), enc()); - assertEquals(1, offsetCon.size); - assertEquals(0, offsetCon.head.asNumeric().intValueExact()); + assertEquals(1, (long) offsetCon.size()); + assertEquals(0, offsetCon.head().asNumeric().intValueExact()); } } diff --git a/core/src/test/java/io/parsingdata/metal/expression/value/reference/RefMultiReferencesTest.java b/core/src/test/java/io/parsingdata/metal/expression/value/reference/RefMultiReferencesTest.java index 5a0af98a..0f7d766e 100644 --- a/core/src/test/java/io/parsingdata/metal/expression/value/reference/RefMultiReferencesTest.java +++ b/core/src/test/java/io/parsingdata/metal/expression/value/reference/RefMultiReferencesTest.java @@ -100,13 +100,13 @@ public void multiDefinitionRef(final ValueExpression ref, final String expected) } private void assertLists(final String expected, final ImmutableList result) { - assertEquals(expected.length(), result.size); + assertEquals(expected.length(), (long) result.size()); ImmutableList tail = reverse(result); for (int i = 0; i < expected.length(); i++) { assertNotNull(tail); - assertNotNull(tail.head); - assertEquals(expected.charAt(i), tail.head.value()[0]); - tail = tail.tail; + assertNotNull(tail.head()); + assertEquals(expected.charAt(i), tail.head().value()[0]); + tail = tail.tail(); } } diff --git a/core/src/test/java/io/parsingdata/metal/expression/value/reference/RefToListTest.java b/core/src/test/java/io/parsingdata/metal/expression/value/reference/RefToListTest.java index b25e8834..e7a46e96 100644 --- a/core/src/test/java/io/parsingdata/metal/expression/value/reference/RefToListTest.java +++ b/core/src/test/java/io/parsingdata/metal/expression/value/reference/RefToListTest.java @@ -19,14 +19,14 @@ class RefToListTest { static Stream toListTest() { return Stream.of( arguments(ImmutableList.create(1), List.of(1)), - arguments(ImmutableList.create(1).add(2), List.of(2, 1)), - arguments(ImmutableList.create(1).add(2).add(3), List.of(3, 2, 1)), + arguments(ImmutableList.create(1).addHead(2), List.of(2, 1)), + arguments(ImmutableList.create(1).addHead(2).addHead(3), List.of(3, 2, 1)), arguments(ImmutableList.create(new Integer[]{1, 2, 3}), List.of(1, 2, 3)), arguments(ImmutableList.create(new Integer[0]), List.of()), arguments(ImmutableList.create("1"), List.of("1")), - arguments(ImmutableList.create("1").add("2"), List.of("2", "1")), - arguments(ImmutableList.create("1").add("2").add("3"), List.of("3", "2", "1")), + arguments(ImmutableList.create("1").addHead("2"), List.of("2", "1")), + arguments(ImmutableList.create("1").addHead("2").addHead("3"), List.of("3", "2", "1")), arguments(ImmutableList.create(new String[]{"1", "2", "3"}), List.of("1", "2", "3")), arguments(ImmutableList.create(new String[0]), List.of()) ); diff --git a/core/src/test/java/io/parsingdata/metal/token/DefTest.java b/core/src/test/java/io/parsingdata/metal/token/DefTest.java index 26eeff9a..4a534054 100644 --- a/core/src/test/java/io/parsingdata/metal/token/DefTest.java +++ b/core/src/test/java/io/parsingdata/metal/token/DefTest.java @@ -79,7 +79,7 @@ public void hugeSize() { final Environment environment = new Environment(state, enc()); final ParseState result = def.parse(environment).get(); - final ParseValue data = Selection.getAllValues(result.order, any -> true, 1).head; + final ParseValue data = Selection.getAllValues(result.order, any -> true, 1).head(); assertThat(data.slice().offset, is(equalTo(BigInteger.ONE))); assertThat(data.slice().length, is(equalTo(BigInteger.valueOf(Long.MAX_VALUE)))); diff --git a/core/src/test/java/io/parsingdata/metal/token/DefUntilTest.java b/core/src/test/java/io/parsingdata/metal/token/DefUntilTest.java index 5b2c3de2..2616bc0c 100644 --- a/core/src/test/java/io/parsingdata/metal/token/DefUntilTest.java +++ b/core/src/test/java/io/parsingdata/metal/token/DefUntilTest.java @@ -94,13 +94,13 @@ void repTest(final String name, final Token token, final int lineCount, final in assertTrue(parseState.isPresent()); ImmutableList values = getAllValues(parseState.get().order, "line"); - assertEquals(lineCount, values.size); - assertEquals(line1, values.tail.tail.head.asString()); - assertEquals(line2, values.tail.head.asString()); - assertEquals(line3, values.head.asString()); + assertEquals(lineCount, (long) values.size()); + assertEquals(line1, values.tail().tail().head().asString()); + assertEquals(line2, values.tail().head().asString()); + assertEquals(line3, values.head().asString()); ImmutableList newLines = getAllValues(parseState.get().order, "newline"); - assertEquals(newlineCount, newLines.size); + assertEquals(newlineCount, (long) newLines.size()); } static Collection shorthandTokenTest() { @@ -122,13 +122,13 @@ void shorthandTokenTest(final String name, final Token token) { assertTrue(parseState.isPresent()); ImmutableList values = getAllValues(parseState.get().order, "line"); - assertEquals(3, values.size); - assertEquals(INPUT_1, values.tail.tail.head.asString()); - assertEquals(INPUT_2, values.tail.head.asString()); - assertEquals(INPUT_3, values.head.asString()); + assertEquals(3, (long) values.size()); + assertEquals(INPUT_1, values.tail().tail().head().asString()); + assertEquals(INPUT_2, values.tail().head().asString()); + assertEquals(INPUT_3, values.head().asString()); ImmutableList newLines = getAllValues(parseState.get().order, "newline"); - assertEquals(3, newLines.size); + assertEquals(3, (long) newLines.size()); } static Collection shorthandExpressionTest() { @@ -146,13 +146,13 @@ void shorthandExpressionTest(final String name, final Token token) { assertTrue(parseState.isPresent()); ImmutableList values = getAllValues(parseState.get().order, "line"); - assertEquals(3, values.size); - assertEquals(INPUT_1 + "\n", values.tail.tail.head.asString()); - assertEquals(INPUT_2 + "\n", values.tail.head.asString()); - assertEquals(INPUT_3 + "\n", values.head.asString()); + assertEquals(3, (long) values.size()); + assertEquals(INPUT_1 + "\n", values.tail().tail().head().asString()); + assertEquals(INPUT_2 + "\n", values.tail().head().asString()); + assertEquals(INPUT_3 + "\n", values.head().asString()); ImmutableList newLines = getAllValues(parseState.get().order, "newline"); - assertEquals(0, newLines.size); + assertEquals(0, (long) newLines.size()); } @Test @@ -180,9 +180,11 @@ private static void assertNameScope(final Function tokenProvider, final Token token = seq("struct", tokenProvider.apply(terminator), terminator); final Optional parse = token.parse(env(stream('d', 'a', 't', 'a', 0, 0))); assertTrue(parse.isPresent()); - assertEquals(terminatorCount, getAllValues(parse.get().order, "struct.terminator").size); - assertEquals(1, getAllValues(parse.get().order, "struct.value").size); - assertEquals("data", getAllValues(parse.get().order, "struct.value").head.asString()); + ImmutableList parseValues1 = getAllValues(parse.get().order, "struct.terminator"); + assertEquals(terminatorCount, (long) parseValues1.size()); + ImmutableList parseValues = getAllValues(parse.get().order, "struct.value"); + assertEquals(1, (long) parseValues.size()); + assertEquals("data", getAllValues(parse.get().order, "struct.value").head().asString()); } } diff --git a/core/src/test/java/io/parsingdata/metal/token/TieTest.java b/core/src/test/java/io/parsingdata/metal/token/TieTest.java index b23f2583..85229181 100644 --- a/core/src/test/java/io/parsingdata/metal/token/TieTest.java +++ b/core/src/test/java/io/parsingdata/metal/token/TieTest.java @@ -54,6 +54,7 @@ import io.parsingdata.metal.Shorthand; import io.parsingdata.metal.data.ImmutableList; +import io.parsingdata.metal.data.ParseItem; import io.parsingdata.metal.data.ParseState; import io.parsingdata.metal.data.ParseValue; import io.parsingdata.metal.expression.value.ValueExpression; @@ -78,7 +79,8 @@ public class TieTest { public void smallContainer() { final Optional result = parseContainer(); assertEquals(5, result.get().offset.intValueExact()); - assertEquals(6, getAllValues(result.get().order, "value").size); + ImmutableList parseValues = getAllValues(result.get().order, "value"); + assertEquals(6, (long) parseValues.size()); } private Optional parseContainer() { @@ -90,7 +92,7 @@ private Optional parseContainer() { @Test public void checkContainerSource() { final Optional result = parseContainer(); - checkFullParse(INC_PREV_MOD_100, fold(ref("value"), Shorthand::cat).eval(result.get(), enc()).head.value()); + checkFullParse(INC_PREV_MOD_100, fold(ref("value"), Shorthand::cat).eval(result.get(), enc()).head().value()); } private Optional checkFullParse(Token token, byte[] data) { @@ -176,7 +178,8 @@ public void tieAndSubOnSameData() { sub(SIMPLE_SEQ, con(0))); final Optional result = nestedSeq.parse(env(stream(1, 2, 3))); assertTrue(result.isPresent()); - assertEquals(0, getReferences(result.get().order).size); + ImmutableList> optionals = getReferences(result.get().order); + assertEquals(0, (long) optionals.size()); } @Test @@ -187,11 +190,12 @@ public void multiTie() { tie(SIMPLE_SEQ, ref("d"))); final Optional result = multiTie.parse(env(stream(1, 2, 3, 1, 2, 3))); assertTrue(result.isPresent()); - assertEquals(0, getReferences(result.get().order).size); + ImmutableList> optionals = getReferences(result.get().order); + assertEquals(0, (long) optionals.size()); final String[] names = { "a", "b", "c", "d" }; for (String name : names) { ImmutableList values = getAllValues(result.get().order, name); - assertEquals(2, values.size); + assertEquals(2, (long) values.size()); } } @@ -204,12 +208,14 @@ public void tieWithDuplicate() { tie(SIMPLE_SEQ, refD)); final Optional result = duplicateTie.parse(env(stream(1, 2, 3))); assertTrue(result.isPresent()); - assertEquals(0, getReferences(result.get().order).size); - assertEquals(1, getAllValues(result.get().order, "d").size); + ImmutableList> optionals = getReferences(result.get().order); + assertEquals(0, (long) optionals.size()); + ImmutableList parseValues = getAllValues(result.get().order, "d"); + assertEquals(1, (long) parseValues.size()); final String[] names = { "a", "b", "c" }; for (String name : names) { ImmutableList values = getAllValues(result.get().order, name); - assertEquals(2, values.size); + assertEquals(2, (long) values.size()); } }