Skip to content

Commit

Permalink
#246 Rename UnaryValueExpression to OneToManyValueExpression.
Browse files Browse the repository at this point in the history
  • Loading branch information
rdvdijk committed Aug 30, 2018
1 parent 16009e4 commit dede597
Show file tree
Hide file tree
Showing 12 changed files with 30 additions and 30 deletions.
6 changes: 3 additions & 3 deletions core/src/main/java/io/parsingdata/metal/Shorthand.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@
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;
import io.parsingdata.metal.expression.value.FoldLeft;
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;
Expand Down Expand Up @@ -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()); }
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/io/parsingdata/metal/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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<Value> eval(final Value value, final ParseState parseState, final Encoding encoding) {
final Inflater inf = new Inflater(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,23 @@
/**
* Base class for {@link ValueExpression}s with one operand.
* <p>
* A UnaryValueExpression implements a ValueExpression that has one
* A OneToManyValueExpression implements a ValueExpression that has one
* <code>operand</code> (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.
* <p>
* 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");
}

Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <code>operand</code>.
*/
public class Len extends UnaryValueExpression {
public class Len extends OneToManyValueExpression {

public Len(final ValueExpression operand) {
super(operand);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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); }

Expand Down
2 changes: 1 addition & 1 deletion core/src/test/java/io/parsingdata/metal/ArgumentsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public static Collection<Object[]> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -102,7 +102,7 @@ public static Collection<Object[]> 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),
Expand All @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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<Value> eval(Value value, ParseState parseState, Encoding encoding) {
return Optional.of(value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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<Value> eval(final Value value, final ParseState parseState, final Encoding encoding) {
final CRC32 crc = new CRC32();
Expand Down

0 comments on commit dede597

Please sign in to comment.