substituting of constants in editor removed

This commit is contained in:
Sergey Solovyev 2011-12-16 18:54:50 +04:00
parent 14bd14c49a
commit 5ff4b4559c
3 changed files with 11 additions and 26 deletions

View File

@ -11,6 +11,7 @@ import jscl.NumeralBase;
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.MathType; import org.solovyev.android.calculator.math.MathType;
import org.solovyev.common.utils.StringUtils;
/** /**
* User: serso * User: serso
@ -44,7 +45,7 @@ public abstract class AbstractNumberBuilder {
} }
private boolean spaceBefore(@NotNull MathType.Result mathTypeResult) { private boolean spaceBefore(@NotNull MathType.Result mathTypeResult) {
return numberBuilder == null && mathTypeResult.getMatch().trim().isEmpty(); return numberBuilder == null && StringUtils.isEmpty(mathTypeResult.getMatch().trim());
} }
private boolean numeralBaseInTheStart(@NotNull MathType mathType) { private boolean numeralBaseInTheStart(@NotNull MathType mathType) {

View File

@ -130,32 +130,16 @@ public class NumberBuilder extends AbstractNumberBuilder {
MathType.Result result = null; MathType.Result result = null;
if (number != null) { if (number != null) {
final String finalNumber = number;
// detect if current number is precisely equals to constant in constants' registry (NOTE: ONLY FOR SYSTEM CONSTANTS)
final IConstant constant = CollectionsUtils.find(engine.getConstantsRegistry().getSystemEntities(), new Finder<IConstant>() {
@Override
public boolean isFound(@Nullable IConstant constant) {
return constant != null && finalNumber.equals(constant.getValue());
}
});
// in any case remove old number from text // in any case remove old number from text
final int oldNumberLength = number.length() + trimmedChars; final int oldNumberLength = number.length() + trimmedChars;
text.delete(text.length() - oldNumberLength, text.length()); text.delete(text.length() - oldNumberLength, text.length());
if (constant != null) { final String newNumber = formatNumber(number, nb, engine);
// let's change number with constant from registry if (offset != null) {
text.append(constant.getName()); // register offset between old number and new number
result = new MathType.Result(MathType.constant, constant.getName()); offset.setObject(newNumber.length() - oldNumberLength);
} else {
final String newNumber = formatNumber(number, nb, engine);
if (offset != null) {
// register offset between old number and new number
offset.setObject(newNumber.length() - oldNumberLength);
}
text.append(newNumber);
} }
text.append(newNumber);
} }
return result; return result;

View File

@ -380,7 +380,7 @@ public class CalculatorEngineTest {
} }
} }
@Test /* @Test
public void testDegrees() throws Exception { public void testDegrees() throws Exception {
final CalculatorEngine cm = CalculatorEngine.instance; final CalculatorEngine cm = CalculatorEngine.instance;
@ -391,8 +391,8 @@ public class CalculatorEngineTest {
try { try {
Assert.assertEquals("0.017", cm.evaluate(JsclOperation.numeric, "°")); Assert.assertEquals("0.017", cm.evaluate(JsclOperation.numeric, "°"));
fail(); fail();
} catch (CalculatorParseException e) { } catch (CalculatorParseException e) {
// ok
} }
Assert.assertEquals("0.017", cm.evaluate(JsclOperation.numeric, "").getResult()); Assert.assertEquals("0.017", cm.evaluate(JsclOperation.numeric, "").getResult());
@ -405,6 +405,6 @@ public class CalculatorEngineTest {
} finally { } finally {
cm.getEngine().setAngleUnits(defaultAngleUnit); cm.getEngine().setAngleUnits(defaultAngleUnit);
} }
} }*/
} }