From 9500fe28b75bf2f65d902a418890c6b5cec40137 Mon Sep 17 00:00:00 2001 From: Roel van Dijk Date: Thu, 30 Aug 2018 18:41:36 +0200 Subject: [PATCH] Rename UnaryValueExpression to OneToManyValueExpression. --- core/src/main/java/io/parsingdata/metal/Shorthand.java | 6 +++--- core/src/main/java/io/parsingdata/metal/Util.java | 4 ++-- .../metal/expression/value/BinaryValueExpression.java | 2 +- ...ueExpression.java => OneToManyValueExpression.java} | 10 +++++----- .../metal/expression/value/arithmetic/Neg.java | 6 +++--- .../metal/expression/value/bitwise/Not.java | 6 +++--- .../metal/expression/value/reference/Len.java | 6 +++--- .../metal/expression/value/reference/Offset.java | 4 ++-- .../test/java/io/parsingdata/metal/ArgumentsTest.java | 2 +- .../metal/ArithmeticValueExpressionSemanticsTest.java | 6 +++--- .../metal/ValueExpressionSemanticsTest.java | 4 ++-- .../java/io/parsingdata/metal/format/Callback.java | 4 ++-- 12 files changed, 30 insertions(+), 30 deletions(-) rename core/src/main/java/io/parsingdata/metal/expression/value/{UnaryValueExpression.java => OneToManyValueExpression.java} (89%) diff --git a/core/src/main/java/io/parsingdata/metal/Shorthand.java b/core/src/main/java/io/parsingdata/metal/Shorthand.java index a92b99cf..750df57a 100644 --- a/core/src/main/java/io/parsingdata/metal/Shorthand.java +++ b/core/src/main/java/io/parsingdata/metal/Shorthand.java @@ -44,6 +44,7 @@ import io.parsingdata.metal.expression.value.Cat; import io.parsingdata.metal.expression.value.Const; import io.parsingdata.metal.expression.value.ConstantFactory; +import io.parsingdata.metal.expression.value.OneToManyValueExpression; import io.parsingdata.metal.expression.value.reference.CurrentIteration; import io.parsingdata.metal.expression.value.Elvis; import io.parsingdata.metal.expression.value.Expand; @@ -51,7 +52,6 @@ import io.parsingdata.metal.expression.value.FoldRight; import io.parsingdata.metal.expression.value.FoldCat; import io.parsingdata.metal.expression.value.Reverse; -import io.parsingdata.metal.expression.value.UnaryValueExpression; import io.parsingdata.metal.expression.value.Value; import io.parsingdata.metal.expression.value.ValueExpression; import io.parsingdata.metal.expression.value.arithmetic.Add; @@ -164,10 +164,10 @@ private Shorthand() {} public static BinaryValueExpression mul(final ValueExpression left, final ValueExpression right) { return new Mul(left, right); } public static BinaryValueExpression sub(final ValueExpression left, final ValueExpression right) { return new Sub(left, right); } public static BinaryValueExpression mod(final ValueExpression left, final ValueExpression right) { return new Mod(left, right); } - public static UnaryValueExpression neg(final ValueExpression operand) { return new Neg(operand); } + public static OneToManyValueExpression neg(final ValueExpression operand) { return new Neg(operand); } public static BinaryValueExpression and(final ValueExpression left, final ValueExpression right) { return new io.parsingdata.metal.expression.value.bitwise.And(left, right); } public static BinaryValueExpression or(final ValueExpression left, final ValueExpression right) { return new io.parsingdata.metal.expression.value.bitwise.Or(left, right); } - public static UnaryValueExpression not(final ValueExpression operand) { return new io.parsingdata.metal.expression.value.bitwise.Not(operand); } + public static OneToManyValueExpression not(final ValueExpression operand) { return new io.parsingdata.metal.expression.value.bitwise.Not(operand); } public static BinaryValueExpression shl(final ValueExpression left, final ValueExpression right) { return new ShiftLeft(left, right); } public static BinaryValueExpression shr(final ValueExpression left, final ValueExpression right) { return new ShiftRight(left, right); } public static ValueExpression con(final long value) { return con(value, new Encoding()); } diff --git a/core/src/main/java/io/parsingdata/metal/Util.java b/core/src/main/java/io/parsingdata/metal/Util.java index c8100a34..29e77168 100644 --- a/core/src/main/java/io/parsingdata/metal/Util.java +++ b/core/src/main/java/io/parsingdata/metal/Util.java @@ -27,7 +27,7 @@ import io.parsingdata.metal.data.ParseState; import io.parsingdata.metal.data.Slice; import io.parsingdata.metal.encoding.Encoding; -import io.parsingdata.metal.expression.value.UnaryValueExpression; +import io.parsingdata.metal.expression.value.OneToManyValueExpression; import io.parsingdata.metal.expression.value.Value; import io.parsingdata.metal.expression.value.ValueExpression; @@ -85,7 +85,7 @@ public static String bytesToHexString(final byte[] bytes) { } public static ValueExpression inflate(final ValueExpression target) { - return new UnaryValueExpression(target) { + return new OneToManyValueExpression(target) { @Override public Optional eval(final Value value, final ParseState parseState, final Encoding encoding) { final Inflater inf = new Inflater(true); 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 24fc71ad..c8c7c75c 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 @@ -49,7 +49,7 @@ * handling the case of evaluating two values. This base class takes care of * evaluating the operands and handling list semantics. * - * @see UnaryValueExpression + * @see OneToManyValueExpression */ public abstract class BinaryValueExpression implements ValueExpression { diff --git a/core/src/main/java/io/parsingdata/metal/expression/value/UnaryValueExpression.java b/core/src/main/java/io/parsingdata/metal/expression/value/OneToManyValueExpression.java similarity index 89% rename from core/src/main/java/io/parsingdata/metal/expression/value/UnaryValueExpression.java rename to core/src/main/java/io/parsingdata/metal/expression/value/OneToManyValueExpression.java index 5f32053c..18fe2097 100644 --- a/core/src/main/java/io/parsingdata/metal/expression/value/UnaryValueExpression.java +++ b/core/src/main/java/io/parsingdata/metal/expression/value/OneToManyValueExpression.java @@ -33,23 +33,23 @@ /** * Base class for {@link ValueExpression}s with one operand. *

- * A UnaryValueExpression implements a ValueExpression that has one + * A OneToManyValueExpression implements a ValueExpression that has one * operand (a {@link ValueExpression}). The operand is first * evaluated. If it evaluates to {@link Optional#empty()}, the result of the * ValueExpression itself will be that as well. *

- * To implement a UnaryValueExpression, only the + * To implement a OneToManyValueExpression, only the * {@link #eval(Value, ParseState, Encoding)} must be implemented, handling * the case of evaluating one value. This base class takes care of evaluating * the operand and handling list semantics. * * @see BinaryValueExpression */ -public abstract class UnaryValueExpression implements ValueExpression { +public abstract class OneToManyValueExpression implements ValueExpression { public final ValueExpression operand; - public UnaryValueExpression(final ValueExpression operand) { + public OneToManyValueExpression(final ValueExpression operand) { this.operand = checkNotNull(operand, "operand"); } @@ -75,7 +75,7 @@ public String toString() { @Override public boolean equals(final Object obj) { return Util.notNullAndSameClass(this, obj) - && Objects.equals(operand, ((UnaryValueExpression)obj).operand); + && Objects.equals(operand, ((OneToManyValueExpression)obj).operand); } @Override diff --git a/core/src/main/java/io/parsingdata/metal/expression/value/arithmetic/Neg.java b/core/src/main/java/io/parsingdata/metal/expression/value/arithmetic/Neg.java index 1b0a886d..8b0e392a 100644 --- a/core/src/main/java/io/parsingdata/metal/expression/value/arithmetic/Neg.java +++ b/core/src/main/java/io/parsingdata/metal/expression/value/arithmetic/Neg.java @@ -21,14 +21,14 @@ import io.parsingdata.metal.data.ParseState; import io.parsingdata.metal.encoding.Encoding; import io.parsingdata.metal.expression.value.ConstantFactory; -import io.parsingdata.metal.expression.value.UnaryValueExpression; +import io.parsingdata.metal.expression.value.OneToManyValueExpression; import io.parsingdata.metal.expression.value.Value; import io.parsingdata.metal.expression.value.ValueExpression; /** - * A {@link UnaryValueExpression} that implements integer negation. + * A {@link OneToManyValueExpression} that implements integer negation. */ -public class Neg extends UnaryValueExpression { +public class Neg extends OneToManyValueExpression { public Neg(final ValueExpression operand) { super(operand); diff --git a/core/src/main/java/io/parsingdata/metal/expression/value/bitwise/Not.java b/core/src/main/java/io/parsingdata/metal/expression/value/bitwise/Not.java index 4da8f734..95480a43 100644 --- a/core/src/main/java/io/parsingdata/metal/expression/value/bitwise/Not.java +++ b/core/src/main/java/io/parsingdata/metal/expression/value/bitwise/Not.java @@ -22,14 +22,14 @@ import io.parsingdata.metal.data.ParseState; import io.parsingdata.metal.encoding.Encoding; import io.parsingdata.metal.expression.value.ConstantFactory; -import io.parsingdata.metal.expression.value.UnaryValueExpression; +import io.parsingdata.metal.expression.value.OneToManyValueExpression; import io.parsingdata.metal.expression.value.Value; import io.parsingdata.metal.expression.value.ValueExpression; /** - * A {@link UnaryValueExpression} that implements the bitwise NOT operator. + * A {@link OneToManyValueExpression} that implements the bitwise NOT operator. */ -public class Not extends UnaryValueExpression { +public class Not extends OneToManyValueExpression { public Not(final ValueExpression operand) { super(operand); diff --git a/core/src/main/java/io/parsingdata/metal/expression/value/reference/Len.java b/core/src/main/java/io/parsingdata/metal/expression/value/reference/Len.java index d76e8f1f..ae292d49 100644 --- a/core/src/main/java/io/parsingdata/metal/expression/value/reference/Len.java +++ b/core/src/main/java/io/parsingdata/metal/expression/value/reference/Len.java @@ -23,15 +23,15 @@ import io.parsingdata.metal.encoding.Encoding; import io.parsingdata.metal.encoding.Sign; import io.parsingdata.metal.expression.value.ConstantFactory; -import io.parsingdata.metal.expression.value.UnaryValueExpression; +import io.parsingdata.metal.expression.value.OneToManyValueExpression; import io.parsingdata.metal.expression.value.Value; import io.parsingdata.metal.expression.value.ValueExpression; /** - * A {@link UnaryValueExpression} that represents the sizes (in bytes) of all + * A {@link OneToManyValueExpression} that represents the sizes (in bytes) of all * {@link Value}s returned by evaluating its operand. */ -public class Len extends UnaryValueExpression { +public class Len extends OneToManyValueExpression { public Len(final ValueExpression operand) { super(operand); diff --git a/core/src/main/java/io/parsingdata/metal/expression/value/reference/Offset.java b/core/src/main/java/io/parsingdata/metal/expression/value/reference/Offset.java index cc7646c2..fea19efc 100644 --- a/core/src/main/java/io/parsingdata/metal/expression/value/reference/Offset.java +++ b/core/src/main/java/io/parsingdata/metal/expression/value/reference/Offset.java @@ -22,7 +22,7 @@ import io.parsingdata.metal.data.ParseValue; import io.parsingdata.metal.encoding.Encoding; import io.parsingdata.metal.expression.value.ConstantFactory; -import io.parsingdata.metal.expression.value.UnaryValueExpression; +import io.parsingdata.metal.expression.value.OneToManyValueExpression; import io.parsingdata.metal.expression.value.Value; import io.parsingdata.metal.expression.value.ValueExpression; @@ -34,7 +34,7 @@ * If a result does not have an offset (such as the {@link Value}s returned by * {@link io.parsingdata.metal.expression.value.Const}), empty is returned. */ -public class Offset extends UnaryValueExpression { +public class Offset extends OneToManyValueExpression { public Offset(final ValueExpression operand) { super(operand); } diff --git a/core/src/test/java/io/parsingdata/metal/ArgumentsTest.java b/core/src/test/java/io/parsingdata/metal/ArgumentsTest.java index a456a704..36d40ea9 100644 --- a/core/src/test/java/io/parsingdata/metal/ArgumentsTest.java +++ b/core/src/test/java/io/parsingdata/metal/ArgumentsTest.java @@ -101,7 +101,7 @@ public static Collection arguments() { // Derived from BinaryValueExpression { Cat.class, new Object[] { VALID_VE, null } }, { Cat.class, new Object[] { null, VALID_VE } }, - // Derived from UnaryValueExpression + // Derived from OneToManyValueExpression { Neg.class, new Object[] { null } }, { Len.class, new Object[] { null } }, // Derived from BinaryLogicalExpression diff --git a/core/src/test/java/io/parsingdata/metal/ArithmeticValueExpressionSemanticsTest.java b/core/src/test/java/io/parsingdata/metal/ArithmeticValueExpressionSemanticsTest.java index f0125dfd..a06d27a1 100644 --- a/core/src/test/java/io/parsingdata/metal/ArithmeticValueExpressionSemanticsTest.java +++ b/core/src/test/java/io/parsingdata/metal/ArithmeticValueExpressionSemanticsTest.java @@ -36,10 +36,10 @@ import java.util.Arrays; import java.util.Collection; +import io.parsingdata.metal.expression.value.OneToManyValueExpression; import org.junit.runners.Parameterized.Parameters; import io.parsingdata.metal.expression.value.BinaryValueExpression; -import io.parsingdata.metal.expression.value.UnaryValueExpression; import io.parsingdata.metal.expression.value.ValueExpression; import io.parsingdata.metal.token.Token; import io.parsingdata.metal.util.ParameterizedParse; @@ -102,7 +102,7 @@ public static Collection data() { private static final Token mul2 = binaryValueExpressionToken(mul(ref("a"), ref("b")), 2); private static final Token sub = binaryValueExpressionToken(sub(ref("a"), ref("b")), 1); private static final Token mod = binaryValueExpressionToken(mod(ref("a"), ref("b")), 1); - private static final Token neg = unaryValueExpressionToken(neg(ref("a"))); + private static final Token neg = oneToManyValueExpression(neg(ref("a"))); private static Token singleToken(final String firstName, final String secondName, final int resultSize, final ValueExpression valueExpression) { return seq(any(firstName), @@ -114,7 +114,7 @@ private static Token binaryValueExpressionToken(final BinaryValueExpression bina singleToken("b", "c", resultSize, binaryValueExpression)); } - private static Token unaryValueExpressionToken(final UnaryValueExpression unaryValueExpression) { + private static Token oneToManyValueExpression(final OneToManyValueExpression unaryValueExpression) { return singleToken("a", "b", 1, unaryValueExpression); } diff --git a/core/src/test/java/io/parsingdata/metal/ValueExpressionSemanticsTest.java b/core/src/test/java/io/parsingdata/metal/ValueExpressionSemanticsTest.java index 04f0e550..36e2bf7c 100644 --- a/core/src/test/java/io/parsingdata/metal/ValueExpressionSemanticsTest.java +++ b/core/src/test/java/io/parsingdata/metal/ValueExpressionSemanticsTest.java @@ -33,13 +33,13 @@ import java.io.IOException; import java.util.Optional; +import io.parsingdata.metal.expression.value.OneToManyValueExpression; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; import io.parsingdata.metal.data.ParseState; import io.parsingdata.metal.encoding.Encoding; -import io.parsingdata.metal.expression.value.UnaryValueExpression; import io.parsingdata.metal.expression.value.Value; import io.parsingdata.metal.token.Token; @@ -63,7 +63,7 @@ public void CatNoMatch() throws IOException { @Test public void callback() throws IOException { final ParseState data = stream(1, 2, 3, 4); - def("a", 4, eq(new UnaryValueExpression(ref("a")) { + def("a", 4, eq(new OneToManyValueExpression(ref("a")) { @Override public Optional eval(Value value, ParseState parseState, Encoding encoding) { return Optional.of(value); diff --git a/formats/src/main/java/io/parsingdata/metal/format/Callback.java b/formats/src/main/java/io/parsingdata/metal/format/Callback.java index 00924789..c40162d1 100644 --- a/formats/src/main/java/io/parsingdata/metal/format/Callback.java +++ b/formats/src/main/java/io/parsingdata/metal/format/Callback.java @@ -23,7 +23,7 @@ import io.parsingdata.metal.data.ParseState; import io.parsingdata.metal.encoding.Encoding; -import io.parsingdata.metal.expression.value.UnaryValueExpression; +import io.parsingdata.metal.expression.value.OneToManyValueExpression; import io.parsingdata.metal.expression.value.Value; import io.parsingdata.metal.expression.value.ValueExpression; @@ -32,7 +32,7 @@ public final class Callback { private Callback() {} public static ValueExpression crc32(final ValueExpression target) { - return new UnaryValueExpression(target) { + return new OneToManyValueExpression(target) { @Override public Optional eval(final Value value, final ParseState parseState, final Encoding encoding) { final CRC32 crc = new CRC32();