functions

This commit is contained in:
Sergey Solovyev
2012-11-14 21:44:23 +04:00
parent 357eed9f3e
commit 75a3a72a84
15 changed files with 342 additions and 110 deletions

View File

@@ -16,6 +16,7 @@ import org.solovyev.android.calculator.model.MathEntityBuilder;
import org.solovyev.common.JBuilder;
import org.solovyev.common.math.MathRegistry;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
@@ -96,7 +97,7 @@ public class CalculatorFunctionsMathRegistry extends AbstractCalculatorMathRegis
final AFunction result = new AFunction();
result.setName(entity.getName());
result.setContent(((CustomFunction) entity).getContent());
result.setParameterNames(((CustomFunction) entity).getParameterNames());
result.setParameterNames(new ArrayList<String>(((CustomFunction) entity).getParameterNames()));
return result;
} else {
return null;

View File

@@ -72,12 +72,6 @@ public class ToJsclTextProcessor implements TextProcessor<PreparedExpression, St
}
}
if (mathTypeBefore != null &&
(mathTypeBefore.getMathType() == MathType.function || mathTypeBefore.getMathType() == MathType.operator) &&
CollectionsUtils.find(MathType.openGroupSymbols, startsWithFinder) != null) {
throw new CalculatorParseException(i, s, new CalculatorMessage(CalculatorMessages.msg_005, MessageType.error, mathTypeBefore.getMatch()));
}
i = mathTypeResult.processToJscl(result, i);
}
return result;

View File

@@ -6,16 +6,18 @@
package org.solovyev.android.calculator.model;
import jscl.math.function.IConstant;
import jscl.math.function.IFunction;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.simpleframework.xml.Element;
import org.simpleframework.xml.ElementList;
import org.simpleframework.xml.Root;
import org.simpleframework.xml.Transient;
import org.solovyev.android.calculator.MathPersistenceEntity;
import org.solovyev.common.math.MathEntity;
import org.solovyev.common.text.StringUtils;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@@ -25,7 +27,7 @@ import java.util.List;
* Time: 5:25 PM
*/
@Root
@Root(name = "function")
public class AFunction implements IFunction, MathPersistenceEntity {
/*
@@ -42,20 +44,20 @@ public class AFunction implements IFunction, MathPersistenceEntity {
@NotNull
private String name;
@Element
@Element(name = "body")
@NotNull
private String content;
@Element(required = false)
@ElementList
@NotNull
private List<String> parameterNames = Collections.emptyList();
private List<String> parameterNames = new ArrayList<String>();
@Element
private boolean system;
@Element(required = false)
@Nullable
private String description;
@NotNull
private String description = "";
/*
**********************************************************************
@@ -86,7 +88,7 @@ public class AFunction implements IFunction, MathPersistenceEntity {
final IFunction that = ((IFunction) mathEntity);
this.name = that.getName();
this.content = that.getContent();
this.description = this.getContent();
this.description = StringUtils.getNotEmpty(this.getDescription(), "");
this.system = that.isSystem();
if (that.isIdDefined()) {
this.id = that.getId();
@@ -104,7 +106,7 @@ public class AFunction implements IFunction, MathPersistenceEntity {
/*
**********************************************************************
*
* GETTERS/SEETTERS
* GETTERS/SETTERS
*
**********************************************************************
*/
@@ -144,8 +146,8 @@ public class AFunction implements IFunction, MathPersistenceEntity {
return content;
}
@Nullable
@Override
@NotNull
@Override
public String getDescription() {
return this.description;
}
@@ -201,29 +203,15 @@ public class AFunction implements IFunction, MathPersistenceEntity {
this.id = function.getId();
}
public Builder(@NotNull IConstant function) {
this.name = function.getName();
public Builder(@NotNull String name,
@NotNull String value,
@NotNull List<String> parameterNames) {
this.name = name;
this.value = value;
this.parameterNames = parameterNames;
}
this.value = function.getValue();
this.system = function.isSystem();
this.description = function.getDescription();
if (function.isIdDefined()) {
this.id = function.getId();
}
}
public Builder(@NotNull String name, @NotNull Double value) {
this(name, String.valueOf(value));
}
public Builder(@NotNull String name, @Nullable String value) {
this.name = name;
this.value = value;
}
@NotNull
@NotNull
public Builder setName(@NotNull String name) {
this.name = name;
return this;
@@ -262,8 +250,8 @@ public class AFunction implements IFunction, MathPersistenceEntity {
result.name = name;
result.content = value;
result.system = system;
result.description = description;
result.parameterNames = parameterNames;
result.description = StringUtils.getNotEmpty(description, "");
result.parameterNames = new ArrayList<String>(parameterNames);
return result;
}