Module separation
This commit is contained in:
parent
33db715776
commit
417cf88912
@ -30,6 +30,11 @@
|
|||||||
<artifactId>annotations</artifactId>
|
<artifactId>annotations</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.solovyev</groupId>
|
||||||
|
<artifactId>jscl</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
|
||||||
|
@ -0,0 +1,16 @@
|
|||||||
|
package org.solovyev.android.calculator;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* User: Solovyev_S
|
||||||
|
* Date: 20.09.12
|
||||||
|
* Time: 12:45
|
||||||
|
*/
|
||||||
|
public interface CalculatorLocator {
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
JCalculatorEngine getCalculatorEngine();
|
||||||
|
|
||||||
|
void setCalculatorEngine(@NotNull JCalculatorEngine calculatorEngine);
|
||||||
|
}
|
@ -0,0 +1,36 @@
|
|||||||
|
package org.solovyev.android.calculator;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* User: Solovyev_S
|
||||||
|
* Date: 20.09.12
|
||||||
|
* Time: 12:45
|
||||||
|
*/
|
||||||
|
public class CalculatorLocatorImpl implements CalculatorLocator {
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private JCalculatorEngine calculatorEngine;
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private static final CalculatorLocator instance = new CalculatorLocatorImpl();
|
||||||
|
|
||||||
|
private CalculatorLocatorImpl() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public static CalculatorLocator getInstance() {
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public JCalculatorEngine getCalculatorEngine() {
|
||||||
|
return calculatorEngine;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setCalculatorEngine(@NotNull JCalculatorEngine calculatorEngine) {
|
||||||
|
this.calculatorEngine = calculatorEngine;
|
||||||
|
}
|
||||||
|
}
|
@ -4,7 +4,7 @@
|
|||||||
* or visit http://se.solovyev.org
|
* or visit http://se.solovyev.org
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.solovyev.android.calculator.history;
|
package org.solovyev.android.calculator;
|
||||||
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
@ -9,7 +9,7 @@ package org.solovyev.android.calculator;
|
|||||||
import jscl.math.Generic;
|
import jscl.math.Generic;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.solovyev.android.calculator.history.Editor;
|
import org.solovyev.android.calculator.Editor;
|
||||||
import org.solovyev.android.calculator.jscl.JsclOperation;
|
import org.solovyev.android.calculator.jscl.JsclOperation;
|
||||||
|
|
||||||
/**
|
/**
|
@ -0,0 +1,34 @@
|
|||||||
|
package org.solovyev.android.calculator;
|
||||||
|
|
||||||
|
import jscl.MathEngine;
|
||||||
|
import jscl.math.function.Function;
|
||||||
|
import jscl.math.function.IConstant;
|
||||||
|
import jscl.math.operator.Operator;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.solovyev.common.math.MathRegistry;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* User: Solovyev_S
|
||||||
|
* Date: 20.09.12
|
||||||
|
* Time: 12:43
|
||||||
|
*/
|
||||||
|
public interface JCalculatorEngine {
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
String getMultiplicationSign();
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
MathRegistry<IConstant> getVarsRegistry();
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
MathRegistry<Function> getFunctionsRegistry();
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
MathRegistry<Operator> getOperatorsRegistry();
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
MathRegistry<Operator> getPostfixFunctionsRegistry();
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
MathEngine getEngine();
|
||||||
|
}
|
@ -9,7 +9,7 @@ package org.solovyev.android.calculator.jscl;
|
|||||||
import jscl.math.Generic;
|
import jscl.math.Generic;
|
||||||
import jscl.text.ParseException;
|
import jscl.text.ParseException;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.solovyev.android.calculator.model.CalculatorEngine;
|
import org.solovyev.android.calculator.CalculatorLocatorImpl;
|
||||||
import org.solovyev.android.calculator.model.DummyTextProcessor;
|
import org.solovyev.android.calculator.model.DummyTextProcessor;
|
||||||
import org.solovyev.android.calculator.model.FromJsclSimplifyTextProcessor;
|
import org.solovyev.android.calculator.model.FromJsclSimplifyTextProcessor;
|
||||||
import org.solovyev.android.calculator.model.TextProcessor;
|
import org.solovyev.android.calculator.model.TextProcessor;
|
||||||
@ -42,11 +42,11 @@ public enum JsclOperation {
|
|||||||
public final String evaluate(@NotNull String expression) throws ParseException {
|
public final String evaluate(@NotNull String expression) throws ParseException {
|
||||||
switch (this) {
|
switch (this) {
|
||||||
case simplify:
|
case simplify:
|
||||||
return CalculatorEngine.instance.getEngine().simplify(expression);
|
return CalculatorLocatorImpl.getInstance().getCalculatorEngine().getEngine().simplify(expression);
|
||||||
case elementary:
|
case elementary:
|
||||||
return CalculatorEngine.instance.getEngine().elementary(expression);
|
return CalculatorLocatorImpl.getInstance().getCalculatorEngine().getEngine().elementary(expression);
|
||||||
case numeric:
|
case numeric:
|
||||||
return CalculatorEngine.instance.getEngine().evaluate(expression);
|
return CalculatorLocatorImpl.getInstance().getCalculatorEngine().getEngine().evaluate(expression);
|
||||||
default:
|
default:
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
@ -56,11 +56,11 @@ public enum JsclOperation {
|
|||||||
public final Generic evaluateGeneric(@NotNull String expression) throws ParseException {
|
public final Generic evaluateGeneric(@NotNull String expression) throws ParseException {
|
||||||
switch (this) {
|
switch (this) {
|
||||||
case simplify:
|
case simplify:
|
||||||
return CalculatorEngine.instance.getEngine().simplifyGeneric(expression);
|
return CalculatorLocatorImpl.getInstance().getCalculatorEngine().getEngine().simplifyGeneric(expression);
|
||||||
case elementary:
|
case elementary:
|
||||||
return CalculatorEngine.instance.getEngine().elementaryGeneric(expression);
|
return CalculatorLocatorImpl.getInstance().getCalculatorEngine().getEngine().elementaryGeneric(expression);
|
||||||
case numeric:
|
case numeric:
|
||||||
return CalculatorEngine.instance.getEngine().evaluateGeneric(expression);
|
return CalculatorLocatorImpl.getInstance().getCalculatorEngine().getEngine().evaluateGeneric(expression);
|
||||||
default:
|
default:
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
@ -10,9 +10,9 @@ import jscl.NumeralBase;
|
|||||||
import jscl.math.function.Constants;
|
import jscl.math.function.Constants;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import org.solovyev.android.calculator.CalculatorLocatorImpl;
|
||||||
import org.solovyev.common.JPredicate;
|
import org.solovyev.common.JPredicate;
|
||||||
import org.solovyev.common.StartsWithFinder;
|
import org.solovyev.common.StartsWithFinder;
|
||||||
import org.solovyev.android.calculator.model.CalculatorEngine;
|
|
||||||
import org.solovyev.android.calculator.model.CalculatorParseException;
|
import org.solovyev.android.calculator.model.CalculatorParseException;
|
||||||
import org.solovyev.common.collections.CollectionsUtils;
|
import org.solovyev.common.collections.CollectionsUtils;
|
||||||
|
|
||||||
@ -26,11 +26,8 @@ public enum MathType {
|
|||||||
private final List<String> tokens = new ArrayList<String>(10);
|
private final List<String> tokens = new ArrayList<String>(10);
|
||||||
{
|
{
|
||||||
for (NumeralBase numeralBase : NumeralBase.values()) {
|
for (NumeralBase numeralBase : NumeralBase.values()) {
|
||||||
final String jsclPrefix = numeralBase.getJsclPrefix();
|
tokens.add(numeralBase.getJsclPrefix());
|
||||||
if (jsclPrefix != null) {
|
}
|
||||||
tokens.add(jsclPrefix);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@ -60,7 +57,7 @@ public enum MathType {
|
|||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public List<String> getTokens() {
|
public List<String> getTokens() {
|
||||||
return CalculatorEngine.instance.getPostfixFunctionsRegistry().getNames();
|
return CalculatorLocatorImpl.getInstance().getCalculatorEngine().getPostfixFunctionsRegistry().getNames();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -104,7 +101,7 @@ public enum MathType {
|
|||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public List<String> getTokens() {
|
public List<String> getTokens() {
|
||||||
return CalculatorEngine.instance.getFunctionsRegistry().getNames();
|
return CalculatorLocatorImpl.getInstance().getCalculatorEngine().getFunctionsRegistry().getNames();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -112,7 +109,7 @@ public enum MathType {
|
|||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public List<String> getTokens() {
|
public List<String> getTokens() {
|
||||||
return CalculatorEngine.instance.getOperatorsRegistry().getNames();
|
return CalculatorLocatorImpl.getInstance().getCalculatorEngine().getOperatorsRegistry().getNames();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -120,7 +117,7 @@ public enum MathType {
|
|||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public List<String> getTokens() {
|
public List<String> getTokens() {
|
||||||
return CalculatorEngine.instance.getVarsRegistry().getNames();
|
return CalculatorLocatorImpl.getInstance().getCalculatorEngine().getVarsRegistry().getNames();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
@ -6,10 +6,8 @@
|
|||||||
|
|
||||||
package org.solovyev.android.calculator.model;
|
package org.solovyev.android.calculator.model;
|
||||||
|
|
||||||
import android.app.Application;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.solovyev.android.msg.AndroidMessage;
|
|
||||||
import org.solovyev.common.exceptions.SersoException;
|
import org.solovyev.common.exceptions.SersoException;
|
||||||
import org.solovyev.common.msg.Message;
|
import org.solovyev.common.msg.Message;
|
||||||
import org.solovyev.common.msg.MessageType;
|
import org.solovyev.common.msg.MessageType;
|
||||||
@ -39,14 +37,17 @@ public class CalculatorParseException extends SersoException implements Message
|
|||||||
this.position = jsclParseException.getPosition();
|
this.position = jsclParseException.getPosition();
|
||||||
}
|
}
|
||||||
|
|
||||||
public CalculatorParseException(@NotNull Integer messageId, @NotNull Application application, @Nullable Integer position, @NotNull String expression, Object... parameters) {
|
public CalculatorParseException(@Nullable Integer position,
|
||||||
this.message = new AndroidMessage(messageId, MessageType.error, application, parameters);
|
@NotNull String expression,
|
||||||
|
@NotNull Message message) {
|
||||||
|
this.message = message;
|
||||||
this.expression = expression;
|
this.expression = expression;
|
||||||
this.position = position;
|
this.position = position;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CalculatorParseException(@NotNull Integer messageId, @NotNull Application application, @NotNull String expression, Object... parameters) {
|
public CalculatorParseException(@NotNull String expression,
|
||||||
this(messageId, application, null, expression, parameters);
|
@NotNull Message message) {
|
||||||
|
this(null, expression, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
@ -3,6 +3,8 @@ package org.solovyev.android.calculator.model;
|
|||||||
import jscl.math.Generic;
|
import jscl.math.Generic;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import org.solovyev.android.calculator.CalculatorLocator;
|
||||||
|
import org.solovyev.android.calculator.CalculatorLocatorImpl;
|
||||||
import org.solovyev.android.calculator.math.MathType;
|
import org.solovyev.android.calculator.math.MathType;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
@ -55,7 +57,7 @@ public class FromJsclSimplifyTextProcessor implements TextProcessor<String, Gene
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (needMultiplicationSign(mathTypeBefore == null ? null : mathTypeBefore.getMathType(), mathTypeAfter == null ? null : mathTypeAfter.getMathType())) {
|
if (needMultiplicationSign(mathTypeBefore == null ? null : mathTypeBefore.getMathType(), mathTypeAfter == null ? null : mathTypeAfter.getMathType())) {
|
||||||
sb.append(CalculatorEngine.instance.getMultiplicationSign());
|
sb.append(CalculatorLocatorImpl.getInstance().getCalculatorEngine().getMultiplicationSign());
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
@ -82,13 +82,6 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.solovyev</groupId>
|
<groupId>org.solovyev</groupId>
|
||||||
<artifactId>jscl</artifactId>
|
<artifactId>jscl</artifactId>
|
||||||
<version>0.0.2</version>
|
|
||||||
<exclusions>
|
|
||||||
<exclusion>
|
|
||||||
<artifactId>xercesImpl</artifactId>
|
|
||||||
<groupId>xerces</groupId>
|
|
||||||
</exclusion>
|
|
||||||
</exclusions>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!--OTHER-->
|
<!--OTHER-->
|
||||||
|
@ -46,6 +46,8 @@ public class CalculatorApplication extends android.app.Application {
|
|||||||
public void onCreate() {
|
public void onCreate() {
|
||||||
super.onCreate();
|
super.onCreate();
|
||||||
|
|
||||||
|
CalculatorLocatorImpl.getInstance().setCalculatorEngine(CalculatorEngine.instance);
|
||||||
|
|
||||||
AdsController.getInstance().init(ADMOB_USER_ID, AD_FREE_PRODUCT_ID, new BillingController.IConfiguration() {
|
AdsController.getInstance().init(ADMOB_USER_ID, AD_FREE_PRODUCT_ID, new BillingController.IConfiguration() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -8,6 +8,7 @@ package org.solovyev.android.calculator.history;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.simpleframework.xml.Element;
|
import org.simpleframework.xml.Element;
|
||||||
import org.simpleframework.xml.Root;
|
import org.simpleframework.xml.Root;
|
||||||
|
import org.solovyev.android.calculator.Editor;
|
||||||
import org.solovyev.android.calculator.ICalculatorDisplay;
|
import org.solovyev.android.calculator.ICalculatorDisplay;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -9,6 +9,7 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.simpleframework.xml.Element;
|
import org.simpleframework.xml.Element;
|
||||||
import org.simpleframework.xml.Root;
|
import org.simpleframework.xml.Root;
|
||||||
|
import org.solovyev.android.calculator.Editor;
|
||||||
|
|
||||||
@Root
|
@Root
|
||||||
public class EditorHistoryState implements Cloneable{
|
public class EditorHistoryState implements Cloneable{
|
||||||
|
@ -10,6 +10,7 @@ import android.widget.EditText;
|
|||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import org.solovyev.android.calculator.Editor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* User: serso
|
* User: serso
|
||||||
|
@ -16,13 +16,16 @@ import jscl.text.ParseInterruptedException;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.solovyev.android.calculator.CalculatorApplication;
|
import org.solovyev.android.calculator.CalculatorApplication;
|
||||||
|
import org.solovyev.android.calculator.JCalculatorEngine;
|
||||||
import org.solovyev.android.calculator.R;
|
import org.solovyev.android.calculator.R;
|
||||||
import org.solovyev.android.calculator.jscl.JsclOperation;
|
import org.solovyev.android.calculator.jscl.JsclOperation;
|
||||||
|
import org.solovyev.android.msg.AndroidMessage;
|
||||||
import org.solovyev.android.prefs.BooleanPreference;
|
import org.solovyev.android.prefs.BooleanPreference;
|
||||||
import org.solovyev.android.prefs.Preference;
|
import org.solovyev.android.prefs.Preference;
|
||||||
import org.solovyev.android.prefs.StringPreference;
|
import org.solovyev.android.prefs.StringPreference;
|
||||||
import org.solovyev.common.MutableObject;
|
import org.solovyev.common.MutableObject;
|
||||||
import org.solovyev.common.msg.MessageRegistry;
|
import org.solovyev.common.msg.MessageRegistry;
|
||||||
|
import org.solovyev.common.msg.MessageType;
|
||||||
import org.solovyev.common.text.EnumMapper;
|
import org.solovyev.common.text.EnumMapper;
|
||||||
import org.solovyev.common.text.NumberMapper;
|
import org.solovyev.common.text.NumberMapper;
|
||||||
import org.solovyev.common.text.StringUtils;
|
import org.solovyev.common.text.StringUtils;
|
||||||
@ -40,7 +43,7 @@ import java.util.concurrent.TimeUnit;
|
|||||||
* Time: 11:38 PM
|
* Time: 11:38 PM
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public enum CalculatorEngine {
|
public enum CalculatorEngine implements JCalculatorEngine {
|
||||||
|
|
||||||
instance;
|
instance;
|
||||||
|
|
||||||
@ -130,7 +133,8 @@ public enum CalculatorEngine {
|
|||||||
this.engine.setUseGroupingSeparator(true);
|
this.engine.setUseGroupingSeparator(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@Override
|
||||||
|
@NotNull
|
||||||
public String getMultiplicationSign() {
|
public String getMultiplicationSign() {
|
||||||
return multiplicationSign;
|
return multiplicationSign;
|
||||||
}
|
}
|
||||||
@ -229,10 +233,12 @@ public enum CalculatorEngine {
|
|||||||
evalException.setObject(new CalculatorEvalException(e, e, jsclExpression));
|
evalException.setObject(new CalculatorEvalException(e, e, jsclExpression));
|
||||||
} catch (ArithmeticException e) {
|
} catch (ArithmeticException e) {
|
||||||
//System.out.println(e.getMessage());
|
//System.out.println(e.getMessage());
|
||||||
parseException.setObject(new CalculatorParseException(R.string.msg_1, CalculatorApplication.getInstance(), jsclExpression, e.getMessage()));
|
final AndroidMessage androidMessage = new AndroidMessage(R.string.msg_1, MessageType.error, CalculatorApplication.getInstance(), e.getMessage());
|
||||||
|
parseException.setObject(new CalculatorParseException(jsclExpression, androidMessage));
|
||||||
} catch (StackOverflowError e) {
|
} catch (StackOverflowError e) {
|
||||||
//System.out.println(StringUtils.fromStackTrace(e.getStackTrace()));
|
//System.out.println(StringUtils.fromStackTrace(e.getStackTrace()));
|
||||||
parseException.setObject(new CalculatorParseException(R.string.msg_2, CalculatorApplication.getInstance(), jsclExpression));
|
final AndroidMessage androidMessage = new AndroidMessage(R.string.msg_2, MessageType.error, CalculatorApplication.getInstance());
|
||||||
|
parseException.setObject(new CalculatorParseException(jsclExpression, androidMessage));
|
||||||
} catch (jscl.text.ParseException e) {
|
} catch (jscl.text.ParseException e) {
|
||||||
//System.out.println(e.getMessage());
|
//System.out.println(e.getMessage());
|
||||||
parseException.setObject(new CalculatorParseException(e));
|
parseException.setObject(new CalculatorParseException(e));
|
||||||
@ -278,11 +284,13 @@ public enum CalculatorEngine {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (calculationResultLocal == null) {
|
if (calculationResultLocal == null) {
|
||||||
throw new CalculatorParseException(R.string.msg_3, CalculatorApplication.getInstance(), jsclExpression);
|
final AndroidMessage androidMessage = new AndroidMessage(R.string.msg_3, MessageType.error, CalculatorApplication.getInstance());
|
||||||
|
throw new CalculatorParseException(jsclExpression, androidMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
throw new CalculatorParseException(R.string.msg_4, CalculatorApplication.getInstance(), jsclExpression);
|
final AndroidMessage androidMessage = new AndroidMessage(R.string.msg_4, MessageType.error, CalculatorApplication.getInstance());
|
||||||
|
throw new CalculatorParseException(jsclExpression, androidMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
final Generic genericResult = calculationResult.getObject();
|
final Generic genericResult = calculationResult.getObject();
|
||||||
@ -356,27 +364,32 @@ public enum CalculatorEngine {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@Override
|
||||||
|
@NotNull
|
||||||
public AndroidMathRegistry<IConstant> getVarsRegistry() {
|
public AndroidMathRegistry<IConstant> getVarsRegistry() {
|
||||||
return varsRegistry;
|
return varsRegistry;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@Override
|
||||||
|
@NotNull
|
||||||
public AndroidMathRegistry<Function> getFunctionsRegistry() {
|
public AndroidMathRegistry<Function> getFunctionsRegistry() {
|
||||||
return functionsRegistry;
|
return functionsRegistry;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@Override
|
||||||
|
@NotNull
|
||||||
public AndroidMathRegistry<Operator> getOperatorsRegistry() {
|
public AndroidMathRegistry<Operator> getOperatorsRegistry() {
|
||||||
return operatorsRegistry;
|
return operatorsRegistry;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@Override
|
||||||
|
@NotNull
|
||||||
public AndroidMathRegistry<Operator> getPostfixFunctionsRegistry() {
|
public AndroidMathRegistry<Operator> getPostfixFunctionsRegistry() {
|
||||||
return postfixFunctionsRegistry;
|
return postfixFunctionsRegistry;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@Override
|
||||||
|
@NotNull
|
||||||
public MathEngine getEngine() {
|
public MathEngine getEngine() {
|
||||||
return engine;
|
return engine;
|
||||||
}
|
}
|
||||||
|
@ -10,9 +10,11 @@ import jscl.math.function.IConstant;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.solovyev.android.calculator.CalculatorApplication;
|
import org.solovyev.android.calculator.CalculatorApplication;
|
||||||
import org.solovyev.android.calculator.R;
|
import org.solovyev.android.calculator.R;
|
||||||
|
import org.solovyev.android.msg.AndroidMessage;
|
||||||
import org.solovyev.common.StartsWithFinder;
|
import org.solovyev.common.StartsWithFinder;
|
||||||
import org.solovyev.android.calculator.math.MathType;
|
import org.solovyev.android.calculator.math.MathType;
|
||||||
import org.solovyev.common.collections.CollectionsUtils;
|
import org.solovyev.common.collections.CollectionsUtils;
|
||||||
|
import org.solovyev.common.msg.MessageType;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -75,7 +77,8 @@ public class ToJsclTextProcessor implements TextProcessor<PreparedExpression, St
|
|||||||
if (mathTypeBefore != null &&
|
if (mathTypeBefore != null &&
|
||||||
(mathTypeBefore.getMathType() == MathType.function || mathTypeBefore.getMathType() == MathType.operator) &&
|
(mathTypeBefore.getMathType() == MathType.function || mathTypeBefore.getMathType() == MathType.operator) &&
|
||||||
CollectionsUtils.find(MathType.openGroupSymbols, startsWithFinder) != null) {
|
CollectionsUtils.find(MathType.openGroupSymbols, startsWithFinder) != null) {
|
||||||
throw new CalculatorParseException(R.string.msg_5, CalculatorApplication.getInstance(), i, s, mathTypeBefore.getMatch());
|
final AndroidMessage androidMessage = new AndroidMessage(R.string.msg_5, MessageType.error, CalculatorApplication.getInstance(), mathTypeBefore.getMatch());
|
||||||
|
throw new CalculatorParseException(i, s, androidMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
i = mathTypeResult.processToJscl(result, i);
|
i = mathTypeResult.processToJscl(result, i);
|
||||||
@ -86,7 +89,8 @@ public class ToJsclTextProcessor implements TextProcessor<PreparedExpression, St
|
|||||||
@NotNull
|
@NotNull
|
||||||
private static PreparedExpression replaceVariables(@NotNull final String s, int depth, @NotNull List<IConstant> undefinedVars) throws CalculatorParseException {
|
private static PreparedExpression replaceVariables(@NotNull final String s, int depth, @NotNull List<IConstant> undefinedVars) throws CalculatorParseException {
|
||||||
if (depth >= MAX_DEPTH) {
|
if (depth >= MAX_DEPTH) {
|
||||||
throw new CalculatorParseException(R.string.msg_6, CalculatorApplication.getInstance(), s);
|
final AndroidMessage androidMessage = new AndroidMessage(R.string.msg_6, MessageType.error, CalculatorApplication.getInstance());
|
||||||
|
throw new CalculatorParseException(s, androidMessage);
|
||||||
} else {
|
} else {
|
||||||
depth++;
|
depth++;
|
||||||
}
|
}
|
||||||
|
@ -11,6 +11,7 @@ import junit.framework.Assert;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
import org.solovyev.android.calculator.Editor;
|
||||||
import org.solovyev.android.calculator.ICalculatorDisplay;
|
import org.solovyev.android.calculator.ICalculatorDisplay;
|
||||||
import org.solovyev.android.calculator.jscl.JsclOperation;
|
import org.solovyev.android.calculator.jscl.JsclOperation;
|
||||||
import org.solovyev.common.equals.CollectionEqualizer;
|
import org.solovyev.common.equals.CollectionEqualizer;
|
||||||
|
12
pom.xml
12
pom.xml
@ -72,6 +72,18 @@
|
|||||||
<version>1.0.0</version>
|
<version>1.0.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.solovyev</groupId>
|
||||||
|
<artifactId>jscl</artifactId>
|
||||||
|
<version>0.0.2</version>
|
||||||
|
<exclusions>
|
||||||
|
<exclusion>
|
||||||
|
<artifactId>xercesImpl</artifactId>
|
||||||
|
<groupId>xerces</groupId>
|
||||||
|
</exclusion>
|
||||||
|
</exclusions>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.solovyev.android</groupId>
|
<groupId>org.solovyev.android</groupId>
|
||||||
<artifactId>android-common-other</artifactId>
|
<artifactId>android-common-other</artifactId>
|
||||||
|
Loading…
Reference in New Issue
Block a user