More deprecation removal

This commit is contained in:
Matthew Miller
2018-06-16 16:36:55 +10:00
parent 20bf6e079b
commit aaaf2d5678
152 changed files with 701 additions and 1150 deletions

View File

@ -68,9 +68,9 @@ import java.util.Stack;
*/
public class Expression {
private static final ThreadLocal<Stack<Expression>> instance = new ThreadLocal<Stack<Expression>>();
private static final ThreadLocal<Stack<Expression>> instance = new ThreadLocal<>();
private final Map<String, RValue> variables = new HashMap<String, RValue>();
private final Map<String, RValue> variables = new HashMap<>();
private final String[] variableNames;
private RValue root;
private final Functions functions = new Functions();
@ -148,7 +148,7 @@ public class Expression {
private void pushInstance() {
Stack<Expression> foo = instance.get();
if (foo == null) {
instance.set(foo = new Stack<Expression>());
instance.set(foo = new Stack<>());
}
foo.push(this);

View File

@ -102,7 +102,7 @@ public class Lexer {
)
);
private static final Set<Character> characterTokens = new HashSet<Character>();
private static final Set<Character> characterTokens = new HashSet<>();
static {
characterTokens.add(',');
characterTokens.add('(');
@ -114,13 +114,14 @@ public class Lexer {
characterTokens.add(':');
}
private static final Set<String> keywords = new HashSet<String>(Arrays.asList("if", "else", "while", "do", "for", "break", "continue", "return", "switch", "case", "default"));
private static final Set<String> keywords =
new HashSet<>(Arrays.asList("if", "else", "while", "do", "for", "break", "continue", "return", "switch", "case", "default"));
private static final Pattern numberPattern = Pattern.compile("^([0-9]*(?:\\.[0-9]+)?(?:[eE][+-]?[0-9]+)?)");
private static final Pattern identifierPattern = Pattern.compile("^([A-Za-z][0-9A-Za-z_]*)");
private List<Token> tokenize() throws LexerException {
List<Token> tokens = new ArrayList<Token>();
List<Token> tokens = new ArrayList<>();
do {
skipWhitespace();
@ -189,7 +190,7 @@ public class Lexer {
public class DecisionTree {
private final String tokenName;
private final Map<Character, DecisionTree> subTrees = new HashMap<Character, Lexer.DecisionTree>();
private final Map<Character, DecisionTree> subTrees = new HashMap<>();
private DecisionTree(String tokenName, Object... args) {
this.tokenName = tokenName;

View File

@ -92,7 +92,7 @@ public class Parser {
}
private RValue parseStatements(boolean singleStatement) throws ParserException {
List<RValue> statements = new ArrayList<RValue>();
List<RValue> statements = new ArrayList<>();
loop: while (position < tokens.size()) {
boolean expectSemicolon = false;
@ -227,8 +227,8 @@ public class Parser {
case 's': // switch
++position;
final RValue parameter = parseBracket();
final List<Double> values = new ArrayList<Double>();
final List<RValue> caseStatements = new ArrayList<RValue>();
final List<Double> values = new ArrayList<>();
final List<RValue> caseStatements = new ArrayList<>();
RValue defaultCase = null;
consumeCharacter('{');
@ -310,7 +310,7 @@ public class Parser {
}
private RValue parseExpression(boolean canBeEmpty) throws ParserException {
LinkedList<Identifiable> halfProcessed = new LinkedList<Identifiable>();
LinkedList<Identifiable> halfProcessed = new LinkedList<>();
// process brackets, numbers, functions, variables and detect prefix operators
boolean expressionStart = true;
@ -397,7 +397,7 @@ public class Parser {
return Functions.getFunction(identifierToken.getPosition(), identifierToken.value);
}
List<RValue> args = new ArrayList<RValue>();
List<RValue> args = new ArrayList<>();
loop: while (true) {
args.add(parseExpression(false));

View File

@ -33,7 +33,7 @@ import java.util.*;
*/
public final class ParserProcessors {
private static final Map<String, String> unaryOpMap = new HashMap<String, String>();
private static final Map<String, String> unaryOpMap = new HashMap<>();
private static final Map<String, String>[] binaryOpMapsLA;
private static final Map<String, String>[] binaryOpMapsRA;
@ -111,7 +111,7 @@ public final class ParserProcessors {
break;
default:
Map<String, String> m = lBinaryOpMapsLA[i] = new HashMap<String, String>();
Map<String, String> m = lBinaryOpMapsLA[i] = new HashMap<>();
for (final Object[] element : a) {
m.put((String) element[0], (String) element[1]);
}
@ -133,7 +133,7 @@ public final class ParserProcessors {
break;
default:
Map<String, String> m = lBinaryOpMapsRA[i] = new HashMap<String, String>();
Map<String, String> m = lBinaryOpMapsRA[i] = new HashMap<>();
for (final Object[] element : a) {
m.put((String) element[0], (String) element[1]);
}
@ -153,8 +153,8 @@ public final class ParserProcessors {
return processUnaryOps(input);
}
LinkedList<Identifiable> lhs = new LinkedList<Identifiable>();
LinkedList<Identifiable> rhs = new LinkedList<Identifiable>();
LinkedList<Identifiable> lhs = new LinkedList<>();
LinkedList<Identifiable> rhs = new LinkedList<>();
String operator = null;
for (Iterator<Identifiable> it = input.descendingIterator(); it.hasNext();) {
@ -195,8 +195,8 @@ public final class ParserProcessors {
return processTernaryOps(input);
}
LinkedList<Identifiable> lhs = new LinkedList<Identifiable>();
LinkedList<Identifiable> rhs = new LinkedList<Identifiable>();
LinkedList<Identifiable> lhs = new LinkedList<>();
LinkedList<Identifiable> rhs = new LinkedList<>();
String operator = null;
for (Identifiable identifiable : input) {
@ -232,9 +232,9 @@ public final class ParserProcessors {
}
private static RValue processTernaryOps(LinkedList<Identifiable> input) throws ParserException {
LinkedList<Identifiable> lhs = new LinkedList<Identifiable>();
LinkedList<Identifiable> mhs = new LinkedList<Identifiable>();
LinkedList<Identifiable> rhs = new LinkedList<Identifiable>();
LinkedList<Identifiable> lhs = new LinkedList<>();
LinkedList<Identifiable> mhs = new LinkedList<>();
LinkedList<Identifiable> rhs = new LinkedList<>();
int partsFound = 0;
int conditionalsFound = 0;
@ -290,7 +290,7 @@ public final class ParserProcessors {
private static RValue processUnaryOps(LinkedList<Identifiable> input) throws ParserException {
// Preprocess postfix operators into unary operators
final Identifiable center;
LinkedList<UnaryOperator> postfixes = new LinkedList<UnaryOperator>();
LinkedList<UnaryOperator> postfixes = new LinkedList<>();
do {
if (input.isEmpty()) {
throw new ParserException(-1, "Expression missing.");

View File

@ -123,7 +123,7 @@ public final class Functions {
throw new NoSuchMethodException(); // TODO: return null (check for side-effects first)
}
private static final Map<String, List<Overload>> functions = new HashMap<String, List<Overload>>();
private static final Map<String, List<Overload>> functions = new HashMap<>();
static {
for (Method method : Functions.class.getMethods()) {
try {
@ -138,10 +138,7 @@ public final class Functions {
Overload overload = new Overload(method);
List<Overload> overloads = functions.get(methodName);
if (overloads == null) {
functions.put(methodName, overloads = new ArrayList<Overload>());
}
List<Overload> overloads = functions.computeIfAbsent(methodName, k -> new ArrayList<>());
overloads.add(overload);
}
@ -279,8 +276,8 @@ public final class Functions {
}
private static final Map<Integer, double[]> gmegabuf = new HashMap<Integer, double[]>();
private final Map<Integer, double[]> megabuf = new HashMap<Integer, double[]>();
private static final Map<Integer, double[]> gmegabuf = new HashMap<>();
private final Map<Integer, double[]> megabuf = new HashMap<>();
public Map<Integer, double[]> getMegabuf() {
return megabuf;
@ -383,12 +380,7 @@ public final class Functions {
return random.nextInt((int) Math.floor(max.getValue()));
}
private static final ThreadLocal<PerlinNoise> localPerlin = new ThreadLocal<PerlinNoise>() {
@Override
protected PerlinNoise initialValue() {
return new PerlinNoise();
}
};
private static final ThreadLocal<PerlinNoise> localPerlin = ThreadLocal.withInitial(PerlinNoise::new);
public static double perlin(RValue seed, RValue x, RValue y, RValue z, RValue frequency, RValue octaves, RValue persistence) throws EvaluationException {
PerlinNoise perlin = localPerlin.get();
@ -403,12 +395,7 @@ public final class Functions {
return perlin.noise(new Vector(x.getValue(), y.getValue(), z.getValue()));
}
private static final ThreadLocal<VoronoiNoise> localVoronoi = new ThreadLocal<VoronoiNoise>() {
@Override
protected VoronoiNoise initialValue() {
return new VoronoiNoise();
}
};
private static final ThreadLocal<VoronoiNoise> localVoronoi = ThreadLocal.withInitial(VoronoiNoise::new);
public static double voronoi(RValue seed, RValue x, RValue y, RValue z, RValue frequency) throws EvaluationException {
VoronoiNoise voronoi = localVoronoi.get();
@ -421,12 +408,7 @@ public final class Functions {
return voronoi.noise(new Vector(x.getValue(), y.getValue(), z.getValue()));
}
private static final ThreadLocal<RidgedMultiFractalNoise> localRidgedMulti = new ThreadLocal<RidgedMultiFractalNoise>() {
@Override
protected RidgedMultiFractalNoise initialValue() {
return new RidgedMultiFractalNoise();
}
};
private static final ThreadLocal<RidgedMultiFractalNoise> localRidgedMulti = ThreadLocal.withInitial(RidgedMultiFractalNoise::new);
public static double ridgedmulti(RValue seed, RValue x, RValue y, RValue z, RValue frequency, RValue octaves) throws EvaluationException {
RidgedMultiFractalNoise ridgedMulti = localRidgedMulti.get();

View File

@ -71,7 +71,7 @@ public class Sequence extends Node {
@Override
public RValue optimize() throws EvaluationException {
final List<RValue> newSequence = new ArrayList<RValue>();
final List<RValue> newSequence = new ArrayList<>();
RValue droppedLast = null;
for (RValue invokable : sequence) {

View File

@ -45,7 +45,7 @@ public class Switch extends Node implements RValue {
}
private static Map<Double, Integer> invertList(List<Double> values) {
Map<Double, Integer> valueMap = new HashMap<Double, Integer>();
Map<Double, Integer> valueMap = new HashMap<>();
for (int i = 0; i < values.size(); ++i) {
valueMap.put(values.get(i), i);
}
@ -124,7 +124,7 @@ public class Switch extends Node implements RValue {
@Override
public RValue optimize() throws EvaluationException {
final RValue optimizedParameter = parameter.optimize();
final List<RValue> newSequence = new ArrayList<RValue>();
final List<RValue> newSequence = new ArrayList<>();
if (optimizedParameter instanceof Constant) {
final double parameter = optimizedParameter.getValue();
@ -165,9 +165,9 @@ public class Switch extends Node implements RValue {
return new Switch(getPosition(), optimizedParameter, Collections.singletonMap(parameter, 0), newSequence, null);
}
final Map<Double, Integer> newValueMap = new HashMap<Double, Integer>();
final Map<Double, Integer> newValueMap = new HashMap<>();
Map<Integer, Double> backMap = new HashMap<Integer, Double>();
Map<Integer, Double> backMap = new HashMap<>();
for (Entry<Double, Integer> entry : valueMap.entrySet()) {
backMap.put(entry.getValue(), entry.getKey());
}