Use Collections.emptyMap and Collections.singletonMap in pattern matching code
This commit is contained in:
parent
04d01565da
commit
788f9663e2
@ -21,7 +21,7 @@ public class ConstantPattern extends VisitorPattern {
|
||||
public Optional<Map<String, Function>> visit(final Variable variable) {
|
||||
if (variable.getType().equals(Variable.V_TYPE.CONSTANT)
|
||||
&& variable.getChar() == symbol) {
|
||||
return Optional.of(new HashMap<>());
|
||||
return Optional.of(Collections.emptyMap());
|
||||
} else {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ public class EquationsSystemPattern extends VisitorPattern {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
Optional<Map<String, Function>> subFunctions = Optional.of(new HashMap<>());
|
||||
Optional<Map<String, Function>> subFunctions = Optional.of(Collections.emptyMap());
|
||||
for (int i = 0; i < patterns.length && subFunctions.isPresent(); i++) {
|
||||
final Pattern curPattern = patterns[i];
|
||||
final Function curFunction = equationsSystem.getParameter(i);
|
||||
|
@ -21,7 +21,7 @@ public class NumberPattern extends VisitorPattern {
|
||||
@Override
|
||||
public Optional<Map<String, Function>> visit(final Number number) {
|
||||
if (number.getTerm().compareTo(value) == 0) {
|
||||
return Optional.of(new HashMap<>());
|
||||
return Optional.of(Collections.emptyMap());
|
||||
} else {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
@ -18,9 +18,7 @@ public class SubFunctionPattern implements Pattern {
|
||||
|
||||
@Override
|
||||
public Optional<Map<String, Function>> match(final Function function) {
|
||||
final HashMap<String, Function> subFunctions = new HashMap<>();
|
||||
subFunctions.put(name, function);
|
||||
return Optional.of(subFunctions);
|
||||
return Optional.of(Collections.singletonMap(name, function));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -13,7 +13,7 @@ import java.util.*;
|
||||
public class UndefinedPattern extends VisitorPattern {
|
||||
@Override
|
||||
public Optional<Map<String, Function>> visit(Undefined undefined) {
|
||||
return Optional.of(new HashMap<>());
|
||||
return Optional.of(Collections.emptyMap());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user