Java 11 migrate remaining (g,h,i) (#1116)
* Moves game-loop to Java 11 * Moves guarded-suspension to Java 11 * Moves half-sync-half-async to Java 11 * Moves hexagonal to Java 11 * Moves intercepting-filter to Java 11 * Moves interpreter to Java 11 * Moves iterator to Java 11
This commit is contained in:
committed by
Ilkka Seppälä
parent
7d0a5c0edb
commit
f835d3d516
@ -49,24 +49,24 @@ public class App {
|
||||
* @param args command line args
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
String tokenString = "4 3 2 - 1 + *";
|
||||
Stack<Expression> stack = new Stack<>();
|
||||
var tokenString = "4 3 2 - 1 + *";
|
||||
var stack = new Stack<Expression>();
|
||||
|
||||
String[] tokenList = tokenString.split(" ");
|
||||
for (String s : tokenList) {
|
||||
var tokenList = tokenString.split(" ");
|
||||
for (var s : tokenList) {
|
||||
if (isOperator(s)) {
|
||||
Expression rightExpression = stack.pop();
|
||||
Expression leftExpression = stack.pop();
|
||||
var rightExpression = stack.pop();
|
||||
var leftExpression = stack.pop();
|
||||
LOGGER.info("popped from stack left: {} right: {}",
|
||||
leftExpression.interpret(), rightExpression.interpret());
|
||||
Expression operator = getOperatorInstance(s, leftExpression, rightExpression);
|
||||
var operator = getOperatorInstance(s, leftExpression, rightExpression);
|
||||
LOGGER.info("operator: {}", operator);
|
||||
int result = operator.interpret();
|
||||
NumberExpression resultExpression = new NumberExpression(result);
|
||||
var result = operator.interpret();
|
||||
var resultExpression = new NumberExpression(result);
|
||||
stack.push(resultExpression);
|
||||
LOGGER.info("push result to stack: {}", resultExpression.interpret());
|
||||
} else {
|
||||
Expression i = new NumberExpression(s);
|
||||
var i = new NumberExpression(s);
|
||||
stack.push(i);
|
||||
LOGGER.info("push to stack: {}", i.interpret());
|
||||
}
|
||||
|
@ -26,15 +26,12 @@ package com.iluwatar.interpreter;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
*
|
||||
* Application test
|
||||
*
|
||||
*/
|
||||
public class AppTest {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
String[] args = {};
|
||||
App.main(args);
|
||||
App.main(new String[]{});
|
||||
}
|
||||
}
|
||||
|
@ -23,25 +23,23 @@
|
||||
|
||||
package com.iluwatar.interpreter;
|
||||
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.IntBinaryOperator;
|
||||
import java.util.stream.Stream;
|
||||
import org.junit.jupiter.api.TestInstance;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.Arguments;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.IntBinaryOperator;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
|
||||
/**
|
||||
* Date: 12/14/15 - 11:48 AM
|
||||
*
|
||||
* <p>
|
||||
* Test Case for Expressions
|
||||
*
|
||||
* @param <E> Type of Expression
|
||||
* @author Jeroen Meulemeester
|
||||
*/
|
||||
@ -55,13 +53,13 @@ public abstract class ExpressionTest<E extends Expression> {
|
||||
* @return A stream with test entries
|
||||
*/
|
||||
static Stream<Arguments> prepareParameters(final IntBinaryOperator resultCalc) {
|
||||
final List<Arguments> testData = new ArrayList<>();
|
||||
for (int i = -10; i < 10; i++) {
|
||||
for (int j = -10; j < 10; j++) {
|
||||
final var testData = new ArrayList<Arguments>();
|
||||
for (var i = -10; i < 10; i++) {
|
||||
for (var j = -10; j < 10; j++) {
|
||||
testData.add(Arguments.of(
|
||||
new NumberExpression(i),
|
||||
new NumberExpression(j),
|
||||
resultCalc.applyAsInt(i, j)
|
||||
new NumberExpression(i),
|
||||
new NumberExpression(j),
|
||||
resultCalc.applyAsInt(i, j)
|
||||
));
|
||||
}
|
||||
}
|
||||
@ -104,7 +102,7 @@ public abstract class ExpressionTest<E extends Expression> {
|
||||
@ParameterizedTest
|
||||
@MethodSource("expressionProvider")
|
||||
public void testInterpret(NumberExpression first, NumberExpression second, int result) {
|
||||
final E expression = factory.apply(first, second);
|
||||
final var expression = factory.apply(first, second);
|
||||
assertNotNull(expression);
|
||||
assertEquals(result, expression.interpret());
|
||||
}
|
||||
@ -115,7 +113,7 @@ public abstract class ExpressionTest<E extends Expression> {
|
||||
@ParameterizedTest
|
||||
@MethodSource("expressionProvider")
|
||||
public void testToString(NumberExpression first, NumberExpression second) {
|
||||
final E expression = factory.apply(first, second);
|
||||
final var expression = factory.apply(first, second);
|
||||
assertNotNull(expression);
|
||||
assertEquals(expectedToString, expression.toString());
|
||||
}
|
||||
|
@ -23,9 +23,8 @@
|
||||
|
||||
package com.iluwatar.interpreter;
|
||||
|
||||
import org.junit.jupiter.params.provider.Arguments;
|
||||
|
||||
import java.util.stream.Stream;
|
||||
import org.junit.jupiter.params.provider.Arguments;
|
||||
|
||||
/**
|
||||
* Date: 12/14/15 - 12:08 PM
|
||||
|
@ -23,9 +23,8 @@
|
||||
|
||||
package com.iluwatar.interpreter;
|
||||
|
||||
import org.junit.jupiter.params.provider.Arguments;
|
||||
|
||||
import java.util.stream.Stream;
|
||||
import org.junit.jupiter.params.provider.Arguments;
|
||||
|
||||
/**
|
||||
* Date: 12/14/15 - 12:08 PM
|
||||
@ -46,7 +45,6 @@ public class MultiplyExpressionTest extends ExpressionTest<MultiplyExpression> {
|
||||
|
||||
/**
|
||||
* Create a new test instance using the given test parameters and expected result
|
||||
*
|
||||
*/
|
||||
public MultiplyExpressionTest() {
|
||||
super("*", MultiplyExpression::new);
|
||||
|
@ -23,14 +23,13 @@
|
||||
|
||||
package com.iluwatar.interpreter;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import java.util.stream.Stream;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.Arguments;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
/**
|
||||
* Date: 12/14/15 - 12:08 PM
|
||||
*
|
||||
@ -61,9 +60,9 @@ public class NumberExpressionTest extends ExpressionTest<NumberExpression> {
|
||||
@ParameterizedTest
|
||||
@MethodSource("expressionProvider")
|
||||
public void testFromString(NumberExpression first) throws Exception {
|
||||
final int expectedValue = first.interpret();
|
||||
final String testStringValue = String.valueOf(expectedValue);
|
||||
final NumberExpression numberExpression = new NumberExpression(testStringValue);
|
||||
final var expectedValue = first.interpret();
|
||||
final var testStringValue = String.valueOf(expectedValue);
|
||||
final var numberExpression = new NumberExpression(testStringValue);
|
||||
assertEquals(expectedValue, numberExpression.interpret());
|
||||
}
|
||||
|
||||
|
@ -23,9 +23,8 @@
|
||||
|
||||
package com.iluwatar.interpreter;
|
||||
|
||||
import org.junit.jupiter.params.provider.Arguments;
|
||||
|
||||
import java.util.stream.Stream;
|
||||
import org.junit.jupiter.params.provider.Arguments;
|
||||
|
||||
/**
|
||||
* Date: 12/14/15 - 12:08 PM
|
||||
@ -41,7 +40,7 @@ public class PlusExpressionTest extends ExpressionTest<PlusExpression> {
|
||||
*/
|
||||
@Override
|
||||
public Stream<Arguments> expressionProvider() {
|
||||
return prepareParameters((f, s) -> f + s);
|
||||
return prepareParameters(Integer::sum);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user