Reformat code and remove unused code
This commit is contained in:
@@ -77,7 +77,7 @@ public abstract class BaseNumberBuilder {
|
||||
if ("−".equals(match) || "-".equals(match) || "+".equals(match)) {
|
||||
final StringBuilder localNb = numberBuilder;
|
||||
if (localNb != null && localNb.length() > 0) {
|
||||
if (localNb.charAt(localNb.length() - 1) == MathType.POWER_10) {
|
||||
if (localNb.charAt(localNb.length() - 1) == MathType.EXPONENT) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@@ -26,7 +26,6 @@ import android.text.SpannableStringBuilder;
|
||||
import jscl.MathContext;
|
||||
import jscl.MathEngine;
|
||||
import jscl.NumeralBase;
|
||||
import jscl.math.numeric.Real;
|
||||
import jscl.text.DoubleParser;
|
||||
import jscl.text.JsclIntegerParser;
|
||||
import jscl.text.ParseException;
|
||||
@@ -45,60 +44,23 @@ public class NumberBuilder extends BaseNumberBuilder {
|
||||
}
|
||||
|
||||
private static int replaceNumberInText(@Nonnull SpannableStringBuilder sb,
|
||||
@Nullable String number,
|
||||
@Nullable String oldNumber,
|
||||
int trimmedChars,
|
||||
@Nonnull NumeralBase nb,
|
||||
@Nonnull final MathEngine engine) {
|
||||
if (number == null) {
|
||||
if (oldNumber == null) {
|
||||
return 0;
|
||||
}
|
||||
// in any case remove old number from text
|
||||
final int oldNumberLength = number.length() + trimmedChars;
|
||||
final int oldNumberLength = oldNumber.length() + trimmedChars;
|
||||
sb.delete(sb.length() - oldNumberLength, sb.length());
|
||||
|
||||
final String newNumber = formatNumber(number, nb, engine);
|
||||
final String newNumber = engine.format(oldNumber, nb);
|
||||
sb.append(newNumber);
|
||||
// offset between old number and new number
|
||||
return newNumber.length() - oldNumberLength;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
private static String formatNumber(@Nonnull String number, @Nonnull NumeralBase nb, @Nonnull MathEngine engine) {
|
||||
String result;
|
||||
|
||||
int indexOfDot = number.indexOf('.');
|
||||
|
||||
if (indexOfDot < 0) {
|
||||
int indexOfE;
|
||||
if (nb == NumeralBase.hex) {
|
||||
indexOfE = -1;
|
||||
} else {
|
||||
indexOfE = number.indexOf(MathType.POWER_10);
|
||||
}
|
||||
if (indexOfE < 0) {
|
||||
result = engine.addGroupingSeparators(nb, number);
|
||||
} else {
|
||||
final String partBeforeE;
|
||||
if (indexOfE != 0) {
|
||||
partBeforeE = engine.addGroupingSeparators(nb, number.substring(0, indexOfE));
|
||||
} else {
|
||||
partBeforeE = "";
|
||||
}
|
||||
result = partBeforeE + number.substring(indexOfE);
|
||||
}
|
||||
} else {
|
||||
final String integerPart;
|
||||
if (indexOfDot != 0) {
|
||||
integerPart = engine.addGroupingSeparators(nb, number.substring(0, indexOfDot));
|
||||
} else {
|
||||
integerPart = "";
|
||||
}
|
||||
result = integerPart + number.substring(indexOfDot);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
private static Double toDouble(@Nonnull String s, @Nonnull NumeralBase nb, @Nonnull final MathContext mc) throws NumberFormatException {
|
||||
final NumeralBase defaultNb = mc.getNumeralBase();
|
||||
@@ -112,7 +74,7 @@ public class NumberBuilder extends BaseNumberBuilder {
|
||||
p.exceptionsPool.release(e);
|
||||
try {
|
||||
p.reset();
|
||||
return ((Real) DoubleParser.parser.parse(p, null).content()).doubleValue();
|
||||
return DoubleParser.parser.parse(p, null).content().doubleValue();
|
||||
} catch (ParseException e1) {
|
||||
p.exceptionsPool.release(e1);
|
||||
throw new NumberFormatException();
|
||||
|
@@ -23,24 +23,21 @@
|
||||
package org.solovyev.android.calculator.math;
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import jscl.JsclMathEngine;
|
||||
import jscl.NumeralBase;
|
||||
import jscl.math.function.Constants;
|
||||
import org.solovyev.android.Check;
|
||||
import org.solovyev.android.calculator.App;
|
||||
import org.solovyev.android.calculator.Engine;
|
||||
import org.solovyev.android.calculator.ParseException;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import jscl.JsclMathEngine;
|
||||
import jscl.NumeralBase;
|
||||
import jscl.math.function.Constants;
|
||||
|
||||
|
||||
public enum MathType {
|
||||
|
||||
@@ -224,7 +221,7 @@ public enum MathType {
|
||||
};
|
||||
|
||||
public static final List<String> groupSymbols = Arrays.asList("()", "[]", "{}");
|
||||
public final static Character POWER_10 = 'E';
|
||||
public final static Character EXPONENT = 'E';
|
||||
public static final String E = "e";
|
||||
public static final String C = "c";
|
||||
public final static String NAN = "NaN";
|
||||
|
Reference in New Issue
Block a user