refactor
This commit is contained in:
parent
fe2436161e
commit
0a22093246
@ -7,18 +7,9 @@ package org.solovyev.android.calculator;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.res.ColorStateList;
|
import android.content.res.ColorStateList;
|
||||||
import android.text.Html;
|
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
import android.widget.TextView;
|
|
||||||
import org.solovyev.common.definitions.Pair;
|
|
||||||
import org.solovyev.common.exceptions.SersoException;
|
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
|
* User: serso
|
||||||
|
@ -10,7 +10,6 @@ import bsh.Interpreter;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.solovyev.common.exceptions.SersoException;
|
import org.solovyev.common.exceptions.SersoException;
|
||||||
import org.solovyev.common.utils.MathUtils;
|
import org.solovyev.common.utils.MathUtils;
|
||||||
import org.solovyev.common.utils.StringUtils;
|
|
||||||
import org.solovyev.util.math.Complex;
|
import org.solovyev.util.math.Complex;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -42,7 +41,7 @@ public class CalculatorModel {
|
|||||||
String result = String.valueOf(evaluationObject).trim();
|
String result = String.valueOf(evaluationObject).trim();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
result = round(result);
|
result = String.valueOf(round(result));
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
if (result.contains("sqrt(-1)")) {
|
if (result.contains("sqrt(-1)")) {
|
||||||
try {
|
try {
|
||||||
@ -82,8 +81,8 @@ public class CalculatorModel {
|
|||||||
|
|
||||||
int multiplyIndex = s.indexOf("*");
|
int multiplyIndex = s.indexOf("*");
|
||||||
if (multiplyIndex >= 0) {
|
if (multiplyIndex >= 0) {
|
||||||
complex.setImag(round(s.substring(plusIndex >= 0 ? plusIndex+1 : 0, multiplyIndex)));
|
complex.setImaginary(round(s.substring(plusIndex >= 0 ? plusIndex + 1 : 0, multiplyIndex)));
|
||||||
result += complex.getImag();
|
result += complex.getImaginary();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -92,10 +91,9 @@ public class CalculatorModel {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String round(@NotNull String result) {
|
private Double round(@NotNull String result) {
|
||||||
final Double dResult = Double.valueOf(result);
|
final Double dResult = Double.valueOf(result);
|
||||||
result = String.valueOf(MathUtils.round(dResult, NUMBER_OF_FRACTION_DIGITS));
|
return MathUtils.round(dResult, NUMBER_OF_FRACTION_DIGITS);
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class ParseException extends SersoException {
|
public static class ParseException extends SersoException {
|
||||||
|
@ -19,6 +19,7 @@ import android.widget.Toast;
|
|||||||
import bsh.EvalError;
|
import bsh.EvalError;
|
||||||
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.math.MathEntityType;
|
||||||
import org.solovyev.android.view.CursorControl;
|
import org.solovyev.android.view.CursorControl;
|
||||||
import org.solovyev.android.view.HistoryControl;
|
import org.solovyev.android.view.HistoryControl;
|
||||||
import org.solovyev.common.utils.MutableObject;
|
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.HistoryAction;
|
||||||
import org.solovyev.common.utils.history.HistoryHelper;
|
import org.solovyev.common.utils.history.HistoryHelper;
|
||||||
import org.solovyev.common.utils.history.SimpleHistoryHelper;
|
import org.solovyev.common.utils.history.SimpleHistoryHelper;
|
||||||
import org.solovyev.util.math.MathEntityType;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* User: serso
|
* User: serso
|
||||||
|
@ -7,11 +7,10 @@ package org.solovyev.android.calculator;
|
|||||||
|
|
||||||
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.math.Functions;
|
||||||
|
import org.solovyev.android.calculator.math.MathEntityType;
|
||||||
import org.solovyev.common.utils.CollectionsUtils;
|
import org.solovyev.common.utils.CollectionsUtils;
|
||||||
import org.solovyev.common.utils.EqualsFinder;
|
|
||||||
import org.solovyev.common.utils.Finder;
|
import org.solovyev.common.utils.Finder;
|
||||||
import org.solovyev.util.math.Functions;
|
|
||||||
import org.solovyev.util.math.MathEntityType;
|
|
||||||
|
|
||||||
public class Preprocessor {
|
public class Preprocessor {
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
* For more information, please, contact se.solovyev@gmail.com
|
* 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;
|
import org.jetbrains.annotations.NonNls;
|
||||||
|
|
@ -3,7 +3,7 @@
|
|||||||
* For more information, please, contact se.solovyev@gmail.com
|
* 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.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
@ -15,23 +15,26 @@ import org.jetbrains.annotations.Nullable;
|
|||||||
public class Complex {
|
public class Complex {
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private String real, imag;
|
private Double real;
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public String getReal() {
|
private Double imaginary;
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public Double getReal() {
|
||||||
return real;
|
return real;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setReal(@Nullable String real) {
|
public void setReal(@Nullable Double real) {
|
||||||
this.real = real;
|
this.real = real;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public String getImag() {
|
public Double getImaginary() {
|
||||||
return imag;
|
return imaginary;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setImag(@Nullable String imag) {
|
public void setImaginary(@Nullable Double imaginary) {
|
||||||
this.imag = imag;
|
this.imaginary = imaginary;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user