Skip to content

Commit

Permalink
#274: Some final reverts/modifications.
Browse files Browse the repository at this point in the history
  • Loading branch information
jvdb committed Dec 24, 2018
1 parent 7cb581b commit ce13698
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ public Bytes(final ValueExpression operand) {

@Override
public ImmutableList<Optional<Value>> eval(final ParseState parseState, final Encoding encoding) {
final ImmutableList<Optional<Value>> evaluatedOperands = operand.eval(parseState, encoding);
if (evaluatedOperands.isEmpty()) {
return evaluatedOperands;
final ImmutableList<Optional<Value>> evaluatedOperand = operand.eval(parseState, encoding);
if (evaluatedOperand.isEmpty()) {
return evaluatedOperand;
}
return toByteValues(new ImmutableList<>(), evaluatedOperands.head, evaluatedOperands.tail, encoding).computeResult();
return toByteValues(new ImmutableList<>(), evaluatedOperand.head, evaluatedOperand.tail, encoding).computeResult();
}

private Trampoline<ImmutableList<Optional<Value>>> toByteValues(final ImmutableList<Optional<Value>> output, final Optional<Value> head, final ImmutableList<Optional<Value>> tail, final Encoding encoding) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ public ImmutableList<Optional<Value>> eval(final ParseState parseState, final En
return reverse(eval(operand.eval(parseState, encoding), parseState, encoding, new ImmutableList<>()).computeResult());
}

private Trampoline<ImmutableList<Optional<Value>>> eval(final ImmutableList<Optional<Value>> evaluatedValues, final ParseState parseState, final Encoding encoding, final ImmutableList<Optional<Value>> result) {
if (evaluatedValues.isEmpty()) {
private Trampoline<ImmutableList<Optional<Value>>> eval(final ImmutableList<Optional<Value>> valuesList, final ParseState parseState, final Encoding encoding, final ImmutableList<Optional<Value>> result) {
if (valuesList.isEmpty()) {
return complete(() -> result);
}
return intermediate(() -> eval(evaluatedValues.tail, parseState, encoding, result.add(evaluatedValues.head.flatMap(value -> eval(value, parseState, encoding)))));
return intermediate(() -> eval(valuesList.tail, parseState, encoding, result.add(valuesList.head.flatMap(value -> eval(value, parseState, encoding)))));
}

public abstract Optional<Value> eval(final Value value, final ParseState parseState, final Encoding encoding);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ public Count(final ValueExpression operand) {

@Override
public ImmutableList<Optional<Value>> eval(final ParseState parseState, final Encoding encoding) {
final ImmutableList<Optional<Value>> evaluatedOperands = operand.eval(parseState, encoding);
return ImmutableList.create(Optional.of(fromNumeric(evaluatedOperands.size)));
final ImmutableList<Optional<Value>> evaluatedOperand = operand.eval(parseState, encoding);
return ImmutableList.create(Optional.of(fromNumeric(evaluatedOperand.size)));
}

private static Value fromNumeric(final long length) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ public First(final ValueExpression operand) {

@Override
public ImmutableList<Optional<Value>> eval(final ParseState parseState, final Encoding encoding) {
final ImmutableList<Optional<Value>> evaluatedOperands = operand.eval(parseState, encoding);
return evaluatedOperands.isEmpty() ? evaluatedOperands : ImmutableList.create(getFirst(evaluatedOperands).computeResult());
final ImmutableList<Optional<Value>> evaluatedOperand = operand.eval(parseState, encoding);
return evaluatedOperand.isEmpty() ? evaluatedOperand : ImmutableList.create(getFirst(evaluatedOperand).computeResult());
}

private Trampoline<Optional<Value>> getFirst(final ImmutableList<Optional<Value>> operandValues) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ public Last(final ValueExpression operand) {

@Override
public ImmutableList<Optional<Value>> eval(final ParseState parseState, final Encoding encoding) {
final ImmutableList<Optional<Value>> list = operand.eval(parseState, encoding);
return list.isEmpty() ? list : ImmutableList.create(list.head);
final ImmutableList<Optional<Value>> evaluatedOperand = operand.eval(parseState, encoding);
return evaluatedOperand.isEmpty() ? evaluatedOperand : ImmutableList.create(evaluatedOperand.head);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,22 +62,22 @@ public ImmutableList<Optional<Value>> eval(final ParseState parseState, final En
return reverse(eval(values.eval(parseState, encoding), indices.eval(parseState, encoding), new ImmutableList<>()).computeResult());
}

private Trampoline<ImmutableList<Optional<Value>>> eval(final ImmutableList<Optional<Value>> values, final ImmutableList<Optional<Value>> indicesValues, final ImmutableList<Optional<Value>> result) {
if (indicesValues.isEmpty()) {
private Trampoline<ImmutableList<Optional<Value>>> eval(final ImmutableList<Optional<Value>> valuesList, final ImmutableList<Optional<Value>> indicesList, final ImmutableList<Optional<Value>> result) {
if (indicesList.isEmpty()) {
return complete(() -> result);
}
final BigInteger valueCount = BigInteger.valueOf(values.size);
final Optional<Value> nextResult = indicesValues.head
final BigInteger valueCount = BigInteger.valueOf(valuesList.size);
final Optional<Value> nextResult = indicesList.head
.filter(index -> index.asNumeric().compareTo(valueCount) < 0 && index.asNumeric().compareTo(ZERO) >= 0)
.flatMap(index -> nth(values, valueCount.subtract(index.asNumeric()).subtract(ONE)).computeResult());
return intermediate(() -> eval(values, indicesValues.tail, result.add(nextResult)));
.flatMap(index -> nth(valuesList, valueCount.subtract(index.asNumeric()).subtract(ONE)).computeResult());
return intermediate(() -> eval(valuesList, indicesList.tail, result.add(nextResult)));
}

private Trampoline<Optional<Value>> nth(final ImmutableList<Optional<Value>> values, final BigInteger indexValue) {
private Trampoline<Optional<Value>> nth(final ImmutableList<Optional<Value>> valuesList, final BigInteger indexValue) {
if (indexValue.equals(ZERO)) {
return complete(() -> values.head);
return complete(() -> valuesList.head);
}
return intermediate(() -> nth(values.tail, indexValue.subtract(ONE)));
return intermediate(() -> nth(valuesList.tail, indexValue.subtract(ONE)));
}

@Override
Expand Down

0 comments on commit ce13698

Please sign in to comment.