MCPcopy Index your code
hub / github.com/Aghajari/MathParser / MathFunction

Interface MathFunction

MathParser/src/com/aghajari/math/MathFunction.java:30–191  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

28import java.util.List;
29
30public interface MathFunction {
31
32 /**
33 * @return the name of function
34 */
35 String name();
36
37 /**
38 * @return True if name mentions this function
39 */
40 boolean compareNames(String name);
41
42 /**
43 * Calculates and returns the value
44 * Parameters are usually double values
45 */
46 double calculate(Object... parameters) throws MathParserException;
47
48 int getParameterCount();
49
50 /**
51 * @return True if the parameter at specified index won't be a double value (String otherwise)
52 */
53 boolean isSpecialParameter(int index);
54
55 /**
56 * Calls when this function just attached to a parser or it's parent variable called to calculate
57 */
58 void attachToParser(MathParser parser);
59
60 static MathFunction wrap(final Method method) {
61 return wrap(method, method.getName());
62 }
63
64 static MathFunction wrap(final Method method, final String name) {
65 return new MathFunction() {
66
67 MathParser parser = null;
68
69 @Override
70 public String name() {
71 return name;
72 }
73
74 @Override
75 public boolean compareNames(String name) {
76 return name().trim().equalsIgnoreCase(name.trim());
77 }
78
79 @Override
80 public double calculate(Object... parameters) throws MathParserException {
81 try {
82 List<Object> pars = new ArrayList<>();
83 if (method.getParameterTypes()[0] == MathParser.class)
84 pars.add(parser);
85 if (getParameterCount() == -1) {
86 pars.add(parameters);
87 } else {

Callers 14

toStringMethod · 0.65
getFunctionMethod · 0.65
getAnswerMethod · 0.65
calculateMethod · 0.65
addFunctionsMethod · 0.65
getFunctionMethod · 0.65
calculateMethod · 0.95
calculateMethod · 0.95
getAnswerMethod · 0.65
addExpressionMethod · 0.95

Implementers 2

LogFunctionMathParser/src/com/aghajari/math/custo
RadicalFunctionMathParser/src/com/aghajari/math/custo

Calls

no outgoing calls

Tested by

no test coverage detected