mirror of
https://github.com/DanilaFe/abacus
synced 2025-01-09 15:54:13 -08:00
Merge pull request #7 from DanilaFe/tree-operators
Implement tree operators and functions.
This commit is contained in:
commit
63a160659a
@ -6,6 +6,6 @@ package org.nwapw.abacus.function;
|
|||||||
*/
|
*/
|
||||||
public enum DocumentationType {
|
public enum DocumentationType {
|
||||||
|
|
||||||
FUNCTION
|
FUNCTION, TREE_VALUE_FUNCTION
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,39 +0,0 @@
|
|||||||
package org.nwapw.abacus.function;
|
|
||||||
|
|
||||||
import org.nwapw.abacus.number.NumberInterface;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A function that operates on one or more
|
|
||||||
* inputs and returns a single number.
|
|
||||||
*/
|
|
||||||
public abstract class Function {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks whether the given params will work for the given function.
|
|
||||||
*
|
|
||||||
* @param params the given params
|
|
||||||
* @return true if the params can be used with this function.
|
|
||||||
*/
|
|
||||||
protected abstract boolean matchesParams(NumberInterface[] params);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Internal apply implementation, which already receives appropriately promoted
|
|
||||||
* parameters that have bee run through matchesParams
|
|
||||||
*
|
|
||||||
* @param params the promoted parameters.
|
|
||||||
* @return the return value of the function.
|
|
||||||
*/
|
|
||||||
protected abstract NumberInterface applyInternal(NumberInterface[] params);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Function to check, promote arguments and run the function.
|
|
||||||
*
|
|
||||||
* @param params the raw input parameters.
|
|
||||||
* @return the return value of the function, or null if an error occurred.
|
|
||||||
*/
|
|
||||||
public NumberInterface apply(NumberInterface... params) {
|
|
||||||
if (!matchesParams(params)) return null;
|
|
||||||
return applyInternal(params);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -50,9 +50,15 @@ public class LexerTokenizer implements Tokenizer<Match<TokenType>>, PluginListen
|
|||||||
for (String operator : manager.getAllOperators()) {
|
for (String operator : manager.getAllOperators()) {
|
||||||
lexer.register(Pattern.sanitize(operator), TokenType.OP);
|
lexer.register(Pattern.sanitize(operator), TokenType.OP);
|
||||||
}
|
}
|
||||||
|
for (String operator : manager.getAllTreeValueOperators()){
|
||||||
|
lexer.register(Pattern.sanitize(operator), TokenType.TREE_VALUE_OP);
|
||||||
|
}
|
||||||
for (String function : manager.getAllFunctions()) {
|
for (String function : manager.getAllFunctions()) {
|
||||||
lexer.register(Pattern.sanitize(function), TokenType.FUNCTION);
|
lexer.register(Pattern.sanitize(function), TokenType.FUNCTION);
|
||||||
}
|
}
|
||||||
|
for (String function : manager.getAllTreeValueFunctions()){
|
||||||
|
lexer.register(Pattern.sanitize(function), TokenType.TREE_VALUE_FUNCTION);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -60,9 +66,15 @@ public class LexerTokenizer implements Tokenizer<Match<TokenType>>, PluginListen
|
|||||||
for (String operator : manager.getAllOperators()) {
|
for (String operator : manager.getAllOperators()) {
|
||||||
lexer.unregister(Pattern.sanitize(operator), TokenType.OP);
|
lexer.unregister(Pattern.sanitize(operator), TokenType.OP);
|
||||||
}
|
}
|
||||||
|
for (String operator : manager.getAllTreeValueOperators()){
|
||||||
|
lexer.unregister(Pattern.sanitize(operator), TokenType.TREE_VALUE_OP);
|
||||||
|
}
|
||||||
for (String function : manager.getAllFunctions()) {
|
for (String function : manager.getAllFunctions()) {
|
||||||
lexer.unregister(Pattern.sanitize(function), TokenType.FUNCTION);
|
lexer.unregister(Pattern.sanitize(function), TokenType.FUNCTION);
|
||||||
}
|
}
|
||||||
|
for (String function : manager.getAllTreeValueFunctions()){
|
||||||
|
lexer.unregister(Pattern.sanitize(function), TokenType.TREE_VALUE_FUNCTION);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -55,10 +55,10 @@ public class ShuntingYardParser implements Parser<Match<TokenType>>, PluginListe
|
|||||||
matchType = match.getType();
|
matchType = match.getType();
|
||||||
if (matchType == TokenType.NUM || matchType == TokenType.VARIABLE) {
|
if (matchType == TokenType.NUM || matchType == TokenType.VARIABLE) {
|
||||||
output.add(match);
|
output.add(match);
|
||||||
} else if (matchType == TokenType.FUNCTION) {
|
} else if (matchType == TokenType.FUNCTION || matchType == TokenType.TREE_VALUE_FUNCTION) {
|
||||||
output.add(new Match<>("", TokenType.INTERNAL_FUNCTION_END));
|
output.add(new Match<>("", TokenType.INTERNAL_FUNCTION_END));
|
||||||
tokenStack.push(match);
|
tokenStack.push(match);
|
||||||
} else if (matchType == TokenType.OP) {
|
} else if (matchType == TokenType.OP || matchType == TokenType.TREE_VALUE_OP) {
|
||||||
String tokenString = match.getContent();
|
String tokenString = match.getContent();
|
||||||
OperatorType type = typeMap.get(tokenString);
|
OperatorType type = typeMap.get(tokenString);
|
||||||
int precedence = precedenceMap.get(tokenString);
|
int precedence = precedenceMap.get(tokenString);
|
||||||
@ -70,7 +70,7 @@ public class ShuntingYardParser implements Parser<Match<TokenType>>, PluginListe
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (tokenString.equals("-") && (previousType == null || previousType == TokenType.OP ||
|
if (tokenString.equals("-") && (previousType == null || previousType == TokenType.OP ||
|
||||||
previousType == TokenType.OPEN_PARENTH)) {
|
previousType == TokenType.TREE_VALUE_OP || previousType == TokenType.OPEN_PARENTH)) {
|
||||||
from.add(0, new Match<>("`", TokenType.OP));
|
from.add(0, new Match<>("`", TokenType.OP));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -78,9 +78,12 @@ public class ShuntingYardParser implements Parser<Match<TokenType>>, PluginListe
|
|||||||
while (!tokenStack.empty() && type == OperatorType.BINARY_INFIX) {
|
while (!tokenStack.empty() && type == OperatorType.BINARY_INFIX) {
|
||||||
Match<TokenType> otherMatch = tokenStack.peek();
|
Match<TokenType> otherMatch = tokenStack.peek();
|
||||||
TokenType otherMatchType = otherMatch.getType();
|
TokenType otherMatchType = otherMatch.getType();
|
||||||
if (!(otherMatchType == TokenType.OP || otherMatchType == TokenType.FUNCTION)) break;
|
if (!(otherMatchType == TokenType.OP ||
|
||||||
|
otherMatchType == TokenType.TREE_VALUE_OP ||
|
||||||
|
otherMatchType == TokenType.FUNCTION ||
|
||||||
|
otherMatchType == TokenType.TREE_VALUE_FUNCTION)) break;
|
||||||
|
|
||||||
if (otherMatchType == TokenType.OP) {
|
if (otherMatchType == TokenType.OP || otherMatchType == TokenType.TREE_VALUE_OP) {
|
||||||
int otherPrecedence = precedenceMap.get(otherMatch.getContent());
|
int otherPrecedence = precedenceMap.get(otherMatch.getContent());
|
||||||
if (otherPrecedence < precedence ||
|
if (otherPrecedence < precedence ||
|
||||||
(associativity == OperatorAssociativity.RIGHT && otherPrecedence == precedence)) {
|
(associativity == OperatorAssociativity.RIGHT && otherPrecedence == precedence)) {
|
||||||
@ -105,7 +108,10 @@ public class ShuntingYardParser implements Parser<Match<TokenType>>, PluginListe
|
|||||||
while (!tokenStack.empty()) {
|
while (!tokenStack.empty()) {
|
||||||
Match<TokenType> match = tokenStack.peek();
|
Match<TokenType> match = tokenStack.peek();
|
||||||
TokenType newMatchType = match.getType();
|
TokenType newMatchType = match.getType();
|
||||||
if (!(newMatchType == TokenType.OP || newMatchType == TokenType.FUNCTION)) return null;
|
if (!(newMatchType == TokenType.OP ||
|
||||||
|
newMatchType == TokenType.TREE_VALUE_OP ||
|
||||||
|
newMatchType == TokenType.FUNCTION ||
|
||||||
|
newMatchType == TokenType.TREE_VALUE_FUNCTION)) return null;
|
||||||
output.add(tokenStack.pop());
|
output.add(tokenStack.pop());
|
||||||
}
|
}
|
||||||
return output;
|
return output;
|
||||||
@ -121,30 +127,43 @@ public class ShuntingYardParser implements Parser<Match<TokenType>>, PluginListe
|
|||||||
if (matches.size() == 0) return null;
|
if (matches.size() == 0) return null;
|
||||||
Match<TokenType> match = matches.remove(0);
|
Match<TokenType> match = matches.remove(0);
|
||||||
TokenType matchType = match.getType();
|
TokenType matchType = match.getType();
|
||||||
if (matchType == TokenType.OP) {
|
if (matchType == TokenType.OP || matchType == TokenType.TREE_VALUE_OP) {
|
||||||
String operator = match.getContent();
|
String operator = match.getContent();
|
||||||
OperatorType type = typeMap.get(operator);
|
OperatorType type = typeMap.get(operator);
|
||||||
if (type == OperatorType.BINARY_INFIX) {
|
if (type == OperatorType.BINARY_INFIX) {
|
||||||
TreeNode right = constructRecursive(matches);
|
TreeNode right = constructRecursive(matches);
|
||||||
TreeNode left = constructRecursive(matches);
|
TreeNode left = constructRecursive(matches);
|
||||||
if (left == null || right == null) return null;
|
if (left == null || right == null) return null;
|
||||||
else return new BinaryNode(operator, left, right);
|
if(matchType == TokenType.OP) {
|
||||||
|
return new NumberBinaryNode(operator, left, right);
|
||||||
|
} else {
|
||||||
|
return new TreeValueBinaryNode(operator, left, right);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
TreeNode applyTo = constructRecursive(matches);
|
TreeNode applyTo = constructRecursive(matches);
|
||||||
if (applyTo == null) return null;
|
if (applyTo == null) return null;
|
||||||
else return new UnaryNode(operator, applyTo);
|
if(matchType == TokenType.OP){
|
||||||
|
return new NumberUnaryNode(operator, applyTo);
|
||||||
|
} else {
|
||||||
|
return new TreeValueUnaryNode(operator, applyTo);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else if (matchType == TokenType.NUM) {
|
} else if (matchType == TokenType.NUM) {
|
||||||
return new NumberNode(match.getContent());
|
return new NumberNode(match.getContent());
|
||||||
} else if (matchType == TokenType.VARIABLE) {
|
} else if (matchType == TokenType.VARIABLE) {
|
||||||
return new VariableNode(match.getContent());
|
return new VariableNode(match.getContent());
|
||||||
} else if (matchType == TokenType.FUNCTION) {
|
} else if (matchType == TokenType.FUNCTION || matchType == TokenType.TREE_VALUE_FUNCTION) {
|
||||||
String functionName = match.getContent();
|
String functionName = match.getContent();
|
||||||
FunctionNode node = new FunctionNode(functionName);
|
CallNode node;
|
||||||
|
if(matchType == TokenType.FUNCTION){
|
||||||
|
node = new FunctionNode(functionName);
|
||||||
|
} else {
|
||||||
|
node = new TreeValueFunctionNode(functionName);
|
||||||
|
}
|
||||||
while (!matches.isEmpty() && matches.get(0).getType() != TokenType.INTERNAL_FUNCTION_END) {
|
while (!matches.isEmpty() && matches.get(0).getType() != TokenType.INTERNAL_FUNCTION_END) {
|
||||||
TreeNode argument = constructRecursive(matches);
|
TreeNode argument = constructRecursive(matches);
|
||||||
if (argument == null) return null;
|
if (argument == null) return null;
|
||||||
node.prependChild(argument);
|
node.getChildren().add(0, argument);
|
||||||
}
|
}
|
||||||
if (matches.isEmpty()) return null;
|
if (matches.isEmpty()) return null;
|
||||||
matches.remove(0);
|
matches.remove(0);
|
||||||
@ -170,6 +189,12 @@ public class ShuntingYardParser implements Parser<Match<TokenType>>, PluginListe
|
|||||||
associativityMap.put(operator, operatorInstance.getAssociativity());
|
associativityMap.put(operator, operatorInstance.getAssociativity());
|
||||||
typeMap.put(operator, operatorInstance.getType());
|
typeMap.put(operator, operatorInstance.getType());
|
||||||
}
|
}
|
||||||
|
for (String operator : manager.getAllTreeValueOperators()) {
|
||||||
|
Operator operatorInstance = manager.treeValueOperatorFor(operator);
|
||||||
|
precedenceMap.put(operator, operatorInstance.getPrecedence());
|
||||||
|
associativityMap.put(operator, operatorInstance.getAssociativity());
|
||||||
|
typeMap.put(operator, operatorInstance.getType());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1,9 +1,6 @@
|
|||||||
package org.nwapw.abacus.plugin;
|
package org.nwapw.abacus.plugin;
|
||||||
|
|
||||||
import org.nwapw.abacus.function.Documentation;
|
import org.nwapw.abacus.function.*;
|
||||||
import org.nwapw.abacus.function.DocumentationType;
|
|
||||||
import org.nwapw.abacus.function.Function;
|
|
||||||
import org.nwapw.abacus.function.Operator;
|
|
||||||
import org.nwapw.abacus.number.NumberInterface;
|
import org.nwapw.abacus.number.NumberInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -65,10 +62,21 @@ public abstract class Plugin {
|
|||||||
* @param name the name to register by.
|
* @param name the name to register by.
|
||||||
* @param toRegister the function implementation.
|
* @param toRegister the function implementation.
|
||||||
*/
|
*/
|
||||||
protected final void registerFunction(String name, Function toRegister) {
|
protected final void registerFunction(String name, NumberFunction toRegister) {
|
||||||
manager.registerFunction(name, toRegister);
|
manager.registerFunction(name, toRegister);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* To be used in load(). Registers a tree value function abstract class
|
||||||
|
* with the plugin internally, which makes it accessible to the plugin manager.
|
||||||
|
*
|
||||||
|
* @param name the name to register by.
|
||||||
|
* @param toRegister the tree value function implementation.
|
||||||
|
*/
|
||||||
|
protected final void registerTreeValueFunction(String name, TreeValueFunction toRegister) {
|
||||||
|
manager.registerTreeValueFunction(name, toRegister);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* To be used in load(). Registers an operator abstract class
|
* To be used in load(). Registers an operator abstract class
|
||||||
* with the plugin internally, which makes it accessible to
|
* with the plugin internally, which makes it accessible to
|
||||||
@ -77,10 +85,22 @@ public abstract class Plugin {
|
|||||||
* @param name the name of the operator.
|
* @param name the name of the operator.
|
||||||
* @param operator the operator to register.
|
* @param operator the operator to register.
|
||||||
*/
|
*/
|
||||||
protected final void registerOperator(String name, Operator operator) {
|
protected final void registerOperator(String name, NumberOperator operator) {
|
||||||
manager.registerOperator(name, operator);
|
manager.registerOperator(name, operator);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* To be used in load(). Registers an operator
|
||||||
|
* with the plugin internally, which makes it accessible
|
||||||
|
* to the plugin manager.
|
||||||
|
*
|
||||||
|
* @param name the name of the tree value operator.
|
||||||
|
* @param operator the tree value operator to register.
|
||||||
|
*/
|
||||||
|
protected final void registerTreeValueOperator(String name, TreeValueOperator operator) {
|
||||||
|
manager.registerTreeValueOperator(name, operator);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* To be used in load(). Registers a new number implementation with the plugin.
|
* To be used in load(). Registers a new number implementation with the plugin.
|
||||||
* This makes it accessible to the plugin manager.
|
* This makes it accessible to the plugin manager.
|
||||||
@ -110,10 +130,22 @@ public abstract class Plugin {
|
|||||||
* @param name the name for which to search
|
* @param name the name for which to search
|
||||||
* @return the resulting function, or null if none was found for that name.
|
* @return the resulting function, or null if none was found for that name.
|
||||||
*/
|
*/
|
||||||
protected final Function functionFor(String name) {
|
protected final NumberFunction functionFor(String name) {
|
||||||
return manager.functionFor(name);
|
return manager.functionFor(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Searches the PluginManager for the given function name.
|
||||||
|
* This can be used by the plugins internally in order to call functions
|
||||||
|
* they do not provide.
|
||||||
|
*
|
||||||
|
* @param name the name for which to search.
|
||||||
|
* @return the resulting tree value function, or null if none was found for that name.
|
||||||
|
*/
|
||||||
|
protected final TreeValueFunction treeValueFunctionFor(String name) {
|
||||||
|
return manager.treeValueFunctionFor(name);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Searches the PluginManager for the given operator name.
|
* Searches the PluginManager for the given operator name.
|
||||||
* This can be used by the plugins internally in order to call
|
* This can be used by the plugins internally in order to call
|
||||||
@ -122,10 +154,22 @@ public abstract class Plugin {
|
|||||||
* @param name the name for which to search
|
* @param name the name for which to search
|
||||||
* @return the resulting operator, or null if none was found for that name.
|
* @return the resulting operator, or null if none was found for that name.
|
||||||
*/
|
*/
|
||||||
protected final Operator operatorFor(String name) {
|
protected final NumberOperator operatorFor(String name) {
|
||||||
return manager.operatorFor(name);
|
return manager.operatorFor(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Searches the PluginManager for the given tree value operator name.
|
||||||
|
* This can be used by the plugins internally in order to call
|
||||||
|
* operations they do not provide.
|
||||||
|
*
|
||||||
|
* @param name the name for which to search.
|
||||||
|
* @return the resulting tree value operator, or null if none was found for that name.
|
||||||
|
*/
|
||||||
|
protected final TreeValueOperator treeValueOperatorFor(String name) {
|
||||||
|
return manager.treeValueOperatorFor(name);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Searches the PluginManager for the given number implementation
|
* Searches the PluginManager for the given number implementation
|
||||||
* name. This can be used by the plugins internally in order to find
|
* name. This can be used by the plugins internally in order to find
|
||||||
|
@ -1,10 +1,7 @@
|
|||||||
package org.nwapw.abacus.plugin;
|
package org.nwapw.abacus.plugin;
|
||||||
|
|
||||||
import org.nwapw.abacus.Abacus;
|
import org.nwapw.abacus.Abacus;
|
||||||
import org.nwapw.abacus.function.Documentation;
|
import org.nwapw.abacus.function.*;
|
||||||
import org.nwapw.abacus.function.DocumentationType;
|
|
||||||
import org.nwapw.abacus.function.Function;
|
|
||||||
import org.nwapw.abacus.function.Operator;
|
|
||||||
import org.nwapw.abacus.number.NumberInterface;
|
import org.nwapw.abacus.number.NumberInterface;
|
||||||
|
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
@ -30,11 +27,19 @@ public class PluginManager {
|
|||||||
/**
|
/**
|
||||||
* The map of functions registered by the plugins.
|
* The map of functions registered by the plugins.
|
||||||
*/
|
*/
|
||||||
private Map<String, Function> registeredFunctions;
|
private Map<String, NumberFunction> registeredFunctions;
|
||||||
|
/**
|
||||||
|
* The map of tree value functions regstered by the plugins.
|
||||||
|
*/
|
||||||
|
private Map<String, TreeValueFunction> registeredTreeValueFunctions;
|
||||||
/**
|
/**
|
||||||
* The map of operators registered by the plugins
|
* The map of operators registered by the plugins
|
||||||
*/
|
*/
|
||||||
private Map<String, Operator> registeredOperators;
|
private Map<String, NumberOperator> registeredOperators;
|
||||||
|
/**
|
||||||
|
* The map of tree value operators registered by the plugins.
|
||||||
|
*/
|
||||||
|
private Map<String, TreeValueOperator> registeredTreeValueOperators;
|
||||||
/**
|
/**
|
||||||
* The map of number implementations registered by the plugins.
|
* The map of number implementations registered by the plugins.
|
||||||
*/
|
*/
|
||||||
@ -72,7 +77,9 @@ public class PluginManager {
|
|||||||
loadedPluginClasses = new HashSet<>();
|
loadedPluginClasses = new HashSet<>();
|
||||||
plugins = new HashSet<>();
|
plugins = new HashSet<>();
|
||||||
registeredFunctions = new HashMap<>();
|
registeredFunctions = new HashMap<>();
|
||||||
|
registeredTreeValueFunctions = new HashMap<>();
|
||||||
registeredOperators = new HashMap<>();
|
registeredOperators = new HashMap<>();
|
||||||
|
registeredTreeValueOperators = new HashMap<>();
|
||||||
registeredNumberImplementations = new HashMap<>();
|
registeredNumberImplementations = new HashMap<>();
|
||||||
registeredDocumentation = new HashSet<>();
|
registeredDocumentation = new HashSet<>();
|
||||||
cachedInterfaceImplementations = new HashMap<>();
|
cachedInterfaceImplementations = new HashMap<>();
|
||||||
@ -86,20 +93,40 @@ public class PluginManager {
|
|||||||
* @param name the name of the function.
|
* @param name the name of the function.
|
||||||
* @param function the function to register.
|
* @param function the function to register.
|
||||||
*/
|
*/
|
||||||
public void registerFunction(String name, Function function) {
|
public void registerFunction(String name, NumberFunction function) {
|
||||||
registeredFunctions.put(name, function);
|
registeredFunctions.put(name, function);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Registers a tree value function under the given name.
|
||||||
|
*
|
||||||
|
* @param name the name of the function.
|
||||||
|
* @param function the function to register.
|
||||||
|
*/
|
||||||
|
public void registerTreeValueFunction(String name, TreeValueFunction function) {
|
||||||
|
registeredTreeValueFunctions.put(name, function);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Registers an operator under the given name.
|
* Registers an operator under the given name.
|
||||||
*
|
*
|
||||||
* @param name the name of the operator.
|
* @param name the name of the operator.
|
||||||
* @param operator the operator to register.
|
* @param operator the operator to register.
|
||||||
*/
|
*/
|
||||||
public void registerOperator(String name, Operator operator) {
|
public void registerOperator(String name, NumberOperator operator) {
|
||||||
registeredOperators.put(name, operator);
|
registeredOperators.put(name, operator);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Registers a tree value operator under the given name.
|
||||||
|
*
|
||||||
|
* @param name the name of the tree value operator.
|
||||||
|
* @param operator the tree value operator to register.
|
||||||
|
*/
|
||||||
|
public void registerTreeValueOperator(String name, TreeValueOperator operator) {
|
||||||
|
registeredTreeValueOperators.put(name, operator);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Registers a number implementation under the given name.
|
* Registers a number implementation under the given name.
|
||||||
*
|
*
|
||||||
@ -126,20 +153,40 @@ public class PluginManager {
|
|||||||
* @param name the name of the function.
|
* @param name the name of the function.
|
||||||
* @return the function, or null if it was not found.
|
* @return the function, or null if it was not found.
|
||||||
*/
|
*/
|
||||||
public Function functionFor(String name) {
|
public NumberFunction functionFor(String name) {
|
||||||
return registeredFunctions.get(name);
|
return registeredFunctions.get(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the tree value function registered under the given name.
|
||||||
|
*
|
||||||
|
* @param name the name of the function.
|
||||||
|
* @return the function, or null if it was not found.
|
||||||
|
*/
|
||||||
|
public TreeValueFunction treeValueFunctionFor(String name) {
|
||||||
|
return registeredTreeValueFunctions.get(name);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the operator registered under the given name.
|
* Gets the operator registered under the given name.
|
||||||
*
|
*
|
||||||
* @param name the name of the operator.
|
* @param name the name of the operator.
|
||||||
* @return the operator, or null if it was not found.
|
* @return the operator, or null if it was not found.
|
||||||
*/
|
*/
|
||||||
public Operator operatorFor(String name) {
|
public NumberOperator operatorFor(String name) {
|
||||||
return registeredOperators.get(name);
|
return registeredOperators.get(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the tree value operator registered under the given name.
|
||||||
|
*
|
||||||
|
* @param name the name of the tree value operator.
|
||||||
|
* @return the operator, or null if it was not found.
|
||||||
|
*/
|
||||||
|
public TreeValueOperator treeValueOperatorFor(String name) {
|
||||||
|
return registeredTreeValueOperators.get(name);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the number implementation registered under the given name.
|
* Gets the number implementation registered under the given name.
|
||||||
*
|
*
|
||||||
@ -277,7 +324,9 @@ public class PluginManager {
|
|||||||
plugin.disable();
|
plugin.disable();
|
||||||
}
|
}
|
||||||
registeredFunctions.clear();
|
registeredFunctions.clear();
|
||||||
|
registeredTreeValueFunctions.clear();
|
||||||
registeredOperators.clear();
|
registeredOperators.clear();
|
||||||
|
registeredTreeValueOperators.clear();
|
||||||
registeredNumberImplementations.clear();
|
registeredNumberImplementations.clear();
|
||||||
registeredDocumentation.clear();
|
registeredDocumentation.clear();
|
||||||
cachedInterfaceImplementations.clear();
|
cachedInterfaceImplementations.clear();
|
||||||
@ -302,6 +351,15 @@ public class PluginManager {
|
|||||||
return registeredFunctions.keySet();
|
return registeredFunctions.keySet();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets all the tree vlaue functions loaded by the PluginManager.
|
||||||
|
*
|
||||||
|
* @return the set of all the tree value functions that were loaded.
|
||||||
|
*/
|
||||||
|
public Set<String> getAllTreeValueFunctions() {
|
||||||
|
return registeredTreeValueFunctions.keySet();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets all the operators loaded by the Plugin Manager.
|
* Gets all the operators loaded by the Plugin Manager.
|
||||||
*
|
*
|
||||||
@ -311,6 +369,15 @@ public class PluginManager {
|
|||||||
return registeredOperators.keySet();
|
return registeredOperators.keySet();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets all the tree value operators loaded by the PluginManager.
|
||||||
|
*
|
||||||
|
* @return the set of all tree value operators that were loaded.
|
||||||
|
*/
|
||||||
|
public Set<String> getAllTreeValueOperators() {
|
||||||
|
return registeredTreeValueOperators.keySet();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets all the number implementations loaded by the Plugin Manager.
|
* Gets all the number implementations loaded by the Plugin Manager.
|
||||||
*
|
*
|
||||||
|
@ -18,83 +18,60 @@ public class StandardPlugin extends Plugin {
|
|||||||
/**
|
/**
|
||||||
* The addition operator, +
|
* The addition operator, +
|
||||||
*/
|
*/
|
||||||
public static final Operator OP_ADD = new Operator(OperatorAssociativity.LEFT, OperatorType.BINARY_INFIX, 0, new Function() {
|
public static final NumberOperator OP_ADD = new NumberOperator(OperatorAssociativity.LEFT, OperatorType.BINARY_INFIX, 0) {
|
||||||
@Override
|
@Override
|
||||||
protected boolean matchesParams(NumberInterface[] params) {
|
public boolean matchesParams(NumberInterface[] params) {
|
||||||
return params.length >= 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected NumberInterface applyInternal(NumberInterface[] params) {
|
|
||||||
NumberInterface sum = params[0];
|
|
||||||
for (int i = 1; i < params.length; i++) {
|
|
||||||
sum = sum.add(params[i]);
|
|
||||||
}
|
|
||||||
return sum;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
/**
|
|
||||||
* The subtraction operator, -
|
|
||||||
*/
|
|
||||||
public static final Operator OP_SUBTRACT = new Operator(OperatorAssociativity.LEFT, OperatorType.BINARY_INFIX, 0, new Function() {
|
|
||||||
@Override
|
|
||||||
protected boolean matchesParams(NumberInterface[] params) {
|
|
||||||
return params.length == 2;
|
return params.length == 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected NumberInterface applyInternal(NumberInterface[] params) {
|
public NumberInterface applyInternal(NumberInterface[] params) {
|
||||||
|
return params[0].add(params[1]);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
/**
|
||||||
|
* The subtraction operator, -
|
||||||
|
*/
|
||||||
|
public static final NumberOperator OP_SUBTRACT = new NumberOperator(OperatorAssociativity.LEFT, OperatorType.BINARY_INFIX, 0) {
|
||||||
|
@Override
|
||||||
|
public boolean matchesParams(NumberInterface[] params) {
|
||||||
|
return params.length == 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NumberInterface applyInternal(NumberInterface[] params) {
|
||||||
return params[0].subtract(params[1]);
|
return params[0].subtract(params[1]);
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
};
|
||||||
/**
|
/**
|
||||||
* The negation operator, -
|
* The negation operator, -
|
||||||
*/
|
*/
|
||||||
public static final Operator OP_NEGATE = new Operator(OperatorAssociativity.LEFT, OperatorType.UNARY_PREFIX, 0, new Function() {
|
public static final NumberOperator OP_NEGATE = new NumberOperator(OperatorAssociativity.LEFT, OperatorType.UNARY_PREFIX, 0) {
|
||||||
@Override
|
@Override
|
||||||
protected boolean matchesParams(NumberInterface[] params) {
|
public boolean matchesParams(NumberInterface[] params) {
|
||||||
return params.length == 1;
|
return params.length == 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected NumberInterface applyInternal(NumberInterface[] params) {
|
public NumberInterface applyInternal(NumberInterface[] params) {
|
||||||
return params[0].negate();
|
return params[0].negate();
|
||||||
}
|
}
|
||||||
});
|
};
|
||||||
/**
|
/**
|
||||||
* The multiplication operator, *
|
* The multiplication operator, *
|
||||||
*/
|
*/
|
||||||
public static final Operator OP_MULTIPLY = new Operator(OperatorAssociativity.LEFT, OperatorType.BINARY_INFIX, 1, new Function() {
|
public static final NumberOperator OP_MULTIPLY = new NumberOperator(OperatorAssociativity.LEFT, OperatorType.BINARY_INFIX, 1) {
|
||||||
@Override
|
@Override
|
||||||
protected boolean matchesParams(NumberInterface[] params) {
|
public boolean matchesParams(NumberInterface[] params) {
|
||||||
return params.length >= 1;
|
return params.length == 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected NumberInterface applyInternal(NumberInterface[] params) {
|
public NumberInterface applyInternal(NumberInterface[] params) {
|
||||||
NumberInterface product = params[0];
|
return params[0].multiply(params[1]);
|
||||||
for (int i = 1; i < params.length; i++) {
|
|
||||||
product = product.multiply(params[i]);
|
|
||||||
}
|
}
|
||||||
return product;
|
};
|
||||||
}
|
|
||||||
});
|
|
||||||
/**
|
|
||||||
* The combination operator.
|
|
||||||
*/
|
|
||||||
public static final Operator OP_NCR = new Operator(OperatorAssociativity.RIGHT, OperatorType.BINARY_INFIX, 0, new Function() {
|
|
||||||
@Override
|
|
||||||
protected boolean matchesParams(NumberInterface[] params) {
|
|
||||||
return params.length == 2 && params[0].fractionalPart().signum() == 0
|
|
||||||
&& params[1].fractionalPart().signum() == 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected NumberInterface applyInternal(NumberInterface[] params) {
|
|
||||||
return OP_NPR.getFunction().apply(params).divide(OP_FACTORIAL.getFunction().apply(params[1]));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
/**
|
/**
|
||||||
* The implementation for double-based naive numbers.
|
* The implementation for double-based naive numbers.
|
||||||
*/
|
*/
|
||||||
@ -109,6 +86,20 @@ public class StandardPlugin extends Plugin {
|
|||||||
return new NaiveNumber(Math.PI);
|
return new NaiveNumber(Math.PI);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
/**
|
||||||
|
* The square root function.
|
||||||
|
*/
|
||||||
|
public static final NumberFunction FUNCTION_SQRT = new NumberFunction() {
|
||||||
|
@Override
|
||||||
|
public boolean matchesParams(NumberInterface[] params) {
|
||||||
|
return params.length == 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NumberInterface applyInternal(NumberInterface[] params) {
|
||||||
|
return OP_CARET.apply(params[0], ((new NaiveNumber(0.5)).promoteTo(params[0].getClass())));
|
||||||
|
}
|
||||||
|
};
|
||||||
/**
|
/**
|
||||||
* The implementation for the infinite-precision BigDecimal.
|
* The implementation for the infinite-precision BigDecimal.
|
||||||
*/
|
*/
|
||||||
@ -152,31 +143,31 @@ public class StandardPlugin extends Plugin {
|
|||||||
/**
|
/**
|
||||||
* The division operator, /
|
* The division operator, /
|
||||||
*/
|
*/
|
||||||
public static final Operator OP_DIVIDE = new Operator(OperatorAssociativity.LEFT, OperatorType.BINARY_INFIX, 1, new Function() {
|
public static final NumberOperator OP_DIVIDE = new NumberOperator(OperatorAssociativity.LEFT, OperatorType.BINARY_INFIX, 1) {
|
||||||
@Override
|
@Override
|
||||||
protected boolean matchesParams(NumberInterface[] params) {
|
public boolean matchesParams(NumberInterface[] params) {
|
||||||
return params.length == 2 && params[1].compareTo(fromInt(params[0].getClass(), 0)) != 0;
|
return params.length == 2 && params[1].compareTo(fromInt(params[0].getClass(), 0)) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected NumberInterface applyInternal(NumberInterface[] params) {
|
public NumberInterface applyInternal(NumberInterface[] params) {
|
||||||
return params[0].divide(params[1]);
|
return params[0].divide(params[1]);
|
||||||
}
|
}
|
||||||
});
|
};
|
||||||
/**
|
/**
|
||||||
* The factorial operator, !
|
* The factorial operator, !
|
||||||
*/
|
*/
|
||||||
public static final Operator OP_FACTORIAL = new Operator(OperatorAssociativity.RIGHT, OperatorType.UNARY_POSTFIX, 0, new Function() {
|
public static final NumberOperator OP_FACTORIAL = new NumberOperator(OperatorAssociativity.RIGHT, OperatorType.UNARY_POSTFIX, 0) {
|
||||||
//private HashMap<Class<? extends NumberInterface>, ArrayList<NumberInterface>> storedList = new HashMap<Class<? extends NumberInterface>, ArrayList<NumberInterface>>();
|
//private HashMap<Class<? extends NumberInterface>, ArrayList<NumberInterface>> storedList = new HashMap<Class<? extends NumberInterface>, ArrayList<NumberInterface>>();
|
||||||
@Override
|
@Override
|
||||||
protected boolean matchesParams(NumberInterface[] params) {
|
public boolean matchesParams(NumberInterface[] params) {
|
||||||
return params.length == 1
|
return params.length == 1
|
||||||
&& params[0].fractionalPart().compareTo(fromInt(params[0].getClass(), 0)) == 0
|
&& params[0].fractionalPart().compareTo(fromInt(params[0].getClass(), 0)) == 0
|
||||||
&& params[0].signum() >= 0;
|
&& params[0].signum() >= 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected NumberInterface applyInternal(NumberInterface[] params) {
|
public NumberInterface applyInternal(NumberInterface[] params) {
|
||||||
if (params[0].signum() == 0) {
|
if (params[0].signum() == 0) {
|
||||||
return fromInt(params[0].getClass(), 1);
|
return fromInt(params[0].getClass(), 1);
|
||||||
}
|
}
|
||||||
@ -194,19 +185,19 @@ public class StandardPlugin extends Plugin {
|
|||||||
storedList.get(params[0].getClass()).add(NaiveNumber.ONE.promoteTo(params[0].getClass()));
|
storedList.get(params[0].getClass()).add(NaiveNumber.ONE.promoteTo(params[0].getClass()));
|
||||||
}*/
|
}*/
|
||||||
}
|
}
|
||||||
});
|
};
|
||||||
/**
|
/**
|
||||||
* The permutation operator.
|
* The permutation operator.
|
||||||
*/
|
*/
|
||||||
public static final Operator OP_NPR = new Operator(OperatorAssociativity.RIGHT, OperatorType.BINARY_INFIX, 0, new Function() {
|
public static final NumberOperator OP_NPR = new NumberOperator(OperatorAssociativity.RIGHT, OperatorType.BINARY_INFIX, 0) {
|
||||||
@Override
|
@Override
|
||||||
protected boolean matchesParams(NumberInterface[] params) {
|
public boolean matchesParams(NumberInterface[] params) {
|
||||||
return params.length == 2 && params[0].fractionalPart().signum() == 0
|
return params.length == 2 && params[0].fractionalPart().signum() == 0
|
||||||
&& params[1].fractionalPart().signum() == 0;
|
&& params[1].fractionalPart().signum() == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected NumberInterface applyInternal(NumberInterface[] params) {
|
public NumberInterface applyInternal(NumberInterface[] params) {
|
||||||
if (params[0].compareTo(params[1]) < 0 ||
|
if (params[0].compareTo(params[1]) < 0 ||
|
||||||
params[0].signum() < 0 ||
|
params[0].signum() < 0 ||
|
||||||
(params[0].signum() == 0 && params[1].signum() != 0)) return fromInt(params[0].getClass(), 0);
|
(params[0].signum() == 0 && params[1].signum() != 0)) return fromInt(params[0].getClass(), 0);
|
||||||
@ -224,32 +215,47 @@ public class StandardPlugin extends Plugin {
|
|||||||
}
|
}
|
||||||
return total;
|
return total;
|
||||||
}
|
}
|
||||||
});
|
};
|
||||||
|
/**
|
||||||
|
* The combination operator.
|
||||||
|
*/
|
||||||
|
public static final NumberOperator OP_NCR = new NumberOperator(OperatorAssociativity.RIGHT, OperatorType.BINARY_INFIX, 0) {
|
||||||
|
@Override
|
||||||
|
public boolean matchesParams(NumberInterface[] params) {
|
||||||
|
return params.length == 2 && params[0].fractionalPart().signum() == 0
|
||||||
|
&& params[1].fractionalPart().signum() == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NumberInterface applyInternal(NumberInterface[] params) {
|
||||||
|
return OP_NPR.apply(params).divide(OP_FACTORIAL.apply(params[1]));
|
||||||
|
}
|
||||||
|
};
|
||||||
/**
|
/**
|
||||||
* The absolute value function, abs(-3) = 3
|
* The absolute value function, abs(-3) = 3
|
||||||
*/
|
*/
|
||||||
public static final Function FUNCTION_ABS = new Function() {
|
public static final NumberFunction FUNCTION_ABS = new NumberFunction() {
|
||||||
@Override
|
@Override
|
||||||
protected boolean matchesParams(NumberInterface[] params) {
|
public boolean matchesParams(NumberInterface[] params) {
|
||||||
return params.length == 1;
|
return params.length == 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected NumberInterface applyInternal(NumberInterface[] params) {
|
public NumberInterface applyInternal(NumberInterface[] params) {
|
||||||
return params[0].multiply(fromInt(params[0].getClass(), params[0].signum()));
|
return params[0].multiply(fromInt(params[0].getClass(), params[0].signum()));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
/**
|
/**
|
||||||
* The natural log function.
|
* The natural log function.
|
||||||
*/
|
*/
|
||||||
public static final Function FUNCTION_LN = new Function() {
|
public static final NumberFunction FUNCTION_LN = new NumberFunction() {
|
||||||
@Override
|
@Override
|
||||||
protected boolean matchesParams(NumberInterface[] params) {
|
public boolean matchesParams(NumberInterface[] params) {
|
||||||
return params.length == 1 && params[0].compareTo(fromInt(params[0].getClass(), 0)) > 0;
|
return params.length == 1 && params[0].compareTo(fromInt(params[0].getClass(), 0)) > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected NumberInterface applyInternal(NumberInterface[] params) {
|
public NumberInterface applyInternal(NumberInterface[] params) {
|
||||||
NumberInterface param = params[0];
|
NumberInterface param = params[0];
|
||||||
NumberInterface one = fromInt(param.getClass(), 1);
|
NumberInterface one = fromInt(param.getClass(), 1);
|
||||||
int powersOf2 = 0;
|
int powersOf2 = 0;
|
||||||
@ -322,73 +328,29 @@ public class StandardPlugin extends Plugin {
|
|||||||
/**
|
/**
|
||||||
* Gets a random number smaller or equal to the given number's integer value.
|
* Gets a random number smaller or equal to the given number's integer value.
|
||||||
*/
|
*/
|
||||||
public static final Function FUNCTION_RAND_INT = new Function() {
|
public static final NumberFunction FUNCTION_RAND_INT = new NumberFunction() {
|
||||||
@Override
|
@Override
|
||||||
protected boolean matchesParams(NumberInterface[] params) {
|
public boolean matchesParams(NumberInterface[] params) {
|
||||||
return params.length == 1;
|
return params.length == 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected NumberInterface applyInternal(NumberInterface[] params) {
|
public NumberInterface applyInternal(NumberInterface[] params) {
|
||||||
return fromInt(params[0].getClass(), (int) Math.round(Math.random() * params[0].floor().intValue()));
|
return fromInt(params[0].getClass(), (int) Math.round(Math.random() * params[0].floor().intValue()));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
/**
|
|
||||||
* The caret / pow operator, ^
|
|
||||||
*/
|
|
||||||
public static final Operator OP_CARET = new Operator(OperatorAssociativity.RIGHT, OperatorType.BINARY_INFIX, 2, new Function() {
|
|
||||||
@Override
|
|
||||||
protected boolean matchesParams(NumberInterface[] params) {
|
|
||||||
NumberInterface zero = fromInt(params[0].getClass(), 0);
|
|
||||||
return params.length == 2
|
|
||||||
&& !(params[0].compareTo(zero) == 0
|
|
||||||
&& params[1].compareTo(zero) == 0)
|
|
||||||
&& !(params[0].signum() == -1 && params[1].fractionalPart().compareTo(zero) != 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected NumberInterface applyInternal(NumberInterface[] params) {
|
|
||||||
NumberInterface zero = fromInt(params[0].getClass(), 0);
|
|
||||||
if (params[0].compareTo(zero) == 0)
|
|
||||||
return zero;
|
|
||||||
else if (params[1].compareTo(zero) == 0)
|
|
||||||
return fromInt(params[0].getClass(), 1);
|
|
||||||
//Detect integer bases:
|
|
||||||
if (params[0].fractionalPart().compareTo(fromInt(params[0].getClass(), 0)) == 0
|
|
||||||
&& FUNCTION_ABS.apply(params[1]).compareTo(fromInt(params[0].getClass(), Integer.MAX_VALUE)) < 0
|
|
||||||
&& FUNCTION_ABS.apply(params[1]).compareTo(fromInt(params[1].getClass(), 1)) >= 0) {
|
|
||||||
NumberInterface[] newParams = {params[0], params[1].fractionalPart()};
|
|
||||||
return params[0].intPow(params[1].floor().intValue()).multiply(applyInternal(newParams));
|
|
||||||
}
|
|
||||||
return FUNCTION_EXP.apply(FUNCTION_LN.apply(FUNCTION_ABS.apply(params[0])).multiply(params[1]));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
/**
|
|
||||||
* The square root function.
|
|
||||||
*/
|
|
||||||
public static final Function FUNCTION_SQRT = new Function() {
|
|
||||||
@Override
|
|
||||||
protected boolean matchesParams(NumberInterface[] params) {
|
|
||||||
return params.length == 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected NumberInterface applyInternal(NumberInterface[] params) {
|
|
||||||
return OP_CARET.getFunction().apply(params[0], ((new NaiveNumber(0.5)).promoteTo(params[0].getClass())));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
private static final HashMap<Class<? extends NumberInterface>, ArrayList<NumberInterface>> FACTORIAL_LISTS = new HashMap<>();
|
private static final HashMap<Class<? extends NumberInterface>, ArrayList<NumberInterface>> FACTORIAL_LISTS = new HashMap<>();
|
||||||
/**
|
/**
|
||||||
* The exponential function, exp(1) = e^1 = 2.71...
|
* The exponential function, exp(1) = e^1 = 2.71...
|
||||||
*/
|
*/
|
||||||
public static final Function FUNCTION_EXP = new Function() {
|
public static final NumberFunction FUNCTION_EXP = new NumberFunction() {
|
||||||
@Override
|
@Override
|
||||||
protected boolean matchesParams(NumberInterface[] params) {
|
public boolean matchesParams(NumberInterface[] params) {
|
||||||
return params.length == 1;
|
return params.length == 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected NumberInterface applyInternal(NumberInterface[] params) {
|
public NumberInterface applyInternal(NumberInterface[] params) {
|
||||||
NumberInterface maxError = params[0].getMaxError();
|
NumberInterface maxError = params[0].getMaxError();
|
||||||
int n = 0;
|
int n = 0;
|
||||||
if (params[0].signum() < 0) {
|
if (params[0].signum() < 0) {
|
||||||
@ -415,17 +377,47 @@ public class StandardPlugin extends Plugin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
/**
|
||||||
|
* The caret / pow operator, ^
|
||||||
|
*/
|
||||||
|
public static final NumberOperator OP_CARET = new NumberOperator(OperatorAssociativity.RIGHT, OperatorType.BINARY_INFIX, 2) {
|
||||||
|
@Override
|
||||||
|
public boolean matchesParams(NumberInterface[] params) {
|
||||||
|
NumberInterface zero = fromInt(params[0].getClass(), 0);
|
||||||
|
return params.length == 2
|
||||||
|
&& !(params[0].compareTo(zero) == 0
|
||||||
|
&& params[1].compareTo(zero) == 0)
|
||||||
|
&& !(params[0].signum() == -1 && params[1].fractionalPart().compareTo(zero) != 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NumberInterface applyInternal(NumberInterface[] params) {
|
||||||
|
NumberInterface zero = fromInt(params[0].getClass(), 0);
|
||||||
|
if (params[0].compareTo(zero) == 0)
|
||||||
|
return zero;
|
||||||
|
else if (params[1].compareTo(zero) == 0)
|
||||||
|
return fromInt(params[0].getClass(), 1);
|
||||||
|
//Detect integer bases:
|
||||||
|
if (params[0].fractionalPart().compareTo(fromInt(params[0].getClass(), 0)) == 0
|
||||||
|
&& FUNCTION_ABS.apply(params[1]).compareTo(fromInt(params[0].getClass(), Integer.MAX_VALUE)) < 0
|
||||||
|
&& FUNCTION_ABS.apply(params[1]).compareTo(fromInt(params[1].getClass(), 1)) >= 0) {
|
||||||
|
NumberInterface[] newParams = {params[0], params[1].fractionalPart()};
|
||||||
|
return params[0].intPow(params[1].floor().intValue()).multiply(applyInternal(newParams));
|
||||||
|
}
|
||||||
|
return FUNCTION_EXP.apply(FUNCTION_LN.apply(FUNCTION_ABS.apply(params[0])).multiply(params[1]));
|
||||||
|
}
|
||||||
|
};
|
||||||
/**
|
/**
|
||||||
* The sine function (the argument is interpreted in radians).
|
* The sine function (the argument is interpreted in radians).
|
||||||
*/
|
*/
|
||||||
public final Function functionSin = new Function() {
|
public final NumberFunction functionSin = new NumberFunction() {
|
||||||
@Override
|
@Override
|
||||||
protected boolean matchesParams(NumberInterface[] params) {
|
public boolean matchesParams(NumberInterface[] params) {
|
||||||
return params.length == 1;
|
return params.length == 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected NumberInterface applyInternal(NumberInterface[] params) {
|
public NumberInterface applyInternal(NumberInterface[] params) {
|
||||||
NumberInterface pi = piFor(params[0].getClass());
|
NumberInterface pi = piFor(params[0].getClass());
|
||||||
NumberInterface twoPi = pi.multiply(fromInt(pi.getClass(), 2));
|
NumberInterface twoPi = pi.multiply(fromInt(pi.getClass(), 2));
|
||||||
NumberInterface theta = getSmallAngle(params[0], pi);
|
NumberInterface theta = getSmallAngle(params[0], pi);
|
||||||
@ -442,14 +434,14 @@ public class StandardPlugin extends Plugin {
|
|||||||
/**
|
/**
|
||||||
* The cosine function (the argument is in radians).
|
* The cosine function (the argument is in radians).
|
||||||
*/
|
*/
|
||||||
public final Function functionCos = new Function() {
|
public final NumberFunction functionCos = new NumberFunction() {
|
||||||
@Override
|
@Override
|
||||||
protected boolean matchesParams(NumberInterface[] params) {
|
public boolean matchesParams(NumberInterface[] params) {
|
||||||
return params.length == 1;
|
return params.length == 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected NumberInterface applyInternal(NumberInterface[] params) {
|
public NumberInterface applyInternal(NumberInterface[] params) {
|
||||||
return functionSin.apply(piFor(params[0].getClass()).divide(fromInt(params[0].getClass(), 2))
|
return functionSin.apply(piFor(params[0].getClass()).divide(fromInt(params[0].getClass(), 2))
|
||||||
.subtract(params[0]));
|
.subtract(params[0]));
|
||||||
}
|
}
|
||||||
@ -457,56 +449,56 @@ public class StandardPlugin extends Plugin {
|
|||||||
/**
|
/**
|
||||||
* The tangent function (the argument is in radians).
|
* The tangent function (the argument is in radians).
|
||||||
*/
|
*/
|
||||||
public final Function functionTan = new Function() {
|
public final NumberFunction functionTan = new NumberFunction() {
|
||||||
@Override
|
@Override
|
||||||
protected boolean matchesParams(NumberInterface[] params) {
|
public boolean matchesParams(NumberInterface[] params) {
|
||||||
return params.length == 1;
|
return params.length == 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected NumberInterface applyInternal(NumberInterface[] params) {
|
public NumberInterface applyInternal(NumberInterface[] params) {
|
||||||
return functionSin.apply(params[0]).divide(functionCos.apply(params[0]));
|
return functionSin.apply(params[0]).divide(functionCos.apply(params[0]));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
/**
|
/**
|
||||||
* The secant function (the argument is in radians).
|
* The secant function (the argument is in radians).
|
||||||
*/
|
*/
|
||||||
public final Function functionSec = new Function() {
|
public final NumberFunction functionSec = new NumberFunction() {
|
||||||
@Override
|
@Override
|
||||||
protected boolean matchesParams(NumberInterface[] params) {
|
public boolean matchesParams(NumberInterface[] params) {
|
||||||
return params.length == 1;
|
return params.length == 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected NumberInterface applyInternal(NumberInterface[] params) {
|
public NumberInterface applyInternal(NumberInterface[] params) {
|
||||||
return fromInt(params[0].getClass(), 1).divide(functionCos.apply(params[0]));
|
return fromInt(params[0].getClass(), 1).divide(functionCos.apply(params[0]));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
/**
|
/**
|
||||||
* The cosecant function (the argument is in radians).
|
* The cosecant function (the argument is in radians).
|
||||||
*/
|
*/
|
||||||
public final Function functionCsc = new Function() {
|
public final NumberFunction functionCsc = new NumberFunction() {
|
||||||
@Override
|
@Override
|
||||||
protected boolean matchesParams(NumberInterface[] params) {
|
public boolean matchesParams(NumberInterface[] params) {
|
||||||
return params.length == 1;
|
return params.length == 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected NumberInterface applyInternal(NumberInterface[] params) {
|
public NumberInterface applyInternal(NumberInterface[] params) {
|
||||||
return fromInt(params[0].getClass(), 1).divide(functionSin.apply(params[0]));
|
return fromInt(params[0].getClass(), 1).divide(functionSin.apply(params[0]));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
/**
|
/**
|
||||||
* The cotangent function (the argument is in radians).
|
* The cotangent function (the argument is in radians).
|
||||||
*/
|
*/
|
||||||
public final Function functionCot = new Function() {
|
public final NumberFunction functionCot = new NumberFunction() {
|
||||||
@Override
|
@Override
|
||||||
protected boolean matchesParams(NumberInterface[] params) {
|
public boolean matchesParams(NumberInterface[] params) {
|
||||||
return params.length == 1;
|
return params.length == 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected NumberInterface applyInternal(NumberInterface[] params) {
|
public NumberInterface applyInternal(NumberInterface[] params) {
|
||||||
return functionCos.apply(params[0]).divide(functionSin.apply(params[0]));
|
return functionCos.apply(params[0]).divide(functionSin.apply(params[0]));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -514,15 +506,15 @@ public class StandardPlugin extends Plugin {
|
|||||||
/**
|
/**
|
||||||
* The arcsine function (return type in radians).
|
* The arcsine function (return type in radians).
|
||||||
*/
|
*/
|
||||||
public final Function functionArcsin = new Function() {
|
public final NumberFunction functionArcsin = new NumberFunction() {
|
||||||
@Override
|
@Override
|
||||||
protected boolean matchesParams(NumberInterface[] params) {
|
public boolean matchesParams(NumberInterface[] params) {
|
||||||
return params.length == 1
|
return params.length == 1
|
||||||
&& FUNCTION_ABS.apply(params[0]).compareTo(fromInt(params[0].getClass(), 1)) <= 0;
|
&& FUNCTION_ABS.apply(params[0]).compareTo(fromInt(params[0].getClass(), 1)) <= 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected NumberInterface applyInternal(NumberInterface[] params) {
|
public NumberInterface applyInternal(NumberInterface[] params) {
|
||||||
if (FUNCTION_ABS.apply(params[0]).compareTo(new NaiveNumber(0.8).promoteTo(params[0].getClass())) >= 0) {
|
if (FUNCTION_ABS.apply(params[0]).compareTo(new NaiveNumber(0.8).promoteTo(params[0].getClass())) >= 0) {
|
||||||
NumberInterface[] newParams = {FUNCTION_SQRT.apply(fromInt(params[0].getClass(), 1).subtract(params[0].multiply(params[0])))};
|
NumberInterface[] newParams = {FUNCTION_SQRT.apply(fromInt(params[0].getClass(), 1).subtract(params[0].multiply(params[0])))};
|
||||||
return piFor(params[0].getClass()).divide(fromInt(params[0].getClass(), 2))
|
return piFor(params[0].getClass()).divide(fromInt(params[0].getClass(), 2))
|
||||||
@ -547,14 +539,14 @@ public class StandardPlugin extends Plugin {
|
|||||||
/**
|
/**
|
||||||
* The arccosine function.
|
* The arccosine function.
|
||||||
*/
|
*/
|
||||||
public final Function functionArccos = new Function() {
|
public final NumberFunction functionArccos = new NumberFunction() {
|
||||||
@Override
|
@Override
|
||||||
protected boolean matchesParams(NumberInterface[] params) {
|
public boolean matchesParams(NumberInterface[] params) {
|
||||||
return params.length == 1 && FUNCTION_ABS.apply(params[0]).compareTo(fromInt(params[0].getClass(), 1)) <= 0;
|
return params.length == 1 && FUNCTION_ABS.apply(params[0]).compareTo(fromInt(params[0].getClass(), 1)) <= 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected NumberInterface applyInternal(NumberInterface[] params) {
|
public NumberInterface applyInternal(NumberInterface[] params) {
|
||||||
return piFor(params[0].getClass()).divide(fromInt(params[0].getClass(), 2))
|
return piFor(params[0].getClass()).divide(fromInt(params[0].getClass(), 2))
|
||||||
.subtract(functionArcsin.apply(params));
|
.subtract(functionArcsin.apply(params));
|
||||||
}
|
}
|
||||||
@ -563,14 +555,14 @@ public class StandardPlugin extends Plugin {
|
|||||||
/**
|
/**
|
||||||
* The arccosecant function.
|
* The arccosecant function.
|
||||||
*/
|
*/
|
||||||
public final Function functionArccsc = new Function() {
|
public final NumberFunction functionArccsc = new NumberFunction() {
|
||||||
@Override
|
@Override
|
||||||
protected boolean matchesParams(NumberInterface[] params) {
|
public boolean matchesParams(NumberInterface[] params) {
|
||||||
return params.length == 1 && FUNCTION_ABS.apply(params[0]).compareTo(fromInt(params[0].getClass(), 1)) >= 0;
|
return params.length == 1 && FUNCTION_ABS.apply(params[0]).compareTo(fromInt(params[0].getClass(), 1)) >= 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected NumberInterface applyInternal(NumberInterface[] params) {
|
public NumberInterface applyInternal(NumberInterface[] params) {
|
||||||
NumberInterface[] reciprocalParamArr = {fromInt(params[0].getClass(), 1).divide(params[0])};
|
NumberInterface[] reciprocalParamArr = {fromInt(params[0].getClass(), 1).divide(params[0])};
|
||||||
return functionArcsin.apply(reciprocalParamArr);
|
return functionArcsin.apply(reciprocalParamArr);
|
||||||
}
|
}
|
||||||
@ -579,14 +571,14 @@ public class StandardPlugin extends Plugin {
|
|||||||
/**
|
/**
|
||||||
* The arcsecant function.
|
* The arcsecant function.
|
||||||
*/
|
*/
|
||||||
public final Function functionArcsec = new Function() {
|
public final NumberFunction functionArcsec = new NumberFunction() {
|
||||||
@Override
|
@Override
|
||||||
protected boolean matchesParams(NumberInterface[] params) {
|
public boolean matchesParams(NumberInterface[] params) {
|
||||||
return params.length == 1 && FUNCTION_ABS.apply(params[0]).compareTo(fromInt(params[0].getClass(), 1)) >= 0;
|
return params.length == 1 && FUNCTION_ABS.apply(params[0]).compareTo(fromInt(params[0].getClass(), 1)) >= 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected NumberInterface applyInternal(NumberInterface[] params) {
|
public NumberInterface applyInternal(NumberInterface[] params) {
|
||||||
NumberInterface[] reciprocalParamArr = {fromInt(params[0].getClass(), 1).divide(params[0])};
|
NumberInterface[] reciprocalParamArr = {fromInt(params[0].getClass(), 1).divide(params[0])};
|
||||||
return functionArccos.apply(reciprocalParamArr);
|
return functionArccos.apply(reciprocalParamArr);
|
||||||
}
|
}
|
||||||
@ -595,14 +587,14 @@ public class StandardPlugin extends Plugin {
|
|||||||
/**
|
/**
|
||||||
* The arctangent function.
|
* The arctangent function.
|
||||||
*/
|
*/
|
||||||
public final Function functionArctan = new Function() {
|
public final NumberFunction functionArctan = new NumberFunction() {
|
||||||
@Override
|
@Override
|
||||||
protected boolean matchesParams(NumberInterface[] params) {
|
public boolean matchesParams(NumberInterface[] params) {
|
||||||
return params.length == 1;
|
return params.length == 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected NumberInterface applyInternal(NumberInterface[] params) {
|
public NumberInterface applyInternal(NumberInterface[] params) {
|
||||||
if (params[0].signum() == -1) {
|
if (params[0].signum() == -1) {
|
||||||
NumberInterface[] negatedParams = {params[0].negate()};
|
NumberInterface[] negatedParams = {params[0].negate()};
|
||||||
return applyInternal(negatedParams).negate();
|
return applyInternal(negatedParams).negate();
|
||||||
@ -636,14 +628,14 @@ public class StandardPlugin extends Plugin {
|
|||||||
/**
|
/**
|
||||||
* The arccotangent function. Range: (0, pi).
|
* The arccotangent function. Range: (0, pi).
|
||||||
*/
|
*/
|
||||||
public final Function functionArccot = new Function() {
|
public final NumberFunction functionArccot = new NumberFunction() {
|
||||||
@Override
|
@Override
|
||||||
protected boolean matchesParams(NumberInterface[] params) {
|
public boolean matchesParams(NumberInterface[] params) {
|
||||||
return params.length == 1;
|
return params.length == 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected NumberInterface applyInternal(NumberInterface[] params) {
|
public NumberInterface applyInternal(NumberInterface[] params) {
|
||||||
return piFor(params[0].getClass()).divide(fromInt(params[0].getClass(), 2))
|
return piFor(params[0].getClass()).divide(fromInt(params[0].getClass(), 2))
|
||||||
.subtract(functionArctan.apply(params));
|
.subtract(functionArctan.apply(params));
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package org.nwapw.abacus.tree;
|
package org.nwapw.abacus.tree;
|
||||||
|
|
||||||
import org.nwapw.abacus.Abacus;
|
import org.nwapw.abacus.Abacus;
|
||||||
import org.nwapw.abacus.function.Function;
|
import org.nwapw.abacus.function.*;
|
||||||
import org.nwapw.abacus.number.NumberInterface;
|
import org.nwapw.abacus.number.NumberInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -30,25 +30,45 @@ public class NumberReducer implements Reducer<NumberInterface> {
|
|||||||
return abacus.numberFromString(((NumberNode) node).getNumber());
|
return abacus.numberFromString(((NumberNode) node).getNumber());
|
||||||
} else if(node instanceof VariableNode) {
|
} else if(node instanceof VariableNode) {
|
||||||
return abacus.numberFromString("0");
|
return abacus.numberFromString("0");
|
||||||
} else if (node instanceof BinaryNode) {
|
} else if (node instanceof NumberBinaryNode) {
|
||||||
NumberInterface left = (NumberInterface) children[0];
|
NumberInterface left = (NumberInterface) children[0];
|
||||||
NumberInterface right = (NumberInterface) children[1];
|
NumberInterface right = (NumberInterface) children[1];
|
||||||
Function function = abacus.getPluginManager().operatorFor(((BinaryNode) node).getOperation()).getFunction();
|
NumberOperator operator = abacus.getPluginManager().operatorFor(((BinaryNode) node).getOperation());
|
||||||
if (function == null) return null;
|
return operator.apply(left, right);
|
||||||
return function.apply(left, right);
|
} else if (node instanceof NumberUnaryNode) {
|
||||||
} else if (node instanceof UnaryNode) {
|
|
||||||
NumberInterface child = (NumberInterface) children[0];
|
NumberInterface child = (NumberInterface) children[0];
|
||||||
Function functionn = abacus.getPluginManager().operatorFor(((UnaryNode) node).getOperation()).getFunction();
|
NumberOperator operator = abacus.getPluginManager().operatorFor(((UnaryNode) node).getOperation());
|
||||||
if (functionn == null) return null;
|
return operator.apply(child);
|
||||||
return functionn.apply(child);
|
|
||||||
} else if (node instanceof FunctionNode) {
|
} else if (node instanceof FunctionNode) {
|
||||||
NumberInterface[] convertedChildren = new NumberInterface[children.length];
|
NumberInterface[] convertedChildren = new NumberInterface[children.length];
|
||||||
for (int i = 0; i < convertedChildren.length; i++) {
|
for (int i = 0; i < convertedChildren.length; i++) {
|
||||||
convertedChildren[i] = (NumberInterface) children[i];
|
convertedChildren[i] = (NumberInterface) children[i];
|
||||||
}
|
}
|
||||||
Function function = abacus.getPluginManager().functionFor(((FunctionNode) node).getFunction());
|
NumberFunction function = abacus.getPluginManager().functionFor(((FunctionNode) node).getCallTo());
|
||||||
if (function == null) return null;
|
if (function == null) return null;
|
||||||
return function.apply(convertedChildren);
|
return function.apply(convertedChildren);
|
||||||
|
} else if (node instanceof TreeValueFunctionNode){
|
||||||
|
CallNode callNode = (CallNode) node;
|
||||||
|
TreeNode[] realChildren = new TreeNode[callNode.getChildren().size()];
|
||||||
|
for(int i = 0; i < realChildren.length; i++){
|
||||||
|
realChildren[i] = callNode.getChildren().get(i);
|
||||||
|
}
|
||||||
|
TreeValueFunction function =
|
||||||
|
abacus.getPluginManager().treeValueFunctionFor(callNode.getCallTo());
|
||||||
|
if(function == null) return null;
|
||||||
|
return function.applyWithReducer(this, realChildren);
|
||||||
|
} else if (node instanceof TreeValueBinaryNode) {
|
||||||
|
BinaryNode binaryNode = (BinaryNode) node;
|
||||||
|
TreeValueOperator operator = abacus.getPluginManager()
|
||||||
|
.treeValueOperatorFor(binaryNode.getOperation());
|
||||||
|
if(operator == null) return null;
|
||||||
|
return operator.applyWithReducer(this, binaryNode.getLeft(), binaryNode.getRight());
|
||||||
|
} else if(node instanceof TreeValueUnaryNode) {
|
||||||
|
UnaryNode unaryNode = (UnaryNode) node;
|
||||||
|
TreeValueOperator operator = abacus.getPluginManager()
|
||||||
|
.treeValueOperatorFor(unaryNode.getOperation());
|
||||||
|
if(operator == null) return null;
|
||||||
|
return operator.applyWithReducer(this, unaryNode.getApplyTo());
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,8 @@ package org.nwapw.abacus.tree;
|
|||||||
public enum TokenType {
|
public enum TokenType {
|
||||||
|
|
||||||
INTERNAL_FUNCTION_END(-1),
|
INTERNAL_FUNCTION_END(-1),
|
||||||
ANY(0), WHITESPACE(1), COMMA(2), OP(3), NUM(4), VARIABLE(5), FUNCTION(6), OPEN_PARENTH(7), CLOSE_PARENTH(8);
|
ANY(0), WHITESPACE(1), COMMA(2), VARIABLE(3), OP(4), TREE_VALUE_OP(4),
|
||||||
|
NUM(5), FUNCTION(6), TREE_VALUE_FUNCTION(6), OPEN_PARENTH(7), CLOSE_PARENTH(7);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The priority by which this token gets sorted.
|
* The priority by which this token gets sorted.
|
||||||
|
@ -0,0 +1,12 @@
|
|||||||
|
package org.nwapw.abacus.function
|
||||||
|
|
||||||
|
import org.nwapw.abacus.function.applicable.Applicable
|
||||||
|
import org.nwapw.abacus.number.NumberInterface
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A function that operates on numbers.
|
||||||
|
*
|
||||||
|
* This function takes some number of input NumberInterfaces and returns
|
||||||
|
* another NumberInterface as a result.
|
||||||
|
*/
|
||||||
|
abstract class NumberFunction : Applicable<NumberInterface, NumberInterface>
|
@ -0,0 +1,17 @@
|
|||||||
|
package org.nwapw.abacus.function
|
||||||
|
|
||||||
|
import org.nwapw.abacus.function.applicable.Applicable
|
||||||
|
import org.nwapw.abacus.number.NumberInterface
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An operator that operates on NumberImplementations.
|
||||||
|
*
|
||||||
|
* This is simply an alias for Operator<NumberInterface, NumberInterface>.
|
||||||
|
* @param associativity the associativity of the operator.
|
||||||
|
* @param type the type of the operator (binary, unary, etc)
|
||||||
|
* @param precedence the precedence of the operator.
|
||||||
|
*/
|
||||||
|
abstract class NumberOperator(associativity: OperatorAssociativity, type: OperatorType,
|
||||||
|
precedence: Int) :
|
||||||
|
Operator(associativity, type, precedence),
|
||||||
|
Applicable<NumberInterface, NumberInterface>
|
@ -3,12 +3,11 @@ package org.nwapw.abacus.function
|
|||||||
/**
|
/**
|
||||||
* A single operator that can be used by Abacus.
|
* A single operator that can be used by Abacus.
|
||||||
*
|
*
|
||||||
* This is a data class that holds the information about a single operator, such as a plus or minus.
|
* This is a class that holds the information about a single operator, such as a plus or minus.
|
||||||
*
|
*
|
||||||
* @param associativity the associativity of this operator, used for order of operations;.
|
* @param associativity the associativity of this operator, used for order of operations;.
|
||||||
* @param type the type of this operator, used for parsing (infix / prefix / postfix and binary / unary)
|
* @param type the type of this operator, used for parsing (infix / prefix / postfix and binary / unary)
|
||||||
* @param precedence the precedence of this operator, used for order of operations.
|
* @param precedence the precedence of this operator, used for order of operations.
|
||||||
* @param function the function this operator applies to its arguments.
|
|
||||||
*/
|
*/
|
||||||
data class Operator(val associativity: OperatorAssociativity, val type: OperatorType,
|
open class Operator(val associativity: OperatorAssociativity, val type: OperatorType,
|
||||||
val precedence: Int, val function: Function)
|
val precedence: Int)
|
@ -0,0 +1,13 @@
|
|||||||
|
package org.nwapw.abacus.function
|
||||||
|
|
||||||
|
import org.nwapw.abacus.function.applicable.ReducerApplicable
|
||||||
|
import org.nwapw.abacus.number.NumberInterface
|
||||||
|
import org.nwapw.abacus.tree.TreeNode
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A function that operates on trees.
|
||||||
|
*
|
||||||
|
* A function that operates on parse tree nodes instead of on already simplified numbers.
|
||||||
|
* Despite this, it returns a number, not a tree.
|
||||||
|
*/
|
||||||
|
abstract class TreeValueFunction : ReducerApplicable<TreeNode, NumberInterface, NumberInterface>
|
@ -0,0 +1,18 @@
|
|||||||
|
package org.nwapw.abacus.function
|
||||||
|
|
||||||
|
import org.nwapw.abacus.function.applicable.ReducerApplicable
|
||||||
|
import org.nwapw.abacus.number.NumberInterface
|
||||||
|
import org.nwapw.abacus.tree.TreeNode
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An operator that operates on trees.
|
||||||
|
*
|
||||||
|
* This operator operates on parse trees, returning, however a number.
|
||||||
|
* @param associativity the associativity of the operator.
|
||||||
|
* @param type the type of the operator (infix, postfix, etc)
|
||||||
|
* @param precedence the precedence of the operator.
|
||||||
|
*/
|
||||||
|
abstract class TreeValueOperator(associativity: OperatorAssociativity, type: OperatorType,
|
||||||
|
precedence: Int) :
|
||||||
|
Operator(associativity, type, precedence),
|
||||||
|
ReducerApplicable<TreeNode, NumberInterface, NumberInterface>
|
@ -0,0 +1,40 @@
|
|||||||
|
package org.nwapw.abacus.function.applicable
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A class that can be applied to arguments.
|
||||||
|
*
|
||||||
|
* Applicable is a class that represents something that can be applied to one or more
|
||||||
|
* arguments of the same type, and returns a single value from that application.
|
||||||
|
* @param <T> the type of the parameters passed to this applicable.
|
||||||
|
* @param <O> the return type of the applicable.
|
||||||
|
*/
|
||||||
|
interface Applicable<in T : Any, out O : Any> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if the given applicable can be used with the given parameters.
|
||||||
|
* @param params the parameter array to verify for compatibility.
|
||||||
|
* @return whether the array can be used with applyInternal.
|
||||||
|
*/
|
||||||
|
fun matchesParams(params: Array<out T>): Boolean
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Applies the applicable object to the given parameters,
|
||||||
|
* without checking for compatibility.
|
||||||
|
* @param params the parameters to apply to.
|
||||||
|
* @return the result of the application.
|
||||||
|
*/
|
||||||
|
fun applyInternal(params: Array<out T>): O?
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If the parameters can be used with this applicable, returns
|
||||||
|
* the result of the application of the applicable to the parameters.
|
||||||
|
* Otherwise, returns null.
|
||||||
|
* @param params the parameters to apply to.
|
||||||
|
* @return the result of the operation, or null if parameters do not match.
|
||||||
|
*/
|
||||||
|
fun apply(vararg params: T): O? {
|
||||||
|
if (!matchesParams(params)) return null
|
||||||
|
return applyInternal(params)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,43 @@
|
|||||||
|
package org.nwapw.abacus.function.applicable
|
||||||
|
|
||||||
|
import org.nwapw.abacus.tree.Reducer
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Applicable that requires a reducer.
|
||||||
|
*
|
||||||
|
* ReducerApplicable slightly more specific Applicable that requires a reducer
|
||||||
|
* to be passed to it along with the parameters.
|
||||||
|
* @param <T> the type of the input arguments.
|
||||||
|
* @param <O> the return type of the application.
|
||||||
|
* @param <R> the required type of the reducer.
|
||||||
|
*/
|
||||||
|
interface ReducerApplicable<in T : Any, out O : Any, in R : Any> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if this applicable can be applied to the
|
||||||
|
* given parameters.
|
||||||
|
* @param params the parameters to check.
|
||||||
|
*/
|
||||||
|
fun matchesParams(params: Array<out T>): Boolean
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Applies this applicable to the given arguments, and reducer.
|
||||||
|
* @param reducer the reducer to use in the application.
|
||||||
|
* @param params the arguments to apply to.
|
||||||
|
* @return the result of the application.
|
||||||
|
*/
|
||||||
|
fun applyWithReducerInternal(reducer: Reducer<R>, params: Array<out T>): O?
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Applies this applicable to the given arguments, and reducer,
|
||||||
|
* if the arguments and reducer are compatible with this applicable.
|
||||||
|
* @param reducer the reducer to use in the application.
|
||||||
|
* @param params the arguments to apply to.
|
||||||
|
* @return the result of the application, or null if the arguments are incompatible.
|
||||||
|
*/
|
||||||
|
fun applyWithReducer(reducer: Reducer<R>, vararg params: T): O? {
|
||||||
|
if (!matchesParams(params)) return null
|
||||||
|
return applyWithReducerInternal(reducer, params)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -11,13 +11,7 @@ package org.nwapw.abacus.tree
|
|||||||
* @param left the left node.
|
* @param left the left node.
|
||||||
* @param right the right node.
|
* @param right the right node.
|
||||||
*/
|
*/
|
||||||
data class BinaryNode(val operation: String, val left: TreeNode? = null, val right: TreeNode?) : TreeNode() {
|
abstract class BinaryNode(val operation: String, val left: TreeNode? = null, val right: TreeNode?) : TreeNode() {
|
||||||
|
|
||||||
override fun <T : Any> reduce(reducer: Reducer<T>): T? {
|
|
||||||
val leftReduce = left?.reduce(reducer) ?: return null
|
|
||||||
val rightReduce = right?.reduce(reducer) ?: return null
|
|
||||||
return reducer.reduceNode(this, leftReduce, rightReduce)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun toString(): String {
|
override fun toString(): String {
|
||||||
return "(" + (left?.toString() ?: "null") + operation + (right?.toString() ?: "null") + ")"
|
return "(" + (left?.toString() ?: "null") + operation + (right?.toString() ?: "null") + ")"
|
||||||
|
29
core/src/main/kotlin/org/nwapw/abacus/tree/CallNode.kt
Normal file
29
core/src/main/kotlin/org/nwapw/abacus/tree/CallNode.kt
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
package org.nwapw.abacus.tree
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents a more generic function call.
|
||||||
|
*
|
||||||
|
* This class does not specify how it should be reduced, allowing other classes
|
||||||
|
* to extend this functionality.
|
||||||
|
*
|
||||||
|
* @param callTo the name of the things being called.
|
||||||
|
*/
|
||||||
|
abstract class CallNode(val callTo: String) : TreeNode() {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The list of children this node has.
|
||||||
|
*/
|
||||||
|
val children: MutableList<TreeNode> = mutableListOf()
|
||||||
|
|
||||||
|
override fun toString(): String {
|
||||||
|
val buffer = StringBuffer()
|
||||||
|
buffer.append(callTo)
|
||||||
|
buffer.append("(")
|
||||||
|
for (i in 0 until children.size) {
|
||||||
|
buffer.append(children[i].toString())
|
||||||
|
buffer.append(if (i != children.size - 1) ", " else ")")
|
||||||
|
}
|
||||||
|
return buffer.toString()
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -8,45 +8,11 @@ package org.nwapw.abacus.tree
|
|||||||
*
|
*
|
||||||
* @param function the function string.
|
* @param function the function string.
|
||||||
*/
|
*/
|
||||||
data class FunctionNode(val function: String) : TreeNode() {
|
class FunctionNode(function: String) : CallNode(function) {
|
||||||
|
|
||||||
/**
|
|
||||||
* List of function parameters added to this node.
|
|
||||||
*/
|
|
||||||
val children: MutableList<TreeNode> = mutableListOf()
|
|
||||||
|
|
||||||
override fun <T : Any> reduce(reducer: Reducer<T>): T? {
|
override fun <T : Any> reduce(reducer: Reducer<T>): T? {
|
||||||
val children = Array<Any>(children.size, { children[it].reduce(reducer) ?: return null; })
|
val children = Array<Any>(children.size, { children[it].reduce(reducer) ?: return null; })
|
||||||
return reducer.reduceNode(this, *children)
|
return reducer.reduceNode(this, *children)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun toString(): String {
|
|
||||||
val buffer = StringBuffer()
|
|
||||||
buffer.append(function)
|
|
||||||
buffer.append('(')
|
|
||||||
for (i in 0 until children.size) {
|
|
||||||
buffer.append(children[i].toString())
|
|
||||||
buffer.append(if (i == children.size - 1) ")" else ",")
|
|
||||||
}
|
|
||||||
return buffer.toString()
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Appends a child to this node's list of children.
|
|
||||||
*
|
|
||||||
* @node the node to append.
|
|
||||||
*/
|
|
||||||
fun appendChild(node: TreeNode) {
|
|
||||||
children.add(node)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Prepends a child to this node's list of children.
|
|
||||||
*
|
|
||||||
* @node the node to prepend.
|
|
||||||
*/
|
|
||||||
fun prependChild(node: TreeNode) {
|
|
||||||
children.add(0, node)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
@ -0,0 +1,22 @@
|
|||||||
|
package org.nwapw.abacus.tree
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A binary operator node that reduces its children.
|
||||||
|
*
|
||||||
|
* NumberBinaryNode operates by simply reducing its children and
|
||||||
|
* then using the result of that reduction to reduce itself.
|
||||||
|
*
|
||||||
|
* @param operation the operation this node performs.
|
||||||
|
* @param left the left child of this node.
|
||||||
|
* @param right the right child of this node.
|
||||||
|
*/
|
||||||
|
class NumberBinaryNode(operation: String, left: TreeNode?, right: TreeNode?)
|
||||||
|
: BinaryNode(operation, left, right) {
|
||||||
|
|
||||||
|
override fun <T : Any> reduce(reducer: Reducer<T>): T? {
|
||||||
|
val left = left?.reduce(reducer) ?: return null
|
||||||
|
val right = right?.reduce(reducer) ?: return null
|
||||||
|
return reducer.reduceNode(this, left, right)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,7 +1,5 @@
|
|||||||
package org.nwapw.abacus.tree
|
package org.nwapw.abacus.tree
|
||||||
|
|
||||||
import org.nwapw.abacus.number.NumberInterface
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A tree node that holds a single number value.
|
* A tree node that holds a single number value.
|
||||||
*
|
*
|
||||||
@ -10,7 +8,7 @@ import org.nwapw.abacus.number.NumberInterface
|
|||||||
*
|
*
|
||||||
* @number the number value of this node.
|
* @number the number value of this node.
|
||||||
*/
|
*/
|
||||||
data class NumberNode(val number: String) : TreeNode() {
|
class NumberNode(val number: String) : TreeNode() {
|
||||||
|
|
||||||
override fun <T : Any> reduce(reducer: Reducer<T>): T? {
|
override fun <T : Any> reduce(reducer: Reducer<T>): T? {
|
||||||
return reducer.reduceNode(this)
|
return reducer.reduceNode(this)
|
||||||
|
@ -0,0 +1,19 @@
|
|||||||
|
package org.nwapw.abacus.tree
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A unary operator node that reduces its children.
|
||||||
|
*
|
||||||
|
* NumberUnaryNode operates by simply reducing its child,
|
||||||
|
* and using the result of that reduction to reduce itself.
|
||||||
|
* @param operation the operation this node performs.
|
||||||
|
* @param child the child this node should be applied to.
|
||||||
|
*/
|
||||||
|
class NumberUnaryNode(operation: String, child: TreeNode?)
|
||||||
|
: UnaryNode(operation, child) {
|
||||||
|
|
||||||
|
override fun <T : Any> reduce(reducer: Reducer<T>): T? {
|
||||||
|
val child = applyTo?.reduce(reducer) ?: return null
|
||||||
|
return reducer.reduceNode(this, child)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,21 @@
|
|||||||
|
package org.nwapw.abacus.tree
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A tree node that represents a binary tree value operator.
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* The tree value operators operate on trees, and so this
|
||||||
|
* node does not reduce its children. It is up to the implementation to handle
|
||||||
|
* reduction.
|
||||||
|
* @param operation the operation this node performs.
|
||||||
|
* @param left the left child of this node.
|
||||||
|
* @param right the right child of this node.
|
||||||
|
*/
|
||||||
|
class TreeValueBinaryNode(operation: String, left: TreeNode?, right: TreeNode?)
|
||||||
|
: BinaryNode(operation, left, right) {
|
||||||
|
|
||||||
|
override fun <T : Any> reduce(reducer: Reducer<T>): T? {
|
||||||
|
return reducer.reduceNode(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,16 @@
|
|||||||
|
package org.nwapw.abacus.tree
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A tree node that represents a tree value function call.
|
||||||
|
*
|
||||||
|
* This is in many ways similar to a simple FunctionNode, and the distinction
|
||||||
|
* is mostly to help the reducer. Besides that, this class also does not
|
||||||
|
* even attempt to reduce its children.
|
||||||
|
*/
|
||||||
|
class TreeValueFunctionNode(name: String) : CallNode(name) {
|
||||||
|
|
||||||
|
override fun <T : Any> reduce(reducer: Reducer<T>): T? {
|
||||||
|
return reducer.reduceNode(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,19 @@
|
|||||||
|
package org.nwapw.abacus.tree
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A tree node that represents a unary tree value operator.
|
||||||
|
*
|
||||||
|
* The tree value operators operate on trees, and so this
|
||||||
|
* node does not reduce its children. It is up to the implementation to handle
|
||||||
|
* reduction.
|
||||||
|
* @param operation the operation this node performs.
|
||||||
|
* @param child the node the operation should be applied to.
|
||||||
|
*/
|
||||||
|
class TreeValueUnaryNode(operation: String, child: TreeNode?)
|
||||||
|
: UnaryNode(operation, child) {
|
||||||
|
|
||||||
|
override fun <T : Any> reduce(reducer: Reducer<T>): T? {
|
||||||
|
return reducer.reduceNode(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -9,12 +9,7 @@ package org.nwapw.abacus.tree
|
|||||||
* @param operation the operation applied to the given node.
|
* @param operation the operation applied to the given node.
|
||||||
* @param applyTo the node to which the operation will be applied.
|
* @param applyTo the node to which the operation will be applied.
|
||||||
*/
|
*/
|
||||||
data class UnaryNode(val operation: String, val applyTo: TreeNode? = null) : TreeNode() {
|
abstract class UnaryNode(val operation: String, val applyTo: TreeNode? = null) : TreeNode() {
|
||||||
|
|
||||||
override fun <T : Any> reduce(reducer: Reducer<T>): T? {
|
|
||||||
val reducedChild = applyTo?.reduce(reducer) ?: return null
|
|
||||||
return reducer.reduceNode(this, reducedChild)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun toString(): String {
|
override fun toString(): String {
|
||||||
return "(" + (applyTo?.toString() ?: "null") + ")" + operation
|
return "(" + (applyTo?.toString() ?: "null") + ")" + operation
|
||||||
|
@ -8,7 +8,7 @@ package org.nwapw.abacus.tree
|
|||||||
*
|
*
|
||||||
* @param variable the actual variable name that this node represents.
|
* @param variable the actual variable name that this node represents.
|
||||||
*/
|
*/
|
||||||
data class VariableNode(val variable: String) : TreeNode() {
|
class VariableNode(val variable: String) : TreeNode() {
|
||||||
|
|
||||||
override fun <T : Any> reduce(reducer: Reducer<T>): T? {
|
override fun <T : Any> reduce(reducer: Reducer<T>): T? {
|
||||||
return reducer.reduceNode(this)
|
return reducer.reduceNode(this)
|
||||||
|
@ -5,10 +5,7 @@ import org.junit.BeforeClass;
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.nwapw.abacus.Abacus;
|
import org.nwapw.abacus.Abacus;
|
||||||
import org.nwapw.abacus.config.Configuration;
|
import org.nwapw.abacus.config.Configuration;
|
||||||
import org.nwapw.abacus.function.Function;
|
import org.nwapw.abacus.function.*;
|
||||||
import org.nwapw.abacus.function.Operator;
|
|
||||||
import org.nwapw.abacus.function.OperatorAssociativity;
|
|
||||||
import org.nwapw.abacus.function.OperatorType;
|
|
||||||
import org.nwapw.abacus.lexing.pattern.Match;
|
import org.nwapw.abacus.lexing.pattern.Match;
|
||||||
import org.nwapw.abacus.number.NumberInterface;
|
import org.nwapw.abacus.number.NumberInterface;
|
||||||
import org.nwapw.abacus.parsing.LexerTokenizer;
|
import org.nwapw.abacus.parsing.LexerTokenizer;
|
||||||
@ -21,24 +18,46 @@ public class TokenizerTests {
|
|||||||
|
|
||||||
private static Abacus abacus = new Abacus(new Configuration(0, "precise", new String[]{}));
|
private static Abacus abacus = new Abacus(new Configuration(0, "precise", new String[]{}));
|
||||||
private static LexerTokenizer lexerTokenizer = new LexerTokenizer();
|
private static LexerTokenizer lexerTokenizer = new LexerTokenizer();
|
||||||
private static Function subtractFunction = new Function() {
|
private static NumberFunction subtractFunction = new NumberFunction() {
|
||||||
@Override
|
@Override
|
||||||
protected boolean matchesParams(NumberInterface[] params) {
|
public boolean matchesParams(NumberInterface[] params) {
|
||||||
return params.length == 2;
|
return params.length == 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected NumberInterface applyInternal(NumberInterface[] params) {
|
public NumberInterface applyInternal(NumberInterface[] params) {
|
||||||
return params[0].subtract(params[1]);
|
return params[0].subtract(params[1]);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
private static Plugin testPlugin = new Plugin(abacus.getPluginManager()) {
|
private static Plugin testPlugin = new Plugin(abacus.getPluginManager()) {
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
registerOperator("+", new Operator(OperatorAssociativity.LEFT, OperatorType.BINARY_INFIX,
|
registerOperator("+", new NumberOperator(OperatorAssociativity.LEFT, OperatorType.BINARY_INFIX,
|
||||||
0, subtractFunction));
|
0) {
|
||||||
registerOperator("-", new Operator(OperatorAssociativity.LEFT, OperatorType.BINARY_INFIX,
|
|
||||||
0, subtractFunction));
|
@Override
|
||||||
|
public boolean matchesParams(NumberInterface[] params) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NumberInterface applyInternal(NumberInterface[] params) {
|
||||||
|
return subtractFunction.apply(params);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
registerOperator("-", new NumberOperator(OperatorAssociativity.LEFT, OperatorType.BINARY_INFIX,
|
||||||
|
0) {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean matchesParams(NumberInterface[] params) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NumberInterface applyInternal(NumberInterface[] params) {
|
||||||
|
return subtractFunction.apply(params);
|
||||||
|
}
|
||||||
|
});
|
||||||
registerFunction("subtract", subtractFunction);
|
registerFunction("subtract", subtractFunction);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -360,6 +360,8 @@ public class AbacusController implements PluginListener {
|
|||||||
PluginManager pluginManager = abacus.getPluginManager();
|
PluginManager pluginManager = abacus.getPluginManager();
|
||||||
functionList.addAll(manager.getAllFunctions().stream().map(name -> pluginManager.documentationFor(name, DocumentationType.FUNCTION))
|
functionList.addAll(manager.getAllFunctions().stream().map(name -> pluginManager.documentationFor(name, DocumentationType.FUNCTION))
|
||||||
.collect(Collectors.toCollection(ArrayList::new)));
|
.collect(Collectors.toCollection(ArrayList::new)));
|
||||||
|
functionList.addAll(manager.getAllTreeValueFunctions().stream().map(name -> pluginManager.documentationFor(name, DocumentationType.TREE_VALUE_FUNCTION))
|
||||||
|
.collect(Collectors.toCollection(ArrayList::new)));
|
||||||
functionList.sort(Comparator.comparing(Documentation::getCodeName));
|
functionList.sort(Comparator.comparing(Documentation::getCodeName));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user