This commit is contained in:
Sergey Solovyev 2011-09-19 12:53:23 +04:00
parent 490b6f5c75
commit 60251243f0
7 changed files with 20 additions and 29 deletions

View File

@ -7,18 +7,9 @@ package org.solovyev.android.calculator;
import android.content.Context;
import android.content.res.ColorStateList;
import android.text.Html;
import android.util.AttributeSet;
import android.widget.EditText;
import android.widget.TextView;
import org.solovyev.common.definitions.Pair;
import org.solovyev.common.exceptions.SersoException;
import org.solovyev.common.utils.CollectionsUtils;
import org.solovyev.util.math.MathEntityType;
import java.util.ArrayList;
import java.util.List;
import java.util.Stack;
/**
* User: serso

View File

@ -10,7 +10,6 @@ import bsh.Interpreter;
import org.jetbrains.annotations.NotNull;
import org.solovyev.common.exceptions.SersoException;
import org.solovyev.common.utils.MathUtils;
import org.solovyev.common.utils.StringUtils;
import org.solovyev.util.math.Complex;
/**
@ -42,7 +41,7 @@ public class CalculatorModel {
String result = String.valueOf(evaluationObject).trim();
try {
result = round(result);
result = String.valueOf(round(result));
} catch (NumberFormatException e) {
if (result.contains("sqrt(-1)")) {
try {
@ -82,8 +81,8 @@ public class CalculatorModel {
int multiplyIndex = s.indexOf("*");
if (multiplyIndex >= 0) {
complex.setImag(round(s.substring(plusIndex >= 0 ? plusIndex+1 : 0, multiplyIndex)));
result += complex.getImag();
complex.setImaginary(round(s.substring(plusIndex >= 0 ? plusIndex + 1 : 0, multiplyIndex)));
result += complex.getImaginary();
}
@ -92,10 +91,9 @@ public class CalculatorModel {
return result;
}
private String round(@NotNull String result) {
private Double round(@NotNull String result) {
final Double dResult = Double.valueOf(result);
result = String.valueOf(MathUtils.round(dResult, NUMBER_OF_FRACTION_DIGITS));
return result;
return MathUtils.round(dResult, NUMBER_OF_FRACTION_DIGITS);
}
public static class ParseException extends SersoException {

View File

@ -19,6 +19,7 @@ import android.widget.Toast;
import bsh.EvalError;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.solovyev.android.calculator.math.MathEntityType;
import org.solovyev.android.view.CursorControl;
import org.solovyev.android.view.HistoryControl;
import org.solovyev.common.utils.MutableObject;
@ -26,7 +27,6 @@ import org.solovyev.common.utils.StringUtils;
import org.solovyev.common.utils.history.HistoryAction;
import org.solovyev.common.utils.history.HistoryHelper;
import org.solovyev.common.utils.history.SimpleHistoryHelper;
import org.solovyev.util.math.MathEntityType;
/**
* User: serso

View File

@ -7,11 +7,10 @@ package org.solovyev.android.calculator;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.solovyev.android.calculator.math.Functions;
import org.solovyev.android.calculator.math.MathEntityType;
import org.solovyev.common.utils.CollectionsUtils;
import org.solovyev.common.utils.EqualsFinder;
import org.solovyev.common.utils.Finder;
import org.solovyev.util.math.Functions;
import org.solovyev.util.math.MathEntityType;
public class Preprocessor {

View File

@ -3,7 +3,7 @@
* For more information, please, contact se.solovyev@gmail.com
*/
package org.solovyev.util.math;
package org.solovyev.android.calculator.math;
import org.jetbrains.annotations.NonNls;

View File

@ -3,7 +3,7 @@
* For more information, please, contact se.solovyev@gmail.com
*/
package org.solovyev.util.math;
package org.solovyev.android.calculator.math;
import java.util.ArrayList;
import java.util.Arrays;

View File

@ -15,23 +15,26 @@ import org.jetbrains.annotations.Nullable;
public class Complex {
@Nullable
private String real, imag;
private Double real;
@Nullable
public String getReal() {
private Double imaginary;
@Nullable
public Double getReal() {
return real;
}
public void setReal(@Nullable String real) {
public void setReal(@Nullable Double real) {
this.real = real;
}
@Nullable
public String getImag() {
return imag;
public Double getImaginary() {
return imaginary;
}
public void setImag(@Nullable String imag) {
this.imag = imag;
public void setImaginary(@Nullable Double imaginary) {
this.imaginary = imaginary;
}
}