Engine refactor

This commit is contained in:
serso 2016-01-20 10:46:23 +01:00
parent 1d366123b3
commit 7faef42dea
28 changed files with 280 additions and 387 deletions

View File

@ -40,11 +40,6 @@ import javax.annotation.Nullable;
import jscl.NumeralBase;
import jscl.math.Generic;
/**
* User: serso
* Date: 9/22/12
* Time: 5:42 PM
*/
public class AndroidCalculator implements Calculator, CalculatorEventListener, SharedPreferences.OnSharedPreferenceChangeListener {
@Nonnull
@ -61,14 +56,6 @@ public class AndroidCalculator implements Calculator, CalculatorEventListener, S
PreferenceManager.getDefaultSharedPreferences(application).registerOnSharedPreferenceChangeListener(this);
}
/*
**********************************************************************
*
* DELEGATED TO CALCULATOR
*
**********************************************************************
*/
@Override
@Nonnull
public CalculatorEventData evaluate(@Nonnull JsclOperation operation, @Nonnull String expression) {
@ -127,8 +114,8 @@ public class AndroidCalculator implements Calculator, CalculatorEventListener, S
}
@Override
public void init() {
this.calculator.init();
public void init(@Nonnull Executor initThread) {
this.calculator.init(initThread);
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
this.calculator.setCalculateOnFly(Preferences.Calculations.calculateOnFly.getPreference(prefs));

View File

@ -50,7 +50,7 @@ public abstract class BaseNumberBuilder {
protected BaseNumberBuilder(@Nonnull Engine engine) {
this.engine = engine;
this.nb = engine.getNumeralBase();
this.nb = engine.getMathEngine().getNumeralBase();
}
/**
@ -94,12 +94,12 @@ public abstract class BaseNumberBuilder {
}
public boolean isHexMode() {
return nb == NumeralBase.hex || (nb == null && engine.getNumeralBase() == NumeralBase.hex);
return nb == NumeralBase.hex || (nb == null && engine.getMathEngine().getNumeralBase() == NumeralBase.hex);
}
@Nonnull
protected NumeralBase getNumeralBase() {
return nb == null ? engine.getNumeralBase() : nb;
return nb == null ? engine.getMathEngine().getNumeralBase() : nb;
}
public abstract int process(@Nonnull SpannableStringBuilder sb, @Nonnull MathType.Result result);

View File

@ -24,6 +24,8 @@ package org.solovyev.android.calculator;
import org.solovyev.android.calculator.jscl.JsclOperation;
import java.util.concurrent.Executor;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
@ -37,7 +39,7 @@ import jscl.math.Generic;
*/
public interface Calculator extends CalculatorEventContainer {
void init();
void init(@Nonnull Executor initThread);
/*
**********************************************************************

View File

@ -26,9 +26,10 @@ import android.content.SharedPreferences;
import android.os.Handler;
import android.preference.PreferenceManager;
import android.util.Log;
import com.squareup.leakcanary.LeakCanary;
import com.squareup.otto.Bus;
import jscl.MathEngine;
import org.acra.ACRA;
import org.acra.ACRAConfiguration;
import org.acra.sender.HttpSender;
@ -41,14 +42,17 @@ import org.solovyev.android.calculator.plot.AndroidCalculatorPlotter;
import org.solovyev.android.calculator.plot.CalculatorPlotterImpl;
import org.solovyev.common.msg.MessageType;
import javax.annotation.Nonnull;
import javax.inject.Inject;
import javax.inject.Named;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.concurrent.Executor;
import javax.annotation.Nonnull;
import javax.inject.Inject;
import javax.inject.Named;
import jscl.MathEngine;
public class CalculatorApplication extends android.app.Application implements SharedPreferences.OnSharedPreferenceChangeListener {
@Inject
@ -79,6 +83,9 @@ public class CalculatorApplication extends android.app.Application implements Sh
@Inject
Calculator calculator;
@Inject
Engine engine;
@Inject
Keyboard keyboard;
@ -103,6 +110,7 @@ public class CalculatorApplication extends android.app.Application implements Sh
.appModule(new AppModule(this))
.build();
component.inject(this);
editor.init();
history.init(initThread);
onPostCreate(preferences, languages);
@ -116,7 +124,7 @@ public class CalculatorApplication extends android.app.Application implements Sh
App.getGa().reportInitially(preferences);
Locator.getInstance().init(calculator,
new Engine(this),
engine,
new AndroidCalculatorClipboard(this),
new AndroidCalculatorNotifier(this),
errorReporter,
@ -130,7 +138,7 @@ public class CalculatorApplication extends android.app.Application implements Sh
calculator.addCalculatorEventListener(listener);
}
Locator.getInstance().getCalculator().init();
calculator.init(initThread);
initThread.execute(new Runnable() {
@Override
@ -143,7 +151,7 @@ public class CalculatorApplication extends android.app.Application implements Sh
private void warmUpEngine() {
try {
// warm-up engine
MathEngine mathEngine = Locator.getInstance().getEngine().getMathEngine();
final MathEngine mathEngine = engine.getMathEngine();
mathEngine.evaluate("1+1");
mathEngine.evaluate("1*1");
} catch (Throwable e) {

View File

@ -70,16 +70,6 @@ public enum CalculatorEventType {
conversion_finished,
/*
**********************************************************************
*
* ENGINE
*
**********************************************************************
*/
engine_preferences_changed,
/*
**********************************************************************
*

View File

@ -24,17 +24,10 @@ package org.solovyev.android.calculator;
import android.text.TextUtils;
import android.util.Log;
import com.squareup.otto.Bus;
import com.squareup.otto.Subscribe;
import jscl.AbstractJsclArithmeticException;
import jscl.MathEngine;
import jscl.NumeralBase;
import jscl.NumeralBaseException;
import jscl.math.Generic;
import jscl.math.function.Function;
import jscl.math.function.IConstant;
import jscl.math.operator.Operator;
import jscl.text.ParseInterruptedException;
import org.solovyev.android.calculator.jscl.JsclOperation;
import org.solovyev.android.calculator.model.Var;
import org.solovyev.android.calculator.text.TextProcessor;
@ -47,40 +40,30 @@ import org.solovyev.common.text.Strings;
import org.solovyev.common.units.ConversionException;
import org.solovyev.common.units.Conversions;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicLong;
/**
* User: Solovyev_S
* Date: 20.09.12
* Time: 16:42
*/
public class CalculatorImpl implements Calculator, CalculatorEventListener {
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
/*
**********************************************************************
*
* CONSTANTS
*
**********************************************************************
*/
import jscl.AbstractJsclArithmeticException;
import jscl.MathEngine;
import jscl.NumeralBase;
import jscl.NumeralBaseException;
import jscl.math.Generic;
import jscl.math.function.Function;
import jscl.math.function.IConstant;
import jscl.math.operator.Operator;
import jscl.text.ParseInterruptedException;
public class CalculatorImpl implements Calculator, CalculatorEventListener {
// one minute
private static final long PREFERENCE_CHECK_INTERVAL = 1000L * 60L;
/*
**********************************************************************
*
* FIELDS
*
**********************************************************************
*/
@Nonnull
private final CalculatorEventContainer calculatorEventContainer = new ListCalculatorEventContainer();
@ -205,8 +188,8 @@ public class CalculatorImpl implements Calculator, CalculatorEventListener {
}
@Override
public void init() {
Locator.getInstance().getEngine().init();
public void init(@Nonnull Executor initThread) {
Locator.getInstance().getEngine().init(initThread);
}
@Override
@ -373,7 +356,7 @@ public class CalculatorImpl implements Calculator, CalculatorEventListener {
final CalculatorEventData eventDataId = nextEventData();
final DisplayState displayViewState = App.getDisplay().getState();
final NumeralBase from = Locator.getInstance().getEngine().getNumeralBase();
final NumeralBase from = Locator.getInstance().getEngine().getMathEngine().getNumeralBase();
calculationsExecutor.execute(new Runnable() {
@Override
@ -524,11 +507,6 @@ public class CalculatorImpl implements Calculator, CalculatorEventListener {
case function_removed:
evaluate();
break;
case engine_preferences_changed:
evaluate(calculatorEventData.getSequenceId());
break;
case use_constant:
final IConstant constant = (IConstant) data;
Locator.getInstance().getKeyboard().buttonPressed(constant.getName());

View File

@ -56,7 +56,7 @@ enum ConversionMenuItem implements AMenuItem<DisplayState> {
if (operation == JsclOperation.numeric) {
if (generic.getConstants().isEmpty()) {
// conversion possible => return true
final NumeralBase fromNumeralBase = Locator.getInstance().getEngine().getNumeralBase();
final NumeralBase fromNumeralBase = Locator.getInstance().getEngine().getMathEngine().getNumeralBase();
if (fromNumeralBase != toNumeralBase) {
result = Locator.getInstance().getCalculator().isConversionPossible(generic, fromNumeralBase, this.toNumeralBase);
}

View File

@ -25,6 +25,7 @@ package org.solovyev.android.calculator;
import android.content.SharedPreferences;
import com.squareup.otto.Bus;
import com.squareup.otto.Subscribe;
import org.solovyev.android.Check;
import org.solovyev.android.calculator.text.TextProcessorEditorResult;
@ -40,7 +41,6 @@ import static java.lang.Math.min;
@Singleton
public class Editor {
private static final String TAG = App.subTag("Editor");
@Nullable
private final EditorTextProcessor textProcessor;
@Nullable
@ -55,6 +55,10 @@ public class Editor {
textProcessor = new EditorTextProcessor(preferences);
}
public void init() {
bus.register(this);
}
public static int clamp(int selection, @Nonnull CharSequence text) {
return clamp(selection, text.length());
}
@ -214,6 +218,13 @@ public class Editor {
return onSelectionChanged(EditorState.forNewSelection(state, clamp(selection, state.text)));
}
@Subscribe
public void onEngineChanged(@Nonnull Engine.ChangedEvent e) {
// this will effectively apply new formatting (if f.e. grouping separator has changed) and
// will start new evaluation
onTextChanged(getState());
}
public static class ChangedEvent {
@Nonnull
public final EditorState oldState;

View File

@ -23,9 +23,30 @@
package org.solovyev.android.calculator;
import android.app.Application;
import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import com.squareup.otto.Bus;
import org.solovyev.android.calculator.model.AndroidMathEntityDao;
import org.solovyev.android.calculator.model.Functions;
import org.solovyev.android.calculator.model.Vars;
import org.solovyev.android.prefs.BooleanPreference;
import org.solovyev.android.prefs.IntegerPreference;
import org.solovyev.android.prefs.Preference;
import org.solovyev.android.prefs.StringPreference;
import org.solovyev.common.text.EnumMapper;
import org.solovyev.common.text.NumberMapper;
import org.solovyev.common.text.Strings;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.Executor;
import javax.annotation.Nonnull;
import javax.inject.Inject;
import javax.inject.Singleton;
import jscl.AngleUnit;
import jscl.JsclMathEngine;
import jscl.MathEngine;
@ -33,48 +54,10 @@ import jscl.NumeralBase;
import jscl.math.function.Function;
import jscl.math.function.IConstant;
import jscl.math.operator.Operator;
import org.solovyev.android.calculator.model.AndroidMathEntityDao;
import org.solovyev.android.calculator.model.Functions;
import org.solovyev.android.calculator.model.Vars;
import org.solovyev.android.prefs.BooleanPreference;
import org.solovyev.android.prefs.Preference;
import org.solovyev.android.prefs.StringPreference;
import org.solovyev.common.text.EnumMapper;
import org.solovyev.common.text.NumberMapper;
import org.solovyev.common.text.Strings;
import javax.annotation.Nonnull;
import java.text.DecimalFormatSymbols;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@Singleton
public class Engine implements SharedPreferences.OnSharedPreferenceChangeListener {
private static final String MULTIPLICATION_SIGN_DEFAULT = "×";
private static final String GROUPING_SEPARATOR_P_KEY = "org.solovyev.android.calculator.CalculatorActivity_calc_grouping_separator";
private static final String MULTIPLICATION_SIGN_P_KEY = "org.solovyev.android.calculator.CalculatorActivity_calc_multiplication_sign";
private static final String SCIENCE_NOTATION_P_KEY = "calculation.output.science_notation";
private static final boolean SCIENCE_NOTATION_DEFAULT = false;
private static final String ROUND_RESULT_P_KEY = "org.solovyev.android.calculator.CalculatorModel_round_result";
private static final boolean ROUND_RESULT_DEFAULT = true;
private static final String RESULT_PRECISION_P_KEY = "org.solovyev.android.calculator.CalculatorModel_result_precision";
private static final String RESULT_PRECISION_DEFAULT = "5";
private static final String NUMERAL_BASES_P_KEY = "org.solovyev.android.calculator.CalculatorActivity_numeral_bases";
private static final String NUMERAL_BASES_DEFAULT = "dec";
private static final String ANGLE_UNITS_P_KEY = "org.solovyev.android.calculator.CalculatorActivity_angle_units";
private static final String ANGLE_UNITS_DEFAULT = "deg";
@Nonnull
private final Context context;
@Nonnull
private final Object lock;
@Nonnull
private final MathEngine mathEngine;
@Nonnull
@ -85,12 +68,16 @@ public class Engine implements SharedPreferences.OnSharedPreferenceChangeListene
private final EntitiesRegistry<Operator> operatorsRegistry;
@Nonnull
private final EntitiesRegistry<Operator> postfixFunctionsRegistry;
@Inject
SharedPreferences preferences;
@Inject
Bus bus;
@Inject
ErrorReporter errorReporter;
@Nonnull
private String multiplicationSign = MULTIPLICATION_SIGN_DEFAULT;
private String multiplicationSign = Preferences.multiplicationSign.getDefaultValue();
public Engine(@Nonnull Context context, @Nonnull MathEngine mathEngine, @Nonnull EntitiesRegistry<IConstant> varsRegistry, @Nonnull EntitiesRegistry<Function> functionsRegistry, @Nonnull EntitiesRegistry<Operator> operatorsRegistry, @Nonnull EntitiesRegistry<Operator> postfixFunctionsRegistry) {
this.context = context;
this.lock = new Object();
public Engine(@Nonnull MathEngine mathEngine, @Nonnull EntitiesRegistry<IConstant> varsRegistry, @Nonnull EntitiesRegistry<Function> functionsRegistry, @Nonnull EntitiesRegistry<Operator> operatorsRegistry, @Nonnull EntitiesRegistry<Operator> postfixFunctionsRegistry) {
this.mathEngine = mathEngine;
this.varsRegistry = varsRegistry;
this.functionsRegistry = functionsRegistry;
@ -98,13 +85,10 @@ public class Engine implements SharedPreferences.OnSharedPreferenceChangeListene
this.postfixFunctionsRegistry = postfixFunctionsRegistry;
}
@Inject
public Engine(@Nonnull Application application) {
this.mathEngine = JsclMathEngine.getInstance();
this.context = application;
PreferenceManager.getDefaultSharedPreferences(application).registerOnSharedPreferenceChangeListener(this);
this.lock = new Object();
this.mathEngine.setRoundResult(true);
this.mathEngine.setUseGroupingSeparator(true);
@ -114,34 +98,38 @@ public class Engine implements SharedPreferences.OnSharedPreferenceChangeListene
this.postfixFunctionsRegistry = new PostfixFunctionsRegistry(mathEngine.getPostfixFunctionsRegistry(), new AndroidMathEntityDao<>(null, application, null));
}
@Nonnull
public static NumeralBase getNumeralBaseFromPrefs(@Nonnull SharedPreferences preferences) {
return Preferences.numeralBase.getPreference(preferences);
private static void migratePreference(@Nonnull SharedPreferences preferences, @Nonnull BooleanPreference preference, @Nonnull String oldKey, @Nonnull SharedPreferences.Editor editor) {
if (!preferences.contains(oldKey)) {
return;
}
editor.putBoolean(preference.getKey(), preferences.getBoolean(oldKey, false));
}
@Nonnull
public static AngleUnit getAngleUnitsFromPrefs(@Nonnull SharedPreferences preferences) {
return Preferences.angleUnit.getPreference(preferences);
private static void migratePreference(@Nonnull SharedPreferences preferences, @Nonnull StringPreference<?> preference, @Nonnull String oldKey, @Nonnull SharedPreferences.Editor editor) {
if (!preferences.contains(oldKey)) {
return;
}
editor.putString(preference.getKey(), preferences.getString(oldKey, null));
}
@Nonnull
public EntitiesRegistry<IConstant> getVarsRegistry() {
return this.varsRegistry;
return varsRegistry;
}
@Nonnull
public EntitiesRegistry<Function> getFunctionsRegistry() {
return this.functionsRegistry;
return functionsRegistry;
}
@Nonnull
public EntitiesRegistry<Operator> getOperatorsRegistry() {
return this.operatorsRegistry;
return operatorsRegistry;
}
@Nonnull
public EntitiesRegistry<Operator> getPostfixFunctionsRegistry() {
return this.postfixFunctionsRegistry;
return postfixFunctionsRegistry;
}
@Nonnull
@ -149,45 +137,75 @@ public class Engine implements SharedPreferences.OnSharedPreferenceChangeListene
return mathEngine;
}
public void init() {
synchronized (lock) {
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
resetPreferences(preferences);
public void init(@Nonnull Executor initThread) {
checkPreferences();
preferences.registerOnSharedPreferenceChangeListener(this);
applyPreferences();
initThread.execute(new Runnable() {
@Override
public void run() {
initAsync();
}
});
}
private void checkPreferences() {
final int oldVersion;
if (Preferences.version.isSet(preferences)) {
oldVersion = Preferences.version.getPreference(preferences);
} else {
oldVersion = 0;
}
final int newVersion = Preferences.version.getPreference(preferences);
if (oldVersion == newVersion) {
return;
}
final SharedPreferences.Editor editor = preferences.edit();
if (oldVersion == 0) {
migratePreference(preferences, Preferences.groupingSeparator, "org.solovyev.android.calculator.CalculatorActivity_calc_grouping_separator", editor);
migratePreference(preferences, Preferences.multiplicationSign, "org.solovyev.android.calculator.CalculatorActivity_calc_multiplication_sign", editor);
migratePreference(preferences, Preferences.numeralBase, "org.solovyev.android.calculator.CalculatorActivity_numeral_bases", editor);
migratePreference(preferences, Preferences.angleUnit, "org.solovyev.android.calculator.CalculatorActivity_angle_units", editor);
migratePreference(preferences, Preferences.Output.precision, "org.solovyev.android.calculator.CalculatorModel_result_precision", editor);
migratePreference(preferences, Preferences.Output.scientificNotation, "calculation.output.science_notation", editor);
migratePreference(preferences, Preferences.Output.round, "org.solovyev.android.calculator.CalculatorModel_round_result", editor);
}
Preferences.version.putDefault(preferences);
editor.apply();
}
private void initAsync() {
safeLoadRegistry(varsRegistry);
safeLoadRegistry(functionsRegistry);
safeLoadRegistry(operatorsRegistry);
safeLoadRegistry(postfixFunctionsRegistry);
}
}
public void resetPreferences() {
resetPreferences(App.getPreferences());
}
private void safeLoadRegistry(@Nonnull EntitiesRegistry<?> registry) {
try {
registry.load();
} catch (Exception e) {
Locator.getInstance().getErrorReporter().onException(e);
errorReporter.onException(e);
}
}
private void resetPreferences(@Nonnull SharedPreferences preferences) {
setPrecision(Preferences.precision.getPreference(preferences));
setRoundResult(Preferences.roundResult.getPreference(preferences));
setAngleUnits(getAngleUnitsFromPrefs(preferences));
setNumeralBase(getNumeralBaseFromPrefs(preferences));
private void applyPreferences() {
mathEngine.setAngleUnits(Preferences.angleUnit.getPreference(preferences));
mathEngine.setNumeralBase(Preferences.numeralBase.getPreference(preferences));
setMultiplicationSign(Preferences.multiplicationSign.getPreference(preferences));
setScienceNotation(Preferences.scienceNotation.getPreference(preferences));
mathEngine.setPrecision(Preferences.Output.precision.getPreference(preferences));
mathEngine.setScienceNotation(Preferences.Output.scientificNotation.getPreference(preferences));
mathEngine.setRoundResult(Preferences.Output.round.getPreference(preferences));
final String groupingSeparator = Preferences.groupingSeparator.getPreference(preferences);
if (Strings.isEmpty(groupingSeparator)) {
setUseGroupingSeparator(false);
mathEngine.setUseGroupingSeparator(false);
} else {
setUseGroupingSeparator(true);
setGroupingSeparator(groupingSeparator.charAt(0));
mathEngine.setUseGroupingSeparator(true);
mathEngine.setGroupingSeparator(groupingSeparator.charAt(0));
}
Locator.getInstance().getCalculator().fireCalculatorEvent(CalculatorEventType.engine_preferences_changed, null);
bus.post(ChangedEvent.INSTANCE);
}
@Nonnull
@ -199,99 +217,46 @@ public class Engine implements SharedPreferences.OnSharedPreferenceChangeListene
this.multiplicationSign = multiplicationSign;
}
public void setUseGroupingSeparator(boolean useGroupingSeparator) {
synchronized (lock) {
this.mathEngine.setUseGroupingSeparator(useGroupingSeparator);
}
}
public void setGroupingSeparator(char groupingSeparator) {
synchronized (lock) {
this.mathEngine.setGroupingSeparator(groupingSeparator);
}
}
public void setPrecision(@Nonnull Integer precision) {
synchronized (lock) {
this.mathEngine.setPrecision(precision);
}
}
public void setRoundResult(@Nonnull Boolean round) {
synchronized (lock) {
this.mathEngine.setRoundResult(round);
}
}
@Nonnull
public AngleUnit getAngleUnits() {
synchronized (lock) {
return this.mathEngine.getAngleUnits();
}
}
public void setAngleUnits(@Nonnull AngleUnit angleUnits) {
synchronized (lock) {
this.mathEngine.setAngleUnits(angleUnits);
}
}
@Nonnull
public NumeralBase getNumeralBase() {
synchronized (lock) {
return this.mathEngine.getNumeralBase();
}
}
public void setNumeralBase(@Nonnull NumeralBase numeralBase) {
synchronized (lock) {
this.mathEngine.setNumeralBase(numeralBase);
}
}
public void setScienceNotation(@Nonnull Boolean scienceNotation) {
synchronized (lock) {
this.mathEngine.setScienceNotation(scienceNotation);
}
}
public void setDecimalGroupSymbols(@Nonnull DecimalFormatSymbols decimalGroupSymbols) {
synchronized (lock) {
this.mathEngine.setDecimalGroupSymbols(decimalGroupSymbols);
}
}
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
if (Preferences.getPreferenceKeys().contains(key)) {
this.resetPreferences();
applyPreferences();
}
}
public static class ChangedEvent {
static final ChangedEvent INSTANCE = new ChangedEvent();
private ChangedEvent() {
}
}
public static class Preferences {
public static final Preference<String> groupingSeparator = StringPreference.of(GROUPING_SEPARATOR_P_KEY, JsclMathEngine.GROUPING_SEPARATOR_DEFAULT);
public static final Preference<String> multiplicationSign = StringPreference.of(MULTIPLICATION_SIGN_P_KEY, MULTIPLICATION_SIGN_DEFAULT);
public static final Preference<Integer> precision = StringPreference.ofTypedValue(RESULT_PRECISION_P_KEY, RESULT_PRECISION_DEFAULT, NumberMapper.of(Integer.class));
public static final Preference<Boolean> roundResult = BooleanPreference.of(ROUND_RESULT_P_KEY, ROUND_RESULT_DEFAULT);
public static final Preference<NumeralBase> numeralBase = StringPreference.ofTypedValue(NUMERAL_BASES_P_KEY, NUMERAL_BASES_DEFAULT, EnumMapper.of(NumeralBase.class));
public static final Preference<AngleUnit> angleUnit = StringPreference.ofTypedValue(ANGLE_UNITS_P_KEY, ANGLE_UNITS_DEFAULT, EnumMapper.of(AngleUnit.class));
public static final Preference<Boolean> scienceNotation = BooleanPreference.of(SCIENCE_NOTATION_P_KEY, SCIENCE_NOTATION_DEFAULT);
public static final StringPreference<String> groupingSeparator = StringPreference.of("engine.groupingSeparator", JsclMathEngine.GROUPING_SEPARATOR_DEFAULT);
public static final StringPreference<String> multiplicationSign = StringPreference.of("engine.multiplicationSign", "×");
public static final StringPreference<NumeralBase> numeralBase = StringPreference.ofTypedValue("engine.numeralBase", "dec", EnumMapper.of(NumeralBase.class));
public static final StringPreference<AngleUnit> angleUnit = StringPreference.ofTypedValue("engine.angleUnit", "deg", EnumMapper.of(AngleUnit.class));
public static final Preference<Integer> version = IntegerPreference.of("engine.version", 1);
private static final List<String> preferenceKeys = new ArrayList<>();
static {
preferenceKeys.add(groupingSeparator.getKey());
preferenceKeys.add(multiplicationSign.getKey());
preferenceKeys.add(precision.getKey());
preferenceKeys.add(roundResult.getKey());
preferenceKeys.add(numeralBase.getKey());
preferenceKeys.add(angleUnit.getKey());
preferenceKeys.add(scienceNotation.getKey());
preferenceKeys.add(Output.precision.getKey());
preferenceKeys.add(Output.scientificNotation.getKey());
preferenceKeys.add(Output.round.getKey());
}
@Nonnull
public static List<String> getPreferenceKeys() {
return Collections.unmodifiableList(preferenceKeys);
}
public static class Output {
public static final StringPreference<Integer> precision = StringPreference.ofTypedValue("engine.output.precision", "5", NumberMapper.of(Integer.class));
public static final BooleanPreference scientificNotation = BooleanPreference.of("engine.output.scientificNotation", false);
public static final BooleanPreference round = BooleanPreference.of("engine.output.round", true);
}
}
}

View File

@ -40,7 +40,7 @@ public class LiteNumberBuilder extends BaseNumberBuilder {
public LiteNumberBuilder(@Nonnull Engine engine) {
super(engine);
this.nb = engine.getNumeralBase();
this.nb = engine.getMathEngine().getNumeralBase();
}
@Override
@ -71,7 +71,7 @@ public class LiteNumberBuilder extends BaseNumberBuilder {
numberBuilder = null;
// must set default numeral base (exit numeral base mode)
nb = engine.getNumeralBase();
nb = engine.getMathEngine().getNumeralBase();
}
}
}

View File

@ -23,17 +23,24 @@
package org.solovyev.android.calculator;
import android.text.SpannableStringBuilder;
import org.solovyev.android.calculator.math.MathType;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import jscl.MathContext;
import jscl.MathEngine;
import jscl.NumeralBase;
import jscl.math.numeric.Real;
import jscl.text.*;
import org.solovyev.android.calculator.math.MathType;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.List;
import jscl.text.DoubleParser;
import jscl.text.JsclIntegerParser;
import jscl.text.MutableInt;
import jscl.text.ParseException;
import jscl.text.Parser;
/**
* User: serso
@ -193,7 +200,7 @@ public class NumberBuilder extends BaseNumberBuilder {
numberBuilder = null;
// must set default numeral base (exit numeral base mode)
nb = engine.getNumeralBase();
nb = engine.getMathEngine().getNumeralBase();
}
return replaceNumberInText(sb, number, trimmedChars, localNb, engine.getMathEngine());

View File

@ -10,7 +10,12 @@ import android.util.SparseArray;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ListView;
import org.solovyev.android.calculator.*;
import org.solovyev.android.calculator.AdView;
import org.solovyev.android.calculator.App;
import org.solovyev.android.calculator.Engine;
import org.solovyev.android.calculator.Preferences;
import org.solovyev.android.calculator.R;
import org.solovyev.android.calculator.language.Language;
import org.solovyev.android.calculator.language.Languages;
import org.solovyev.android.checkout.BillingRequests;
@ -18,12 +23,11 @@ import org.solovyev.android.checkout.Checkout;
import org.solovyev.android.checkout.ProductTypes;
import org.solovyev.android.checkout.RequestListener;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.List;
import static org.solovyev.android.calculator.Engine.Preferences.precision;
import static org.solovyev.android.calculator.Engine.Preferences.roundResult;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import static org.solovyev.android.calculator.wizard.CalculatorWizards.DEFAULT_WIZARD_FLOW;
import static org.solovyev.android.wizard.WizardUi.startWizard;
@ -118,7 +122,7 @@ public class PreferencesFragment extends org.solovyev.android.material.preferenc
});
final SharedPreferences preferences = App.getPreferences();
onSharedPreferenceChanged(preferences, roundResult.getKey());
onSharedPreferenceChanged(preferences, Engine.Preferences.Output.round.getKey());
}
private void prepareLanguagePreference(int preference) {
@ -156,10 +160,10 @@ public class PreferencesFragment extends org.solovyev.android.material.preferenc
@Override
public void onSharedPreferenceChanged(SharedPreferences preferences, String key) {
if (roundResult.getKey().equals(key)) {
final Preference preference = findPreference(precision.getKey());
if (Engine.Preferences.Output.round.getKey().equals(key)) {
final Preference preference = findPreference(Engine.Preferences.Output.precision.getKey());
if (preference != null) {
preference.setEnabled(preferences.getBoolean(key, roundResult.getDefaultValue()));
preference.setEnabled(preferences.getBoolean(key, Engine.Preferences.Output.round.getDefaultValue()));
}
}
}

View File

@ -48,7 +48,7 @@ public class AngleUnitsButton extends DirectionDragButton {
public AngleUnitsButton(Context context, @Nonnull AttributeSet attrs) {
super(context, attrs);
this.angleUnit = Locator.getInstance().getEngine().getAngleUnits();
this.angleUnit = Locator.getInstance().getEngine().getMathEngine().getAngleUnits();
}
@Override

View File

@ -1,65 +0,0 @@
/*
* Copyright 2013 serso aka se.solovyev
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* Contact details
*
* Email: se.solovyev@gmail.com
* Site: http://se.solovyev.org
*/
package org.solovyev.android.calculator.view;
import android.content.Context;
import android.content.SharedPreferences;
import android.util.AttributeSet;
import android.widget.TextView;
import org.solovyev.android.calculator.Engine;
import org.solovyev.android.calculator.Locator;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
/**
* User: serso
* Date: 12/10/11
* Time: 10:34 PM
*/
public class CalculatorAdditionalTitle extends TextView implements SharedPreferences.OnSharedPreferenceChangeListener {
public CalculatorAdditionalTitle(Context context) {
super(context);
}
public CalculatorAdditionalTitle(Context context, AttributeSet attrs) {
super(context, attrs);
}
public CalculatorAdditionalTitle(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
public void init(@Nonnull SharedPreferences preferences) {
onSharedPreferenceChanged(preferences, null);
}
@Override
public void onSharedPreferenceChanged(SharedPreferences preferences, @Nullable String key) {
setText(((Engine) Locator.getInstance().getEngine()).getNumeralBaseFromPrefs(preferences)
+ " / " +
((Engine) Locator.getInstance().getEngine()).getAngleUnitsFromPrefs(preferences));
}
}

View File

@ -65,12 +65,12 @@ public class NumeralBaseConverterDialog {
String value = initialFromValue;
try {
value = ToJsclTextProcessor.getInstance().process(value).getExpression();
b.setFromValue(UnitImpl.newInstance(value, CalculatorNumeralBase.valueOf(Locator.getInstance().getEngine().getNumeralBase())));
b.setFromValue(UnitImpl.newInstance(value, CalculatorNumeralBase.valueOf(Locator.getInstance().getEngine().getMathEngine().getNumeralBase())));
} catch (CalculatorParseException e) {
b.setFromValue(UnitImpl.newInstance(value, CalculatorNumeralBase.valueOf(Locator.getInstance().getEngine().getNumeralBase())));
b.setFromValue(UnitImpl.newInstance(value, CalculatorNumeralBase.valueOf(Locator.getInstance().getEngine().getMathEngine().getNumeralBase())));
}
} else {
b.setFromValue(UnitImpl.newInstance("", CalculatorNumeralBase.valueOf(Locator.getInstance().getEngine().getNumeralBase())));
b.setFromValue(UnitImpl.newInstance("", CalculatorNumeralBase.valueOf(Locator.getInstance().getEngine().getMathEngine().getNumeralBase())));
}
b.setConverter(CalculatorNumeralBase.getConverter());
@ -91,7 +91,7 @@ public class NumeralBaseConverterDialog {
public void onClick(@Nonnull Unit<String> fromUnits, @Nonnull Unit<String> toUnits) {
String toUnitsValue = toUnits.getValue();
if (!toUnits.getUnitType().equals(CalculatorNumeralBase.valueOf(Locator.getInstance().getEngine().getNumeralBase()))) {
if (!toUnits.getUnitType().equals(CalculatorNumeralBase.valueOf(Locator.getInstance().getEngine().getMathEngine().getNumeralBase()))) {
toUnitsValue = ((CalculatorNumeralBase) toUnits.getUnitType()).getNumeralBase().getJsclPrefix() + toUnitsValue;
}

View File

@ -47,7 +47,7 @@ public class NumeralBasesButton extends DirectionDragButton {
public NumeralBasesButton(Context context, @Nonnull AttributeSet attrs) {
super(context, attrs);
this.numeralBase = Locator.getInstance().getEngine().getNumeralBase();
this.numeralBase = Locator.getInstance().getEngine().getMathEngine().getNumeralBase();
}
@Override

View File

@ -23,13 +23,15 @@
package org.solovyev.android.calculator.wizard;
import android.content.SharedPreferences;
import jscl.AngleUnit;
import org.solovyev.android.calculator.Engine;
import org.solovyev.android.calculator.Preferences;
import org.solovyev.android.calculator.R;
import javax.annotation.Nonnull;
import jscl.AngleUnit;
import static org.solovyev.android.calculator.Preferences.Gui.Layout.main_calculator;
import static org.solovyev.android.calculator.Preferences.Gui.Layout.main_calculator_mobile;
@ -51,8 +53,8 @@ enum CalculatorMode {
}
Preferences.Calculations.preferredAngleUnits.putPreference(preferences, AngleUnit.deg);
Engine.Preferences.angleUnit.putPreference(preferences, AngleUnit.deg);
Engine.Preferences.scienceNotation.putPreference(preferences, false);
Engine.Preferences.roundResult.putPreference(preferences, true);
Engine.Preferences.Output.scientificNotation.putPreference(preferences, false);
Engine.Preferences.Output.round.putPreference(preferences, true);
}
},
@ -67,8 +69,8 @@ enum CalculatorMode {
}
Preferences.Calculations.preferredAngleUnits.putPreference(preferences, AngleUnit.rad);
Engine.Preferences.angleUnit.putPreference(preferences, AngleUnit.rad);
Engine.Preferences.scienceNotation.putPreference(preferences, true);
Engine.Preferences.roundResult.putPreference(preferences, false);
Engine.Preferences.Output.scientificNotation.putPreference(preferences, true);
Engine.Preferences.Output.round.putPreference(preferences, false);
}
};

View File

@ -21,9 +21,6 @@
-->
<resources>
<string name="p_calc_result_precision_key" translatable="false">org.solovyev.android.calculator.CalculatorModel_result_precision</string>
<string name="p_calc_result_precision" translatable="false">5</string>
<string name="p_calc_color_display_key" translatable="false">org.solovyev.android.calculator.CalculatorModel_color_display</string>
<string name="p_calc_color_display" translatable="false">true</string>
@ -39,36 +36,14 @@
</string>
<string name="p_calc_show_release_notes" translatable="false">true</string>
<string name="p_calc_round_result_key" translatable="false">org.solovyev.android.calculator.CalculatorModel_round_result</string>
<string name="p_calc_round_result" translatable="false">true</string>
<string name="p_calc_science_notation_key" translatable="false">calculation.output.science_notation</string>
<string name="p_calc_science_notation" translatable="false">false</string>
<string name="p_calc_history" translatable="false">org.solovyev.android.calculator.CalculatorModel_history</string>
<string name="p_calc_angle_units_key" translatable="false">org.solovyev.android.calculator.CalculatorActivity_angle_units</string>
<string name="p_calc_angle_units" translatable="false">deg</string>
<string name="p_calc_numeral_bases_key" translatable="false">org.solovyev.android.calculator.CalculatorActivity_numeral_bases</string>
<string name="p_calc_numeral_bases" translatable="false">dec</string>
<string name="p_calc_theme_key" translatable="false">org.solovyev.android.calculator.CalculatorActivity_calc_theme</string>
<string name="p_calc_theme" translatable="false">default_theme</string>
<string name="p_calc_layout_key" translatable="false">org.solovyev.android.calculator.CalculatorActivity_calc_layout</string>
<string name="p_calc_layout" translatable="false">main_calculator</string>
<string name="p_calc_grouping_separator_key" translatable="false">
org.solovyev.android.calculator.CalculatorActivity_calc_grouping_separator
</string>
<string name="p_calc_grouping_separator" translatable="false">" "</string>
<string name="p_calc_multiplication_sign_key" translatable="false">
org.solovyev.android.calculator.CalculatorActivity_calc_multiplication_sign
</string>
<string name="p_calc_multiplication_sign" translatable="false">"×"</string>
<string name="p_calc_ad_free" translatable="false">false</string>
</resources>

View File

@ -39,7 +39,7 @@
<ListPreference
a:entries="@array/p_multiplication_sign_values"
a:entryValues="@array/p_multiplication_sign_values"
a:key="@string/p_calc_multiplication_sign_key"
a:key="engine.multiplicationSign"
a:summary="@string/c_calc_multiplication_sign_summary"
a:title="@string/c_calc_multiplication_sign" />

View File

@ -27,27 +27,27 @@
<android.preference.CheckBoxPreference
a:defaultValue="true"
a:key="@string/p_calc_round_result_key"
a:key="engine.output.round"
a:summary="@string/c_calc_round_result_summary"
a:title="@string/c_calc_round_result_title" />
<org.solovyev.android.prefs.IntegerPickerDialogPreference
a:defaultValue="5"
a:key="@string/p_calc_result_precision_key"
a:key="engine.output.precision"
a:summary="@string/c_calc_result_precision_summary"
a:title="@string/p_calc_result_precision_title"
range:boundaries="0;16" />
<android.preference.CheckBoxPreference
a:defaultValue="false"
a:key="@string/p_calc_science_notation_key"
a:key="engine.output.scientificNotation"
a:summary="@string/c_calc_science_notation_summary"
a:title="@string/c_calc_science_notation_title" />
<ListPreference
a:entries="@array/p_grouping_separator_names"
a:entryValues="@array/p_grouping_separator_values"
a:key="@string/p_calc_grouping_separator_key"
a:key="engine.groupingSeparator"
a:summary="@string/c_calc_grouping_separator_summary"
a:title="@string/c_calc_grouping_separator" />
@ -61,7 +61,7 @@
<ListPreference
a:entries="@array/p_angle_units_names"
a:entryValues="@array/p_angle_units"
a:key="@string/p_calc_angle_units_key"
a:key="engine.angleUnit"
a:summary="@string/c_angle_units_summary"
a:title="@string/c_calc_angle_units" />
@ -75,7 +75,7 @@
<ListPreference
a:entries="@array/p_numeral_bases_names"
a:entryValues="@array/p_numeral_bases"
a:key="@string/p_calc_numeral_bases_key"
a:key="engine.numeralBase"
a:summary="@string/c_numeral_bases_summary"
a:title="@string/c_calc_numeral_bases" />

View File

@ -37,7 +37,12 @@ public class AbstractCalculatorTest {
protected void setUp() throws Exception {
Locator.getInstance().init(new CalculatorImpl(Mockito.mock(Bus.class), Mockito.mock(Executor.class)), CalculatorTestUtils.newCalculatorEngine(), Mockito.mock(CalculatorClipboard.class), Mockito.mock(CalculatorNotifier.class), new SystemErrorReporter(), Mockito.mock(CalculatorPreferenceService.class), Mockito.mock(Keyboard.class), Mockito.mock(CalculatorPlotter.class));
Locator.getInstance().getEngine().init();
Locator.getInstance().getEngine().init(new Executor() {
@Override
public void execute(Runnable command) {
command.run();
}
});
}
}

View File

@ -23,19 +23,22 @@
package org.solovyev.android.calculator;
import android.content.Context;
import com.squareup.otto.Bus;
import jscl.JsclMathEngine;
import org.junit.Assert;
import org.mockito.Mockito;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.fakes.RoboSharedPreferences;
import org.solovyev.android.calculator.jscl.JsclOperation;
import org.solovyev.android.calculator.language.Languages;
import org.solovyev.android.calculator.plot.CalculatorPlotter;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.io.*;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.text.DecimalFormatSymbols;
import java.util.HashMap;
import java.util.Map;
@ -43,6 +46,11 @@ import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Executor;
import java.util.concurrent.TimeUnit;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import jscl.JsclMathEngine;
/**
* User: serso
* Date: 10/7/12
@ -56,17 +64,27 @@ public class CalculatorTestUtils {
public static void staticSetUp() throws Exception {
App.init(new CalculatorApplication(), new Languages(new RoboSharedPreferences(new HashMap<String, Map<String, Object>>(), "test", 0)));
Locator.getInstance().init(new CalculatorImpl(Mockito.mock(Bus.class), Mockito.mock(Executor.class)), newCalculatorEngine(), Mockito.mock(CalculatorClipboard.class), Mockito.mock(CalculatorNotifier.class), new SystemErrorReporter(), Mockito.mock(CalculatorPreferenceService.class), Mockito.mock(Keyboard.class), Mockito.mock(CalculatorPlotter.class));
Locator.getInstance().getEngine().init();
Locator.getInstance().getEngine().init(new Executor() {
@Override
public void execute(Runnable command) {
command.run();
}
});
final DecimalFormatSymbols decimalGroupSymbols = new DecimalFormatSymbols();
decimalGroupSymbols.setDecimalSeparator('.');
decimalGroupSymbols.setGroupingSeparator(' ');
Locator.getInstance().getEngine().setDecimalGroupSymbols(decimalGroupSymbols);
Locator.getInstance().getEngine().getMathEngine().setDecimalGroupSymbols(decimalGroupSymbols);
}
public static void staticSetUp(@Nullable Context context) throws Exception {
Locator.getInstance().init(new CalculatorImpl(Mockito.mock(Bus.class), Mockito.mock(Executor.class)), newCalculatorEngine(), Mockito.mock(CalculatorClipboard.class), Mockito.mock(CalculatorNotifier.class), new SystemErrorReporter(), Mockito.mock(CalculatorPreferenceService.class), Mockito.mock(Keyboard.class), Mockito.mock(CalculatorPlotter.class));
Locator.getInstance().getEngine().init();
Locator.getInstance().getEngine().init(new Executor() {
@Override
public void execute(Runnable command) {
command.run();
}
});
if (context != null) {
initViews(context);
@ -89,7 +107,7 @@ public class CalculatorTestUtils {
final OperatorsRegistry operatorsRegistry = new OperatorsRegistry(jsclEngine.getOperatorsRegistry(), mathEntityDao);
final PostfixFunctionsRegistry postfixFunctionsRegistry = new PostfixFunctionsRegistry(jsclEngine.getPostfixFunctionsRegistry(), mathEntityDao);
return new Engine(RuntimeEnvironment.application, jsclEngine, varsRegistry, functionsRegistry, operatorsRegistry, postfixFunctionsRegistry);
return new Engine(jsclEngine, varsRegistry, functionsRegistry, operatorsRegistry, postfixFunctionsRegistry);
}
public static void assertEval(@Nonnull String expected, @Nonnull String expression) {

View File

@ -50,7 +50,7 @@ public class FromJsclSimplifyTextProcessorTest extends AbstractCalculatorTest {
//Assert.assertEquals("((e)(e))", tp.process("((2.718281828459045)*(2.718281828459045))"));
DecimalFormatSymbols decimalGroupSymbols = new DecimalFormatSymbols();
decimalGroupSymbols.setGroupingSeparator(' ');
Locator.getInstance().getEngine().setDecimalGroupSymbols(decimalGroupSymbols);
Locator.getInstance().getEngine().getMathEngine().setDecimalGroupSymbols(decimalGroupSymbols);
//Assert.assertEquals("123 456 789e", tp.process("123456789*2.718281828459045"));
//Assert.assertEquals("123 456 789e", tp.process("123 456 789 * 2.718281828459045"));
//Assert.assertEquals("t11e", tp.process("t11*2.718281828459045"));

View File

@ -58,7 +58,7 @@ public class AndroidEngineTest extends AbstractCalculatorTest {
@BeforeClass
public static void staticSetUp() throws Exception {
CalculatorTestUtils.staticSetUp();
Locator.getInstance().getEngine().setPrecision(3);
Locator.getInstance().getEngine().getMathEngine().setPrecision(3);
}

View File

@ -41,7 +41,7 @@ public class ComparisonTest extends AbstractCalculatorTest {
@BeforeClass
public static void staticSetUp() throws Exception {
CalculatorTestUtils.staticSetUp();
Locator.getInstance().getEngine().setPrecision(3);
Locator.getInstance().getEngine().getMathEngine().setPrecision(3);
}
@Test

View File

@ -49,7 +49,7 @@ public class EvaluateTest extends AbstractCalculatorTest {
@BeforeClass
public static void staticSetUp() throws Exception {
CalculatorTestUtils.staticSetUp();
Locator.getInstance().getEngine().setPrecision(3);
Locator.getInstance().getEngine().getMathEngine().setPrecision(3);
}
@Test

View File

@ -22,22 +22,28 @@
package org.solovyev.android.calculator.model;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import org.solovyev.android.calculator.AbstractCalculatorTest;
import org.solovyev.android.calculator.CalculatorEvalException;
import org.solovyev.android.calculator.CalculatorParseException;
import org.solovyev.android.calculator.CalculatorTestUtils;
import org.solovyev.android.calculator.Locator;
import org.solovyev.common.Converter;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.Nonnull;
import au.com.bytecode.opencsv.CSVReader;
import jscl.JsclMathEngine;
import jscl.MathEngine;
import jscl.math.Expression;
import jscl.text.ParseException;
import jscl.util.ExpressionGeneratorWithInput;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import org.solovyev.android.calculator.*;
import org.solovyev.common.Converter;
import javax.annotation.Nonnull;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
/**
* User: serso
@ -49,7 +55,7 @@ public class NumeralBaseTest extends AbstractCalculatorTest {
@BeforeClass
public static void staticSetUp() throws Exception {
CalculatorTestUtils.staticSetUp();
Locator.getInstance().getEngine().setPrecision(3);
Locator.getInstance().getEngine().getMathEngine().setPrecision(3);
}
public static void testExpression(@Nonnull String[] line, @Nonnull Converter<String, String> converter) throws ParseException, CalculatorEvalException, CalculatorParseException {

View File

@ -87,10 +87,10 @@ public class ToJsclTextProcessorTest extends AbstractCalculatorTest {
Assert.assertEquals("EE", preprocessor.process("EE").toString());
try {
Locator.getInstance().getEngine().setNumeralBase(NumeralBase.hex);
Locator.getInstance().getEngine().getMathEngine().setNumeralBase(NumeralBase.hex);
Assert.assertEquals("22F*exp(F)", preprocessor.process("22Fexp(F)").toString());
} finally {
Locator.getInstance().getEngine().setNumeralBase(NumeralBase.dec);
Locator.getInstance().getEngine().getMathEngine().setNumeralBase(NumeralBase.dec);
}
Assert.assertEquals("0x:ABCDEF", preprocessor.process("0x:ABCDEF").toString());
Assert.assertEquals("0x:ABCDEF", preprocessor.process("0x:A BC DEF").toString());