Changes
This commit is contained in:
parent
bbaedc71c9
commit
81510d18ea
@ -109,7 +109,7 @@ public class AndroidCalculator implements Calculator, CalculatorEventListener, S
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public PreparedExpression prepareExpression(@Nonnull String expression) throws CalculatorParseException {
|
||||
public PreparedExpression prepareExpression(@Nonnull String expression) throws ParseException {
|
||||
return calculator.prepareExpression(expression);
|
||||
}
|
||||
|
||||
|
@ -22,15 +22,13 @@
|
||||
|
||||
package org.solovyev.android.calculator;
|
||||
|
||||
import jscl.NumeralBase;
|
||||
import jscl.math.Generic;
|
||||
import org.solovyev.android.calculator.jscl.JsclOperation;
|
||||
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import jscl.NumeralBase;
|
||||
import jscl.math.Generic;
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
/**
|
||||
* User: Solovyev_S
|
||||
@ -98,5 +96,5 @@ public interface Calculator extends CalculatorEventContainer {
|
||||
CalculatorEventData fireCalculatorEvent(@Nonnull CalculatorEventType calculatorEventType, @Nullable Object data, @Nonnull Long sequenceId);
|
||||
|
||||
@Nonnull
|
||||
PreparedExpression prepareExpression(@Nonnull String expression) throws CalculatorParseException;
|
||||
PreparedExpression prepareExpression(@Nonnull String expression) throws ParseException;
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ public interface CalculatorFailure {
|
||||
Exception getException();
|
||||
|
||||
@Nullable
|
||||
CalculatorParseException getCalculationParseException();
|
||||
ParseException getCalculationParseException();
|
||||
|
||||
@Nullable
|
||||
CalculatorEvalException getCalculationEvalException();
|
||||
|
@ -45,8 +45,8 @@ public class CalculatorFailureImpl implements CalculatorFailure {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CalculatorParseException getCalculationParseException() {
|
||||
return exception instanceof CalculatorParseException ? (CalculatorParseException) exception : null;
|
||||
public ParseException getCalculationParseException() {
|
||||
return exception instanceof ParseException ? (ParseException) exception : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -24,13 +24,18 @@ 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.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;
|
||||
import org.solovyev.android.calculator.units.CalculatorNumeralBase;
|
||||
import org.solovyev.common.msg.ListMessageRegistry;
|
||||
import org.solovyev.common.msg.Message;
|
||||
@ -40,24 +45,14 @@ 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;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import jscl.AbstractJsclArithmeticException;
|
||||
import jscl.MathEngine;
|
||||
import jscl.NumeralBase;
|
||||
import jscl.NumeralBaseException;
|
||||
import jscl.math.Generic;
|
||||
import jscl.math.function.IConstant;
|
||||
import jscl.math.operator.Operator;
|
||||
import jscl.text.ParseInterruptedException;
|
||||
|
||||
public class CalculatorImpl implements Calculator, CalculatorEventListener {
|
||||
|
||||
// one minute
|
||||
@ -70,7 +65,7 @@ public class CalculatorImpl implements Calculator, CalculatorEventListener {
|
||||
private final AtomicLong counter = new AtomicLong(CalculatorUtils.FIRST_ID);
|
||||
|
||||
@Nonnull
|
||||
private final TextProcessor<PreparedExpression, String> preprocessor = ToJsclTextProcessor.getInstance();
|
||||
private final ToJsclTextProcessor preprocessor = ToJsclTextProcessor.getInstance();
|
||||
|
||||
@Nonnull
|
||||
private final Executor calculationsExecutor = Executors.newFixedThreadPool(10);
|
||||
@ -101,7 +96,7 @@ public class CalculatorImpl implements Calculator, CalculatorEventListener {
|
||||
if (!Strings.isEmpty(fromString)) {
|
||||
try {
|
||||
fromString = ToJsclTextProcessor.getInstance().process(fromString).getExpression();
|
||||
} catch (CalculatorParseException e) {
|
||||
} catch (ParseException e) {
|
||||
// ok, problems while processing occurred
|
||||
}
|
||||
}
|
||||
@ -272,17 +267,17 @@ public class CalculatorImpl implements Calculator, CalculatorEventListener {
|
||||
}
|
||||
|
||||
} catch (ArithmeticException e) {
|
||||
handleException(sequenceId, operation, expression, mr, preparedExpression, new CalculatorParseException(expression, new CalculatorMessage(CalculatorMessages.msg_001, MessageType.error, e.getMessage())));
|
||||
handleException(sequenceId, operation, expression, mr, preparedExpression, new ParseException(expression, new CalculatorMessage(CalculatorMessages.msg_001, MessageType.error, e.getMessage())));
|
||||
} catch (StackOverflowError e) {
|
||||
handleException(sequenceId, operation, expression, mr, preparedExpression, new CalculatorParseException(expression, new CalculatorMessage(CalculatorMessages.msg_002, MessageType.error)));
|
||||
handleException(sequenceId, operation, expression, mr, preparedExpression, new ParseException(expression, new CalculatorMessage(CalculatorMessages.msg_002, MessageType.error)));
|
||||
} catch (jscl.text.ParseException e) {
|
||||
handleException(sequenceId, operation, expression, mr, preparedExpression, new CalculatorParseException(e));
|
||||
handleException(sequenceId, operation, expression, mr, preparedExpression, new ParseException(e));
|
||||
} catch (ParseInterruptedException e) {
|
||||
|
||||
// do nothing - we ourselves interrupt the calculations
|
||||
fireCalculatorEvent(newCalculationEventData(operation, expression, sequenceId), CalculatorEventType.calculation_cancelled, null);
|
||||
|
||||
} catch (CalculatorParseException e) {
|
||||
} catch (ParseException e) {
|
||||
handleException(sequenceId, operation, expression, mr, preparedExpression, e);
|
||||
}
|
||||
}
|
||||
@ -298,7 +293,7 @@ public class CalculatorImpl implements Calculator, CalculatorEventListener {
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public PreparedExpression prepareExpression(@Nonnull String expression) throws CalculatorParseException {
|
||||
public PreparedExpression prepareExpression(@Nonnull String expression) throws ParseException {
|
||||
return preprocessor.process(expression);
|
||||
}
|
||||
|
||||
@ -314,7 +309,7 @@ public class CalculatorImpl implements Calculator, CalculatorEventListener {
|
||||
@Nonnull String expression,
|
||||
@Nullable MessageRegistry mr,
|
||||
@Nullable PreparedExpression preparedExpression,
|
||||
@Nonnull CalculatorParseException parseException) {
|
||||
@Nonnull ParseException parseException) {
|
||||
|
||||
if (operation == JsclOperation.numeric
|
||||
&& preparedExpression != null
|
||||
|
@ -24,22 +24,14 @@ package org.solovyev.android.calculator;
|
||||
|
||||
import org.solovyev.common.msg.MessageType;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Locale;
|
||||
import java.util.MissingResourceException;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import static org.solovyev.common.msg.MessageType.*;
|
||||
|
||||
import static org.solovyev.common.msg.MessageType.error;
|
||||
import static org.solovyev.common.msg.MessageType.info;
|
||||
import static org.solovyev.common.msg.MessageType.warning;
|
||||
|
||||
/**
|
||||
* User: serso
|
||||
* Date: 9/20/12
|
||||
* Time: 8:10 PM
|
||||
*/
|
||||
public final class CalculatorMessages {
|
||||
|
||||
|
||||
|
@ -130,7 +130,7 @@ public class Display implements CalculatorEventListener {
|
||||
if (calculatorEvalException != null) {
|
||||
errorMessage = CalculatorMessages.getBundle().getString(CalculatorMessages.syntax_error);
|
||||
} else {
|
||||
final CalculatorParseException calculationParseException = data.getCalculationParseException();
|
||||
final ParseException calculationParseException = data.getCalculationParseException();
|
||||
if (calculationParseException != null) {
|
||||
errorMessage = calculationParseException.getLocalizedMessage();
|
||||
} else {
|
||||
|
@ -106,7 +106,7 @@ public class DisplayView extends AutoResizeTextView {
|
||||
}
|
||||
try {
|
||||
return textHighlighter.process(text).getCharSequence();
|
||||
} catch (CalculatorParseException e) {
|
||||
} catch (ParseException e) {
|
||||
return text;
|
||||
}
|
||||
}
|
||||
|
@ -25,18 +25,12 @@ package org.solovyev.android.calculator;
|
||||
import org.solovyev.common.msg.Message;
|
||||
import org.solovyev.common.msg.MessageLevel;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* User: serso
|
||||
* Date: 10/6/11
|
||||
* Time: 9:25 PM
|
||||
*/
|
||||
public class CalculatorParseException extends Exception implements Message {
|
||||
public class ParseException extends RuntimeException implements Message {
|
||||
|
||||
@Nonnull
|
||||
private final Message message;
|
||||
@ -47,22 +41,22 @@ public class CalculatorParseException extends Exception implements Message {
|
||||
@Nullable
|
||||
private final Integer position;
|
||||
|
||||
public CalculatorParseException(@Nonnull jscl.text.ParseException jsclParseException) {
|
||||
public ParseException(@Nonnull jscl.text.ParseException jsclParseException) {
|
||||
this.message = jsclParseException;
|
||||
this.expression = jsclParseException.getExpression();
|
||||
this.position = jsclParseException.getPosition();
|
||||
}
|
||||
|
||||
public CalculatorParseException(@Nullable Integer position,
|
||||
@Nonnull String expression,
|
||||
@Nonnull Message message) {
|
||||
public ParseException(@Nullable Integer position,
|
||||
@Nonnull String expression,
|
||||
@Nonnull Message message) {
|
||||
this.message = message;
|
||||
this.expression = expression;
|
||||
this.position = position;
|
||||
}
|
||||
|
||||
public CalculatorParseException(@Nonnull String expression,
|
||||
@Nonnull Message message) {
|
||||
public ParseException(@Nonnull String expression,
|
||||
@Nonnull Message message) {
|
||||
this(null, expression, message);
|
||||
}
|
||||
|
@ -22,17 +22,12 @@
|
||||
|
||||
package org.solovyev.android.calculator;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
import jscl.math.function.IConstant;
|
||||
|
||||
/**
|
||||
* User: serso
|
||||
* Date: 10/18/11
|
||||
* Time: 10:07 PM
|
||||
*/
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.List;
|
||||
|
||||
public class PreparedExpression implements CharSequence {
|
||||
|
||||
@Nonnull
|
||||
@ -75,6 +70,7 @@ public class PreparedExpression implements CharSequence {
|
||||
return expression.subSequence(i, i1);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.expression;
|
||||
|
@ -22,43 +22,40 @@
|
||||
|
||||
package org.solovyev.android.calculator;
|
||||
|
||||
import jscl.math.function.Function;
|
||||
import jscl.math.function.IConstant;
|
||||
import org.solovyev.android.calculator.math.MathType;
|
||||
import org.solovyev.android.calculator.text.TextProcessor;
|
||||
import org.solovyev.common.collections.Collections;
|
||||
import org.solovyev.common.msg.MessageType;
|
||||
import org.solovyev.common.search.StartsWithFinder;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import jscl.math.function.Function;
|
||||
import jscl.math.function.IConstant;
|
||||
|
||||
public class ToJsclTextProcessor implements TextProcessor<PreparedExpression, String> {
|
||||
|
||||
@Nonnull
|
||||
private static final Integer MAX_DEPTH = 20;
|
||||
|
||||
@Nonnull
|
||||
private static final TextProcessor<PreparedExpression, String> instance = new ToJsclTextProcessor();
|
||||
private static final ToJsclTextProcessor instance = new ToJsclTextProcessor();
|
||||
|
||||
private ToJsclTextProcessor() {
|
||||
}
|
||||
|
||||
|
||||
@Nonnull
|
||||
public static TextProcessor<PreparedExpression, String> getInstance() {
|
||||
public static ToJsclTextProcessor getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
private static PreparedExpression processWithDepth(@Nonnull String s, int depth, @Nonnull List<IConstant> undefinedVars) throws CalculatorParseException {
|
||||
private static PreparedExpression processWithDepth(@Nonnull String s, int depth, @Nonnull List<IConstant> undefinedVars) throws ParseException {
|
||||
return replaceVariables(processExpression(s).toString(), depth, undefinedVars);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
private static StringBuilder processExpression(@Nonnull String s) throws CalculatorParseException {
|
||||
private static StringBuilder processExpression(@Nonnull String s) throws ParseException {
|
||||
final StartsWithFinder startsWithFinder = StartsWithFinder.newInstance(s);
|
||||
final StringBuilder result = new StringBuilder();
|
||||
|
||||
@ -91,7 +88,7 @@ public class ToJsclTextProcessor implements TextProcessor<PreparedExpression, St
|
||||
final String functionName = mathTypeBefore.match;
|
||||
final Function function = Locator.getInstance().getEngine().getFunctionsRegistry().get(functionName);
|
||||
if (function == null || function.getMinParameters() > 0) {
|
||||
throw new CalculatorParseException(i, s, new CalculatorMessage(CalculatorMessages.msg_005, MessageType.error, mathTypeBefore.match));
|
||||
throw new ParseException(i, s, new CalculatorMessage(CalculatorMessages.msg_005, MessageType.error, mathTypeBefore.match));
|
||||
}
|
||||
}
|
||||
|
||||
@ -101,9 +98,9 @@ public class ToJsclTextProcessor implements TextProcessor<PreparedExpression, St
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
private static PreparedExpression replaceVariables(@Nonnull final String s, int depth, @Nonnull List<IConstant> undefinedVars) throws CalculatorParseException {
|
||||
private static PreparedExpression replaceVariables(@Nonnull final String s, int depth, @Nonnull List<IConstant> undefinedVars) throws ParseException {
|
||||
if (depth >= MAX_DEPTH) {
|
||||
throw new CalculatorParseException(s, new CalculatorMessage(CalculatorMessages.msg_006, MessageType.error));
|
||||
throw new ParseException(s, new CalculatorMessage(CalculatorMessages.msg_006, MessageType.error));
|
||||
} else {
|
||||
depth++;
|
||||
}
|
||||
@ -164,7 +161,7 @@ public class ToJsclTextProcessor implements TextProcessor<PreparedExpression, St
|
||||
|
||||
@Override
|
||||
@Nonnull
|
||||
public PreparedExpression process(@Nonnull String s) throws CalculatorParseException {
|
||||
public PreparedExpression process(@Nonnull String s) throws ParseException {
|
||||
return processWithDepth(s, 0, new ArrayList<IConstant>());
|
||||
}
|
||||
}
|
||||
|
@ -36,49 +36,26 @@ import android.support.v7.app.AlertDialog;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.text.Editable;
|
||||
import android.text.TextUtils;
|
||||
import android.view.ContextMenu;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.ViewParent;
|
||||
import android.view.*;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
|
||||
import org.solovyev.android.Check;
|
||||
import org.solovyev.android.calculator.App;
|
||||
import org.solovyev.android.calculator.AppComponent;
|
||||
import org.solovyev.android.calculator.BaseDialogFragment;
|
||||
import org.solovyev.android.calculator.Calculator;
|
||||
import org.solovyev.android.calculator.CalculatorEventType;
|
||||
import org.solovyev.android.calculator.FunctionsRegistry;
|
||||
import org.solovyev.android.calculator.KeyboardUi;
|
||||
import org.solovyev.android.calculator.KeyboardWindow;
|
||||
import org.solovyev.android.calculator.Locator;
|
||||
import org.solovyev.android.calculator.R;
|
||||
import org.solovyev.android.calculator.math.edit.CalculatorFunctionsActivity;
|
||||
import org.solovyev.android.calculator.math.edit.FunctionsFragment;
|
||||
import org.solovyev.android.calculator.math.edit.VarEditorSaver;
|
||||
import org.solovyev.common.math.MathRegistry;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import javax.inject.Inject;
|
||||
|
||||
import butterknife.Bind;
|
||||
import butterknife.ButterKnife;
|
||||
import jscl.math.function.CustomFunction;
|
||||
import jscl.math.function.Function;
|
||||
import jscl.math.function.IConstant;
|
||||
import org.solovyev.android.Check;
|
||||
import org.solovyev.android.calculator.*;
|
||||
import org.solovyev.android.calculator.math.edit.CalculatorFunctionsActivity;
|
||||
import org.solovyev.android.calculator.math.edit.FunctionsFragment;
|
||||
import org.solovyev.android.calculator.math.edit.VarEditorSaver;
|
||||
import org.solovyev.common.math.MathRegistry;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import javax.inject.Inject;
|
||||
import java.util.*;
|
||||
|
||||
import static org.solovyev.android.calculator.function.CppFunction.NO_ID;
|
||||
|
||||
@ -305,12 +282,18 @@ public class EditFunctionFragment extends BaseDialogFragment implements View.OnC
|
||||
}
|
||||
|
||||
private void applyData() {
|
||||
final CppFunction newFunction = CppFunction.builder(nameView.getText().toString(), bodyView.getText().toString())
|
||||
.withId(function == null ? NO_ID : function.id)
|
||||
.withParameters(collectParameters())
|
||||
.withDescription(descriptionView.getText().toString()).build();
|
||||
final Function oldFunction = (function == null || function.id == NO_ID) ? null : registry.getById(function.id);
|
||||
registry.add(newFunction.toCustomFunctionBuilder(), oldFunction);
|
||||
try {
|
||||
final String body = calculator.prepareExpression(bodyView.getText().toString()).getExpression();
|
||||
|
||||
final CppFunction newFunction = CppFunction.builder(nameView.getText().toString(), body)
|
||||
.withId(function == null ? NO_ID : function.id)
|
||||
.withParameters(collectParameters())
|
||||
.withDescription(descriptionView.getText().toString()).build();
|
||||
final Function oldFunction = (function == null || function.id == NO_ID) ? null : registry.getById(function.id);
|
||||
registry.add(newFunction.toCustomFunctionBuilder(), oldFunction);
|
||||
} catch (ParseException e) {
|
||||
setError(bodyLabel, e.getLocalizedMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private boolean validate() {
|
||||
@ -345,8 +328,14 @@ public class EditFunctionFragment extends BaseDialogFragment implements View.OnC
|
||||
setError(bodyLabel, getString(R.string.function_is_empty));
|
||||
return false;
|
||||
}
|
||||
clearError(bodyLabel);
|
||||
return true;
|
||||
try {
|
||||
calculator.prepareExpression(body);
|
||||
clearError(bodyLabel);
|
||||
return true;
|
||||
} catch (ParseException e) {
|
||||
setError(bodyLabel, e.getLocalizedMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private boolean validateParameters() {
|
||||
|
@ -22,25 +22,18 @@
|
||||
|
||||
package org.solovyev.android.calculator.jscl;
|
||||
|
||||
import org.solovyev.android.calculator.CalculatorParseException;
|
||||
import jscl.math.Generic;
|
||||
import org.solovyev.android.calculator.text.TextProcessor;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import jscl.math.Generic;
|
||||
|
||||
/**
|
||||
* User: serso
|
||||
* Date: 10/6/11
|
||||
* Time: 9:48 PM
|
||||
*/
|
||||
class FromJsclNumericTextProcessor implements TextProcessor<String, Generic> {
|
||||
|
||||
public static final FromJsclNumericTextProcessor instance = new FromJsclNumericTextProcessor();
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public String process(@Nonnull Generic numeric) throws CalculatorParseException {
|
||||
public String process(@Nonnull Generic numeric) {
|
||||
return numeric.toString().replace("*", "");
|
||||
}
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ package org.solovyev.android.calculator.math;
|
||||
import jscl.JsclMathEngine;
|
||||
import jscl.NumeralBase;
|
||||
import jscl.math.function.Constants;
|
||||
import org.solovyev.android.calculator.CalculatorParseException;
|
||||
import org.solovyev.android.calculator.ParseException;
|
||||
import org.solovyev.android.calculator.Locator;
|
||||
import org.solovyev.common.JPredicate;
|
||||
import org.solovyev.common.collections.Collections;
|
||||
@ -65,7 +65,7 @@ public enum MathType {
|
||||
|
||||
grouping_separator(250, false, false, MathGroupType.number, "'", " ") {
|
||||
@Override
|
||||
public int processToJscl(@Nonnull StringBuilder result, int i, @Nonnull String match) throws CalculatorParseException {
|
||||
public int processToJscl(@Nonnull StringBuilder result, int i, @Nonnull String match) throws ParseException {
|
||||
return i;
|
||||
}
|
||||
},
|
||||
@ -347,7 +347,7 @@ public enum MathType {
|
||||
return needMultiplicationSignBefore && mathTypeBefore.isNeedMultiplicationSignAfter();
|
||||
}
|
||||
|
||||
public int processToJscl(@Nonnull StringBuilder result, int i, @Nonnull String match) throws CalculatorParseException {
|
||||
public int processToJscl(@Nonnull StringBuilder result, int i, @Nonnull String match) throws ParseException {
|
||||
final String substitute = getSubstituteToJscl(match);
|
||||
result.append(substitute == null ? match : substitute);
|
||||
return returnI(i, match);
|
||||
@ -400,7 +400,7 @@ public enum MathType {
|
||||
this.match = match;
|
||||
}
|
||||
|
||||
public int processToJscl(@Nonnull StringBuilder result, int i) throws CalculatorParseException {
|
||||
public int processToJscl(@Nonnull StringBuilder result, int i) throws ParseException {
|
||||
return type.processToJscl(result, i, match);
|
||||
}
|
||||
}
|
||||
|
@ -28,32 +28,18 @@ import android.support.v4.app.FragmentActivity;
|
||||
import android.view.ContextMenu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
|
||||
import com.melnykov.fab.FloatingActionButton;
|
||||
|
||||
import org.solovyev.android.calculator.CalculatorEventData;
|
||||
import org.solovyev.android.calculator.CalculatorEventListener;
|
||||
import org.solovyev.android.calculator.CalculatorEventType;
|
||||
import org.solovyev.android.calculator.CalculatorFragmentType;
|
||||
import org.solovyev.android.calculator.CalculatorParseException;
|
||||
import org.solovyev.android.calculator.Change;
|
||||
import org.solovyev.android.calculator.EntitiesRegistry;
|
||||
import org.solovyev.android.calculator.Locator;
|
||||
import org.solovyev.android.calculator.PreparedExpression;
|
||||
import org.solovyev.android.calculator.R;
|
||||
import org.solovyev.android.calculator.ToJsclTextProcessor;
|
||||
import jscl.math.function.IConstant;
|
||||
import org.solovyev.android.calculator.*;
|
||||
import org.solovyev.android.calculator.math.MathType;
|
||||
import org.solovyev.common.JPredicate;
|
||||
import org.solovyev.common.collections.Collections;
|
||||
import org.solovyev.common.text.Strings;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import jscl.math.function.IConstant;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class VarsFragment extends BaseEntitiesFragment<IConstant>implements CalculatorEventListener {
|
||||
|
||||
@ -72,8 +58,6 @@ public class VarsFragment extends BaseEntitiesFragment<IConstant>implements Calc
|
||||
return constants.isEmpty();
|
||||
} catch (RuntimeException e) {
|
||||
return true;
|
||||
} catch (CalculatorParseException e) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -27,7 +27,7 @@ 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.CalculatorParseException;
|
||||
import org.solovyev.android.calculator.ParseException;
|
||||
import org.solovyev.android.calculator.Locator;
|
||||
import org.solovyev.android.calculator.PersistedEntity;
|
||||
import org.solovyev.common.math.MathEntity;
|
||||
@ -252,7 +252,7 @@ public class OldFunction implements IFunction, PersistedEntity, Serializable {
|
||||
result.name = name;
|
||||
try {
|
||||
result.content = Locator.getInstance().getCalculator().prepareExpression(value).toString();
|
||||
} catch (CalculatorParseException e) {
|
||||
} catch (ParseException e) {
|
||||
throw new CreationException(e);
|
||||
}
|
||||
result.system = system;
|
||||
@ -265,9 +265,9 @@ public class OldFunction implements IFunction, PersistedEntity, Serializable {
|
||||
public static class CreationException extends RuntimeException implements Message {
|
||||
|
||||
@Nonnull
|
||||
private final CalculatorParseException message;
|
||||
private final ParseException message;
|
||||
|
||||
public CreationException(@Nonnull CalculatorParseException cause) {
|
||||
public CreationException(@Nonnull ParseException cause) {
|
||||
super(cause);
|
||||
message = cause;
|
||||
}
|
||||
|
@ -22,24 +22,17 @@
|
||||
|
||||
package org.solovyev.android.calculator.text;
|
||||
|
||||
import org.solovyev.android.calculator.CalculatorParseException;
|
||||
import jscl.math.Generic;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import jscl.math.Generic;
|
||||
|
||||
/**
|
||||
* User: serso
|
||||
* Date: 10/18/11
|
||||
* Time: 10:39 PM
|
||||
*/
|
||||
public enum DummyTextProcessor implements TextProcessor<String, Generic> {
|
||||
|
||||
instance;
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public String process(@Nonnull Generic s) throws CalculatorParseException {
|
||||
public String process(@Nonnull Generic s) {
|
||||
return s.toString();
|
||||
}
|
||||
}
|
||||
|
@ -22,23 +22,15 @@
|
||||
|
||||
package org.solovyev.android.calculator.text;
|
||||
|
||||
import org.solovyev.android.calculator.CalculatorParseException;
|
||||
import jscl.math.Generic;
|
||||
import org.solovyev.android.calculator.Locator;
|
||||
import org.solovyev.android.calculator.math.MathType;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import jscl.math.Generic;
|
||||
|
||||
/**
|
||||
* User: serso
|
||||
* Date: 10/20/11
|
||||
* Time: 2:59 PM
|
||||
*/
|
||||
public class FromJsclSimplifyTextProcessor implements TextProcessor<String, Generic> {
|
||||
|
||||
public static final FromJsclSimplifyTextProcessor instance = new FromJsclSimplifyTextProcessor();
|
||||
@ -49,7 +41,7 @@ public class FromJsclSimplifyTextProcessor implements TextProcessor<String, Gene
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public String process(@Nonnull Generic from) throws CalculatorParseException {
|
||||
public String process(@Nonnull Generic from) {
|
||||
return removeMultiplicationSigns(from.toString());
|
||||
}
|
||||
|
||||
|
@ -22,17 +22,10 @@
|
||||
|
||||
package org.solovyev.android.calculator.text;
|
||||
|
||||
import org.solovyev.android.calculator.CalculatorParseException;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
/**
|
||||
* User: serso
|
||||
* Date: 9/26/11
|
||||
* Time: 12:12 PM
|
||||
*/
|
||||
public interface TextProcessor<TO extends CharSequence, FROM> {
|
||||
|
||||
@Nonnull
|
||||
TO process(@Nonnull FROM from) throws CalculatorParseException;
|
||||
TO process(@Nonnull FROM from);
|
||||
}
|
||||
|
@ -26,9 +26,8 @@ import android.app.AlertDialog;
|
||||
import android.content.Context;
|
||||
import android.view.View;
|
||||
import android.view.WindowManager;
|
||||
|
||||
import org.solovyev.android.calculator.CalculatorParseException;
|
||||
import org.solovyev.android.calculator.Locator;
|
||||
import org.solovyev.android.calculator.ParseException;
|
||||
import org.solovyev.android.calculator.R;
|
||||
import org.solovyev.android.calculator.ToJsclTextProcessor;
|
||||
import org.solovyev.android.calculator.units.CalculatorNumeralBase;
|
||||
@ -37,10 +36,9 @@ import org.solovyev.common.text.Strings;
|
||||
import org.solovyev.common.units.Unit;
|
||||
import org.solovyev.common.units.UnitImpl;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* User: serso
|
||||
@ -66,7 +64,7 @@ public class NumeralBaseConverterDialog {
|
||||
try {
|
||||
value = ToJsclTextProcessor.getInstance().process(value).getExpression();
|
||||
b.setFromValue(UnitImpl.newInstance(value, CalculatorNumeralBase.valueOf(Locator.getInstance().getEngine().getMathEngine().getNumeralBase())));
|
||||
} catch (CalculatorParseException e) {
|
||||
} catch (ParseException e) {
|
||||
b.setFromValue(UnitImpl.newInstance(value, CalculatorNumeralBase.valueOf(Locator.getInstance().getEngine().getMathEngine().getNumeralBase())));
|
||||
}
|
||||
} else {
|
||||
|
@ -95,7 +95,7 @@ public class CalculatorTestUtils {
|
||||
final JsclMathEngine jsclEngine = JsclMathEngine.getInstance();
|
||||
|
||||
final VarsRegistry varsRegistry = new VarsRegistry(jsclEngine.getConstantsRegistry(), entityDao);
|
||||
final FunctionsRegistry functionsRegistry = new FunctionsRegistry(jsclEngine.getFunctionsRegistry());
|
||||
final FunctionsRegistry functionsRegistry = new FunctionsRegistry(jsclEngine);
|
||||
final OperatorsRegistry operatorsRegistry = new OperatorsRegistry(jsclEngine.getOperatorsRegistry());
|
||||
final PostfixFunctionsRegistry postfixFunctionsRegistry = new PostfixFunctionsRegistry(jsclEngine.getPostfixFunctionsRegistry());
|
||||
|
||||
|
@ -132,7 +132,7 @@ public class HistoryTest {
|
||||
}
|
||||
|
||||
private void addState(@Nonnull String text) {
|
||||
history.addRecent(HistoryState.builder(EditorState.create(text, 3), DisplayState.empty()));
|
||||
history.addRecent(HistoryState.builder(EditorState.create(text, 3), DisplayState.empty()).build());
|
||||
}
|
||||
|
||||
private static final String oldXml1 = "<history>\n" +
|
||||
@ -281,7 +281,7 @@ public class HistoryTest {
|
||||
|
||||
@Test
|
||||
public void testShouldLoadStates() throws Exception {
|
||||
final List<HistoryState> states = Json.load(new File(HistoryTest.class.getResource("recent-history.json").getFile()));
|
||||
final List<HistoryState> states = Json.load(new File(HistoryTest.class.getResource("recent-history.json").getFile()), HistoryState.JSON_CREATOR);
|
||||
assertEquals(8, states.size());
|
||||
|
||||
HistoryState state = states.get(0);
|
||||
|
@ -27,7 +27,7 @@ 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.ParseException;
|
||||
import org.solovyev.android.calculator.CalculatorTestUtils;
|
||||
import org.solovyev.android.calculator.Locator;
|
||||
import org.solovyev.common.Converter;
|
||||
@ -42,7 +42,6 @@ import au.com.bytecode.opencsv.CSVReader;
|
||||
import jscl.JsclMathEngine;
|
||||
import jscl.MathEngine;
|
||||
import jscl.math.Expression;
|
||||
import jscl.text.ParseException;
|
||||
import jscl.util.ExpressionGeneratorWithInput;
|
||||
|
||||
/**
|
||||
@ -58,7 +57,7 @@ public class NumeralBaseTest extends AbstractCalculatorTest {
|
||||
Locator.getInstance().getEngine().getMathEngine().setPrecision(3);
|
||||
}
|
||||
|
||||
public static void testExpression(@Nonnull String[] line, @Nonnull Converter<String, String> converter) throws ParseException, CalculatorEvalException, CalculatorParseException {
|
||||
public static void testExpression(@Nonnull String[] line, @Nonnull Converter<String, String> converter) throws jscl.text.ParseException, CalculatorEvalException, ParseException {
|
||||
final String dec = line[0].toUpperCase();
|
||||
final String hex = "0x:" + line[1].toUpperCase();
|
||||
final String bin = "0b:" + line[2].toUpperCase();
|
||||
|
@ -26,7 +26,7 @@ import org.junit.Assert;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.solovyev.android.calculator.AbstractCalculatorTest;
|
||||
import org.solovyev.android.calculator.CalculatorParseException;
|
||||
import org.solovyev.android.calculator.ParseException;
|
||||
import org.solovyev.android.calculator.CalculatorTestUtils;
|
||||
import org.solovyev.android.calculator.Locator;
|
||||
import org.solovyev.android.calculator.PreparedExpression;
|
||||
@ -49,7 +49,7 @@ public class ToJsclTextProcessorTest extends AbstractCalculatorTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSpecialCases() throws CalculatorParseException {
|
||||
public void testSpecialCases() throws ParseException {
|
||||
final TextProcessor<PreparedExpression, String> preprocessor = ToJsclTextProcessor.getInstance();
|
||||
Assert.assertEquals("3^E10", preprocessor.process("3^E10").toString());
|
||||
}
|
||||
@ -108,30 +108,30 @@ public class ToJsclTextProcessorTest extends AbstractCalculatorTest {
|
||||
try {
|
||||
preprocessor.process("ln()");
|
||||
Assert.fail();
|
||||
} catch (CalculatorParseException e) {
|
||||
} catch (ParseException e) {
|
||||
}
|
||||
try {
|
||||
preprocessor.process("ln()ln()");
|
||||
Assert.fail();
|
||||
} catch (CalculatorParseException e) {
|
||||
} catch (ParseException e) {
|
||||
}
|
||||
|
||||
try {
|
||||
preprocessor.process("eln()eln()ln()ln()ln()e");
|
||||
Assert.fail();
|
||||
} catch (CalculatorParseException e) {
|
||||
} catch (ParseException e) {
|
||||
}
|
||||
|
||||
try {
|
||||
preprocessor.process("ln(ln(ln(ln(ln(ln(ln(ln(ln(ln(ln(ln(ln(ln(ln()))))))))))))))");
|
||||
Assert.fail();
|
||||
} catch (CalculatorParseException e) {
|
||||
} catch (ParseException e) {
|
||||
}
|
||||
|
||||
try {
|
||||
preprocessor.process("cos(cos(cos(cos(acos(acos(acos(acos(acos(acos(acos(acos(cos(cos(cos(cos(cosh(acos(cos(cos(cos(cos(cos(acos(acos(acos(acos(acos(acos(acos(acos(cos(cos(cos(cos(cosh(acos(cos())))))))))))))))))))))))))))))))))))))");
|
||||
Assert.fail();
|
||||
} catch (CalculatorParseException e) {
|
||||
} catch (ParseException e) {
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user