registries

This commit is contained in:
Sergey Solovyev 2012-10-07 19:29:37 +04:00
parent d4cff84040
commit 78a1cc4942
32 changed files with 1441 additions and 1290 deletions

View File

@ -1,46 +1,58 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.solovyev.android</groupId>
<artifactId>calculatorpp-parent</artifactId>
<version>1.3.2</version>
</parent>
<groupId>org.solovyev.android</groupId>
<artifactId>calculatorpp-core</artifactId>
<version>1.3.2</version>
<name>Calculator++ Application Core</name>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.intellij</groupId>
<artifactId>annotations</artifactId>
</dependency>
<dependency>
<groupId>org.solovyev</groupId>
<artifactId>jscl</artifactId>
</dependency>
<dependency>
<groupId>org.simpleframework</groupId>
<artifactId>simple-xml</artifactId>
</dependency>
</dependencies>
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.solovyev.android</groupId>
<artifactId>calculatorpp-parent</artifactId>
<version>1.3.2</version>
</parent>
<groupId>org.solovyev.android</groupId>
<artifactId>calculatorpp-core</artifactId>
<version>1.3.2</version>
<name>Calculator++ Application Core</name>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>org.solovyev</groupId>
<artifactId>common-text</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>1.9.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.intellij</groupId>
<artifactId>annotations</artifactId>
</dependency>
<dependency>
<groupId>org.solovyev</groupId>
<artifactId>jscl</artifactId>
</dependency>
<dependency>
<groupId>org.simpleframework</groupId>
<artifactId>simple-xml</artifactId>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,148 @@
/*
* Copyright (c) 2009-2011. Created by serso aka se.solovyev.
* For more information, please, contact se.solovyev@gmail.com
* or visit http://se.solovyev.org
*/
package org.solovyev.android.calculator;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.solovyev.common.JBuilder;
import org.solovyev.common.math.MathEntity;
import org.solovyev.common.math.MathRegistry;
import java.util.List;
import java.util.Map;
/**
* User: serso
* Date: 10/30/11
* Time: 1:03 AM
*/
public abstract class AbstractCalculatorMathRegistry<T extends MathEntity, P extends MathPersistenceEntity> implements CalculatorMathRegistry<T> {
@NotNull
private final MathRegistry<T> mathRegistry;
@NotNull
private final String prefix;
@NotNull
private final MathEntityDao<P> mathEntityDao;
protected AbstractCalculatorMathRegistry(@NotNull MathRegistry<T> mathRegistry,
@NotNull String prefix,
@NotNull MathEntityDao<P> mathEntityDao) {
this.mathRegistry = mathRegistry;
this.prefix = prefix;
this.mathEntityDao = mathEntityDao;
}
@NotNull
protected abstract Map<String, String> getSubstitutes();
@Nullable
@Override
public String getDescription(@NotNull String mathEntityName) {
final String stringName;
final Map<String, String> substitutes = getSubstitutes();
final String substitute = substitutes.get(mathEntityName);
if (substitute == null) {
stringName = prefix + mathEntityName;
} else {
stringName = prefix + substitute;
}
return mathEntityDao.getDescription(stringName);
}
public synchronized void load() {
final MathEntityPersistenceContainer<P> persistenceContainer = mathEntityDao.load();
if (persistenceContainer != null) {
for (P entity : persistenceContainer.getEntities()) {
if (!contains(entity.getName())) {
add(createBuilder(entity));
}
}
}
/*Log.d(AndroidVarsRegistry.class.getName(), vars.size() + " variables registered!");
for (Var var : vars) {
Log.d(AndroidVarsRegistry.class.getName(), var.toString());
}*/
}
@NotNull
protected abstract JBuilder<? extends T> createBuilder(@NotNull P entity);
@Override
public synchronized void save() {
final MathEntityPersistenceContainer<P> container = createPersistenceContainer();
for (T entity : this.getEntities()) {
if (!entity.isSystem()) {
final P persistenceEntity = transform(entity);
if (persistenceEntity != null) {
container.getEntities().add(persistenceEntity);
}
}
}
this.mathEntityDao.save(container);
}
@Nullable
protected abstract P transform(@NotNull T entity);
@NotNull
protected abstract MathEntityPersistenceContainer<P> createPersistenceContainer();
@NotNull
@Override
public List<T> getEntities() {
return mathRegistry.getEntities();
}
@NotNull
@Override
public List<T> getSystemEntities() {
return mathRegistry.getSystemEntities();
}
@Override
public T add(@NotNull JBuilder<? extends T> JBuilder) {
return mathRegistry.add(JBuilder);
}
@Override
public void remove(@NotNull T var) {
mathRegistry.remove(var);
}
@NotNull
@Override
public List<String> getNames() {
return mathRegistry.getNames();
}
@Override
public boolean contains(@NotNull String name) {
return mathRegistry.contains(name);
}
@Override
public T get(@NotNull String name) {
return mathRegistry.get(name);
}
@Override
public T getById(@NotNull Integer id) {
return mathRegistry.getById(id);
}
}

View File

@ -0,0 +1,20 @@
package org.solovyev.android.calculator;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* User: serso
* Date: 10/7/12
* Time: 6:43 PM
*/
public interface MathEntityDao<T extends MathPersistenceEntity> {
void save(@NotNull MathEntityPersistenceContainer<T> container);
@Nullable
MathEntityPersistenceContainer<T> load();
@Nullable
String getDescription(@NotNull String descriptionId);
}

View File

@ -1,4 +1,4 @@
package org.solovyev.android.calculator.model;
package org.solovyev.android.calculator;
import java.util.List;
@ -8,5 +8,7 @@ import java.util.List;
* Time: 5:03 PM
*/
public interface MathEntityPersistenceContainer<T extends MathPersistenceEntity> {
public List<T> getEntities();
public List<T> getEntities();
}

View File

@ -4,7 +4,7 @@
* or visit http://se.solovyev.org
*/
package org.solovyev.android.calculator.model;
package org.solovyev.android.calculator;
import org.jetbrains.annotations.NotNull;

View File

@ -354,7 +354,7 @@ public enum MathType {
final String s = CollectionsUtils.find(mathType.getTokens(), startsWithFinder);
if (s != null) {
if ( s.length() == 1 ) {
if (hexMode || JsclMathEngine.instance.getNumeralBase() == NumeralBase.hex) {
if (hexMode || JsclMathEngine.getInstance().getNumeralBase() == NumeralBase.hex) {
final Character ch = s.charAt(0);
if ( NumeralBase.hex.getAcceptableCharacters().contains(ch) ) {
return new Result(MathType.digit, s);

View File

@ -10,6 +10,7 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.simpleframework.xml.Element;
import org.simpleframework.xml.Root;
import org.solovyev.android.calculator.MathPersistenceEntity;
import org.solovyev.common.collections.CollectionsUtils;
import org.solovyev.common.text.CollectionTransformations;
import org.solovyev.common.text.StringMapper;

View File

@ -1,10 +1,9 @@
package org.solovyev.android.calculator.model;
import jscl.math.function.CustomFunction;
import jscl.math.function.Function;
import jscl.math.function.IConstant;
import org.simpleframework.xml.ElementList;
import org.simpleframework.xml.Root;
import org.solovyev.android.calculator.MathEntityPersistenceContainer;
import java.util.ArrayList;
import java.util.List;

View File

@ -0,0 +1,32 @@
package org.solovyev.android.calculator;
import jscl.JsclMathEngine;
import org.jetbrains.annotations.NotNull;
import org.mockito.Mockito;
import org.solovyev.android.calculator.history.CalculatorHistory;
/**
* User: serso
* Date: 10/7/12
* Time: 6:30 PM
*/
public class AbstractCalculatorTest {
protected static void staticSetUp() throws Exception {
CalculatorLocatorImpl.getInstance().init(new CalculatorImpl(), newCalculatorEngine(), Mockito.mock(CalculatorClipboard.class), Mockito.mock(CalculatorNotifier.class), Mockito.mock(CalculatorHistory.class));
}
protected void setUp() throws Exception {
CalculatorLocatorImpl.getInstance().init(new CalculatorImpl(), newCalculatorEngine(), Mockito.mock(CalculatorClipboard.class), Mockito.mock(CalculatorNotifier.class), Mockito.mock(CalculatorHistory.class));
}
@NotNull
private static CalculatorEngineImpl newCalculatorEngine() {
final CalculatorMathRegistry varsRegistry = Mockito.mock(CalculatorMathRegistry.class);
//Mockito.when(varsRegistry.get())
final CalculatorEngineImpl result = new CalculatorEngineImpl(JsclMathEngine.getInstance(), varsRegistry, Mockito.mock(CalculatorMathRegistry.class), Mockito.mock(CalculatorMathRegistry.class), Mockito.mock(CalculatorMathRegistry.class), null);
result.init();
return result;
}
}

View File

@ -1,200 +1,201 @@
package org.solovyev.android.calculator;
import junit.framework.Assert;
import org.jetbrains.annotations.NotNull;
import org.junit.Before;
import org.junit.Test;
/**
* User: Solovyev_S
* Date: 21.09.12
* Time: 12:44
*/
public class CalculatorEditorImplTest {
@NotNull
private CalculatorEditor calculatorEditor;
@Before
public void setUp() throws Exception {
this.calculatorEditor = new CalculatorEditorImpl(new CalculatorImpl());
}
@Test
public void testInsert() throws Exception {
CalculatorEditorViewState viewState = this.calculatorEditor.getViewState();
Assert.assertEquals("", viewState.getText());
Assert.assertEquals(0, viewState.getSelection());
viewState = this.calculatorEditor.insert("");
Assert.assertEquals("", viewState.getText());
Assert.assertEquals(0, viewState.getSelection());
viewState = this.calculatorEditor.insert("test");
Assert.assertEquals("test", viewState.getText());
Assert.assertEquals(4, viewState.getSelection());
viewState = this.calculatorEditor.insert("test");
Assert.assertEquals("testtest", viewState.getText());
Assert.assertEquals(8, viewState.getSelection());
viewState = this.calculatorEditor.insert("");
Assert.assertEquals("testtest", viewState.getText());
Assert.assertEquals(8, viewState.getSelection());
viewState = this.calculatorEditor.insert("1234567890");
Assert.assertEquals("testtest1234567890", viewState.getText());
Assert.assertEquals(18, viewState.getSelection());
viewState = this.calculatorEditor.moveCursorLeft();
viewState = this.calculatorEditor.insert("9");
Assert.assertEquals("testtest12345678990", viewState.getText());
Assert.assertEquals(18, viewState.getSelection());
viewState = this.calculatorEditor.setCursorOnStart();
viewState = this.calculatorEditor.insert("9");
Assert.assertEquals("9testtest12345678990", viewState.getText());
Assert.assertEquals(1, viewState.getSelection());
viewState = this.calculatorEditor.erase();
viewState = this.calculatorEditor.insert("9");
Assert.assertEquals("9testtest12345678990", viewState.getText());
Assert.assertEquals(1, viewState.getSelection());
}
@Test
public void testErase() throws Exception {
this.calculatorEditor.setText("");
this.calculatorEditor.erase();
Assert.assertEquals("", this.calculatorEditor.getViewState().getText());
this.calculatorEditor.setText("test");
this.calculatorEditor.erase();
Assert.assertEquals("tes", this.calculatorEditor.getViewState().getText());
this.calculatorEditor.erase();
Assert.assertEquals("te", this.calculatorEditor.getViewState().getText());
this.calculatorEditor.erase();
Assert.assertEquals("t", this.calculatorEditor.getViewState().getText());
this.calculatorEditor.erase();
Assert.assertEquals("", this.calculatorEditor.getViewState().getText());
this.calculatorEditor.erase();
Assert.assertEquals("", this.calculatorEditor.getViewState().getText());
this.calculatorEditor.setText("1234");
this.calculatorEditor.moveCursorLeft();
this.calculatorEditor.erase();
Assert.assertEquals("124", this.calculatorEditor.getViewState().getText());
this.calculatorEditor.erase();
Assert.assertEquals("14", this.calculatorEditor.getViewState().getText());
this.calculatorEditor.erase();
Assert.assertEquals("4", this.calculatorEditor.getViewState().getText());
this.calculatorEditor.setText("1");
this.calculatorEditor.moveCursorLeft();
this.calculatorEditor.erase();
Assert.assertEquals("1", this.calculatorEditor.getViewState().getText());
}
@Test
public void testMoveSelection() throws Exception {
this.calculatorEditor.setText("");
CalculatorEditorViewState viewState = this.calculatorEditor.moveSelection(0);
Assert.assertEquals(0, viewState.getSelection());
viewState = this.calculatorEditor.moveSelection(2);
Assert.assertEquals(0, viewState.getSelection());
viewState = this.calculatorEditor.moveSelection(100);
Assert.assertEquals(0, viewState.getSelection());
viewState = this.calculatorEditor.moveSelection(-3);
Assert.assertEquals(0, viewState.getSelection());
viewState = this.calculatorEditor.moveSelection(-100);
Assert.assertEquals(0, viewState.getSelection());
viewState = this.calculatorEditor.setText("0123456789");
viewState = this.calculatorEditor.moveSelection(0);
Assert.assertEquals(10, viewState.getSelection());
viewState = this.calculatorEditor.moveSelection(1);
Assert.assertEquals(10, viewState.getSelection());
viewState = this.calculatorEditor.moveSelection(-2);
Assert.assertEquals(8, viewState.getSelection());
viewState = this.calculatorEditor.moveSelection(1);
Assert.assertEquals(9, viewState.getSelection());
viewState = this.calculatorEditor.moveSelection(-9);
Assert.assertEquals(0, viewState.getSelection());
viewState = this.calculatorEditor.moveSelection(-10);
Assert.assertEquals(0, viewState.getSelection());
viewState = this.calculatorEditor.moveSelection(2);
Assert.assertEquals(2, viewState.getSelection());
viewState = this.calculatorEditor.moveSelection(2);
Assert.assertEquals(4, viewState.getSelection());
viewState = this.calculatorEditor.moveSelection(-6);
Assert.assertEquals(0, viewState.getSelection());
}
@Test
public void testSetText() throws Exception {
CalculatorEditorViewState viewState = this.calculatorEditor.setText("test");
Assert.assertEquals("test", viewState.getText());
Assert.assertEquals(4, viewState.getSelection());
viewState = this.calculatorEditor.setText("testtest");
Assert.assertEquals("testtest", viewState.getText());
Assert.assertEquals(8, viewState.getSelection());
viewState = this.calculatorEditor.setText("");
Assert.assertEquals("", viewState.getText());
Assert.assertEquals(0, viewState.getSelection());
viewState = this.calculatorEditor.setText("testtest", 0);
Assert.assertEquals("testtest", viewState.getText());
Assert.assertEquals(0, viewState.getSelection());
viewState = this.calculatorEditor.setText("testtest", 2);
Assert.assertEquals("testtest", viewState.getText());
Assert.assertEquals(2, viewState.getSelection());
viewState = this.calculatorEditor.setText("", 0);
Assert.assertEquals("", viewState.getText());
Assert.assertEquals(0, viewState.getSelection());
viewState = this.calculatorEditor.setText("", 3);
Assert.assertEquals("", viewState.getText());
Assert.assertEquals(0, viewState.getSelection());
viewState = this.calculatorEditor.setText("", -3);
Assert.assertEquals("", viewState.getText());
Assert.assertEquals(0, viewState.getSelection());
viewState = this.calculatorEditor.setText("test");
Assert.assertEquals("test", viewState.getText());
Assert.assertEquals(4, viewState.getSelection());
viewState = this.calculatorEditor.setText("", 2);
Assert.assertEquals("", viewState.getText());
Assert.assertEquals(0, viewState.getSelection());
}
}
package org.solovyev.android.calculator;
import junit.framework.Assert;
import org.jetbrains.annotations.NotNull;
import org.junit.Before;
import org.junit.Test;
/**
* User: Solovyev_S
* Date: 21.09.12
* Time: 12:44
*/
public class CalculatorEditorImplTest extends AbstractCalculatorTest {
@NotNull
private CalculatorEditor calculatorEditor;
@Before
public void setUp() throws Exception {
super.setUp();
this.calculatorEditor = new CalculatorEditorImpl(CalculatorLocatorImpl.getInstance().getCalculator());
}
@Test
public void testInsert() throws Exception {
CalculatorEditorViewState viewState = this.calculatorEditor.getViewState();
Assert.assertEquals("", viewState.getText());
Assert.assertEquals(0, viewState.getSelection());
viewState = this.calculatorEditor.insert("");
Assert.assertEquals("", viewState.getText());
Assert.assertEquals(0, viewState.getSelection());
viewState = this.calculatorEditor.insert("test");
Assert.assertEquals("test", viewState.getText());
Assert.assertEquals(4, viewState.getSelection());
viewState = this.calculatorEditor.insert("test");
Assert.assertEquals("testtest", viewState.getText());
Assert.assertEquals(8, viewState.getSelection());
viewState = this.calculatorEditor.insert("");
Assert.assertEquals("testtest", viewState.getText());
Assert.assertEquals(8, viewState.getSelection());
viewState = this.calculatorEditor.insert("1234567890");
Assert.assertEquals("testtest1234567890", viewState.getText());
Assert.assertEquals(18, viewState.getSelection());
viewState = this.calculatorEditor.moveCursorLeft();
viewState = this.calculatorEditor.insert("9");
Assert.assertEquals("testtest12345678990", viewState.getText());
Assert.assertEquals(18, viewState.getSelection());
viewState = this.calculatorEditor.setCursorOnStart();
viewState = this.calculatorEditor.insert("9");
Assert.assertEquals("9testtest12345678990", viewState.getText());
Assert.assertEquals(1, viewState.getSelection());
viewState = this.calculatorEditor.erase();
viewState = this.calculatorEditor.insert("9");
Assert.assertEquals("9testtest12345678990", viewState.getText());
Assert.assertEquals(1, viewState.getSelection());
}
@Test
public void testErase() throws Exception {
this.calculatorEditor.setText("");
this.calculatorEditor.erase();
Assert.assertEquals("", this.calculatorEditor.getViewState().getText());
this.calculatorEditor.setText("test");
this.calculatorEditor.erase();
Assert.assertEquals("tes", this.calculatorEditor.getViewState().getText());
this.calculatorEditor.erase();
Assert.assertEquals("te", this.calculatorEditor.getViewState().getText());
this.calculatorEditor.erase();
Assert.assertEquals("t", this.calculatorEditor.getViewState().getText());
this.calculatorEditor.erase();
Assert.assertEquals("", this.calculatorEditor.getViewState().getText());
this.calculatorEditor.erase();
Assert.assertEquals("", this.calculatorEditor.getViewState().getText());
this.calculatorEditor.setText("1234");
this.calculatorEditor.moveCursorLeft();
this.calculatorEditor.erase();
Assert.assertEquals("124", this.calculatorEditor.getViewState().getText());
this.calculatorEditor.erase();
Assert.assertEquals("14", this.calculatorEditor.getViewState().getText());
this.calculatorEditor.erase();
Assert.assertEquals("4", this.calculatorEditor.getViewState().getText());
this.calculatorEditor.setText("1");
this.calculatorEditor.moveCursorLeft();
this.calculatorEditor.erase();
Assert.assertEquals("1", this.calculatorEditor.getViewState().getText());
}
@Test
public void testMoveSelection() throws Exception {
this.calculatorEditor.setText("");
CalculatorEditorViewState viewState = this.calculatorEditor.moveSelection(0);
Assert.assertEquals(0, viewState.getSelection());
viewState = this.calculatorEditor.moveSelection(2);
Assert.assertEquals(0, viewState.getSelection());
viewState = this.calculatorEditor.moveSelection(100);
Assert.assertEquals(0, viewState.getSelection());
viewState = this.calculatorEditor.moveSelection(-3);
Assert.assertEquals(0, viewState.getSelection());
viewState = this.calculatorEditor.moveSelection(-100);
Assert.assertEquals(0, viewState.getSelection());
viewState = this.calculatorEditor.setText("0123456789");
viewState = this.calculatorEditor.moveSelection(0);
Assert.assertEquals(10, viewState.getSelection());
viewState = this.calculatorEditor.moveSelection(1);
Assert.assertEquals(10, viewState.getSelection());
viewState = this.calculatorEditor.moveSelection(-2);
Assert.assertEquals(8, viewState.getSelection());
viewState = this.calculatorEditor.moveSelection(1);
Assert.assertEquals(9, viewState.getSelection());
viewState = this.calculatorEditor.moveSelection(-9);
Assert.assertEquals(0, viewState.getSelection());
viewState = this.calculatorEditor.moveSelection(-10);
Assert.assertEquals(0, viewState.getSelection());
viewState = this.calculatorEditor.moveSelection(2);
Assert.assertEquals(2, viewState.getSelection());
viewState = this.calculatorEditor.moveSelection(2);
Assert.assertEquals(4, viewState.getSelection());
viewState = this.calculatorEditor.moveSelection(-6);
Assert.assertEquals(0, viewState.getSelection());
}
@Test
public void testSetText() throws Exception {
CalculatorEditorViewState viewState = this.calculatorEditor.setText("test");
Assert.assertEquals("test", viewState.getText());
Assert.assertEquals(4, viewState.getSelection());
viewState = this.calculatorEditor.setText("testtest");
Assert.assertEquals("testtest", viewState.getText());
Assert.assertEquals(8, viewState.getSelection());
viewState = this.calculatorEditor.setText("");
Assert.assertEquals("", viewState.getText());
Assert.assertEquals(0, viewState.getSelection());
viewState = this.calculatorEditor.setText("testtest", 0);
Assert.assertEquals("testtest", viewState.getText());
Assert.assertEquals(0, viewState.getSelection());
viewState = this.calculatorEditor.setText("testtest", 2);
Assert.assertEquals("testtest", viewState.getText());
Assert.assertEquals(2, viewState.getSelection());
viewState = this.calculatorEditor.setText("", 0);
Assert.assertEquals("", viewState.getText());
Assert.assertEquals(0, viewState.getSelection());
viewState = this.calculatorEditor.setText("", 3);
Assert.assertEquals("", viewState.getText());
Assert.assertEquals(0, viewState.getSelection());
viewState = this.calculatorEditor.setText("", -3);
Assert.assertEquals("", viewState.getText());
Assert.assertEquals(0, viewState.getSelection());
viewState = this.calculatorEditor.setText("test");
Assert.assertEquals("test", viewState.getText());
Assert.assertEquals(4, viewState.getSelection());
viewState = this.calculatorEditor.setText("", 2);
Assert.assertEquals("", viewState.getText());
Assert.assertEquals(0, viewState.getSelection());
}
}

View File

@ -9,18 +9,18 @@ package org.solovyev.android.calculator.math;
import junit.framework.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import org.solovyev.android.calculator.CalculatorLocatorImpl;
import org.solovyev.android.calculator.AbstractCalculatorTest;
/**
* User: serso
* Date: 10/5/11
* Time: 1:25 AM
*/
public class MathTypeTest {
public class MathTypeTest extends AbstractCalculatorTest {
@BeforeClass
public static void setUp() throws Exception {
CalculatorLocatorImpl.getInstance().getEngine().init();
public static void staticSetUp() throws Exception {
AbstractCalculatorTest.staticSetUp();
}
@Test

View File

@ -156,6 +156,13 @@
<artifactId>annotations</artifactId>
</dependency>
<dependency>
<groupId>com.pivotallabs</groupId>
<artifactId>robolectric</artifactId>
<version>1.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>

View File

@ -0,0 +1,39 @@
package org.solovyev.android.calculator;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* User: serso
* Date: 10/7/12
* Time: 7:17 PM
*/
public enum AndroidFunctionCategory {
trigonometric(R.string.c_fun_category_trig),
hyperbolic_trigonometric(R.string.c_fun_category_hyper_trig),
comparison(R.string.c_fun_category_comparison),
my(R.string.c_fun_category_my),
common(R.string.c_fun_category_common);
private final int captionId;
AndroidFunctionCategory(int captionId) {
this.captionId = captionId;
}
public int getCaptionId() {
return captionId;
}
@Nullable
public AndroidFunctionCategory valueOf( @NotNull FunctionCategory functionCategory ) {
for (AndroidFunctionCategory androidFunctionCategory : values()) {
if ( androidFunctionCategory.name().equals(functionCategory.name()) ) {
return androidFunctionCategory;
}
}
return null;
}
}

View File

@ -0,0 +1,89 @@
/*
* Copyright (c) 2009-2011. Created by serso aka se.solovyev.
* For more information, please, contact se.solovyev@gmail.com
* or visit http://se.solovyev.org
*/
package org.solovyev.android.calculator;
import jscl.math.function.CustomFunction;
import jscl.math.function.Function;
import org.jetbrains.annotations.NotNull;
import org.solovyev.android.calculator.model.AFunction;
import org.solovyev.android.calculator.model.Functions;
import org.solovyev.common.JBuilder;
import org.solovyev.common.math.MathRegistry;
import java.util.HashMap;
import java.util.Map;
/**
* User: serso
* Date: 11/17/11
* Time: 11:28 PM
*/
public class AndroidFunctionsMathRegistry extends AbstractCalculatorMathRegistry<Function, AFunction> {
@NotNull
private static final Map<String, String> substitutes = new HashMap<String, String>();
static {
substitutes.put("", "sqrt");
}
@NotNull
private static final String FUNCTION_DESCRIPTION_PREFIX = "c_fun_description_";
public AndroidFunctionsMathRegistry(@NotNull MathRegistry<Function> functionsRegistry,
@NotNull MathEntityDao<AFunction> mathEntityDao) {
super(functionsRegistry, FUNCTION_DESCRIPTION_PREFIX, mathEntityDao);
}
@Override
public void load() {
super.load();
add(new CustomFunction.Builder(true, "log", new String[]{"base", "x"}, "ln(x)/ln(base)"));
}
@NotNull
@Override
protected Map<String, String> getSubstitutes() {
return substitutes;
}
@Override
public String getCategory(@NotNull Function function) {
for (FunctionCategory category : FunctionCategory.values()) {
if ( category.isInCategory(function) ) {
return category.name();
}
}
return null;
}
@NotNull
@Override
protected JBuilder<? extends Function> createBuilder(@NotNull AFunction entity) {
return new CustomFunction.Builder(entity.getName(), entity.getParameterNamesAsArray(), entity.getContent());
}
@Override
protected AFunction transform(@NotNull Function entity) {
if (entity instanceof CustomFunction) {
final AFunction result = new AFunction();
result.setName(entity.getName());
result.setContent(((CustomFunction) entity).getContent());
result.setParameterNames(((CustomFunction) entity).getParameterNames());
return result;
} else {
return null;
}
}
@NotNull
@Override
protected MathEntityPersistenceContainer<AFunction> createPersistenceContainer() {
return new Functions();
}
}

View File

@ -0,0 +1,92 @@
package org.solovyev.android.calculator;
import jscl.math.function.ArcTrigonometric;
import jscl.math.function.Comparison;
import jscl.math.function.Function;
import jscl.math.function.Trigonometric;
import org.jetbrains.annotations.NotNull;
import org.solovyev.common.collections.CollectionsUtils;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
/**
* User: serso
* Date: 10/7/12
* Time: 7:15 PM
*/
public enum FunctionCategory {
trigonometric(100){
@Override
public boolean isInCategory(@NotNull Function function) {
return (function instanceof Trigonometric || function instanceof ArcTrigonometric) && !hyperbolic_trigonometric.isInCategory(function);
}
},
hyperbolic_trigonometric(300) {
private final List<String> names = Arrays.asList("sinh", "cosh", "tanh", "coth", "asinh", "acosh", "atanh", "acoth");
@Override
public boolean isInCategory(@NotNull Function function) {
return names.contains(function.getName());
}
},
comparison(200) {
@Override
public boolean isInCategory(@NotNull Function function) {
return function instanceof Comparison;
}
},
my(0) {
@Override
public boolean isInCategory(@NotNull Function function) {
return !function.isSystem();
}
},
common(50) {
@Override
public boolean isInCategory(@NotNull Function function) {
for (FunctionCategory category : values()) {
if ( category != this ) {
if ( category.isInCategory(function) ) {
return false;
}
}
}
return true;
}
};
private final int tabOrder;
FunctionCategory(int tabOrder) {
this.tabOrder = tabOrder;
}
public abstract boolean isInCategory(@NotNull Function function);
@NotNull
public static List<FunctionCategory> getCategoriesByTabOrder() {
final List<FunctionCategory> result = CollectionsUtils.asList(FunctionCategory.values());
Collections.sort(result, new Comparator<FunctionCategory>() {
@Override
public int compare(FunctionCategory category, FunctionCategory category1) {
return category.tabOrder - category1.tabOrder;
}
});
// todo serso: current solution (as creating functions is not implemented yet)
result.remove(my);
return result;
}
}

View File

@ -1,79 +1,78 @@
/*
* Copyright (c) 2009-2011. Created by serso aka se.solovyev.
* For more information, please, contact se.solovyev@gmail.com
* or visit http://se.solovyev.org
*/
package org.solovyev.android.calculator.math.edit;
import android.os.Bundle;
import com.actionbarsherlock.app.SherlockFragmentActivity;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.solovyev.android.calculator.*;
import org.solovyev.android.calculator.about.CalculatorFragmentType;
import org.solovyev.android.calculator.history.CalculatorHistoryActivity;
import org.solovyev.android.calculator.model.AndroidFunctionsMathRegistry;
/**
* User: serso
* Date: 12/21/11
* Time: 10:33 PM
*/
public class CalculatorFunctionsActivity extends SherlockFragmentActivity implements CalculatorEventListener {
@NotNull
private final CalculatorActivityHelper activityHelper = CalculatorApplication.getInstance().createActivityHelper(R.layout.main_empty, CalculatorHistoryActivity.class.getSimpleName());
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
activityHelper.onCreate(this, savedInstanceState);
final CalculatorFragmentType fragmentType = CalculatorFragmentType.functions;
for (AndroidFunctionsMathRegistry.Category category : AndroidFunctionsMathRegistry.Category.getCategoriesByTabOrder()) {
activityHelper.addTab(this, fragmentType.createSubFragmentTag(category.name()), fragmentType.getFragmentClass(), AbstractMathEntityListFragment.createBundleFor(category.name()), category.getCaptionId(), R.id.main_layout);
}
}
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
activityHelper.onSaveInstanceState(this, outState);
}
@Override
protected void onResume() {
super.onResume();
activityHelper.onResume(this);
}
@Override
protected void onPause() {
this.activityHelper.onPause(this);
super.onPause();
}
@Override
protected void onDestroy() {
super.onDestroy();
this.activityHelper.onDestroy(this);
}
@Override
public void onCalculatorEvent(@NotNull CalculatorEventData calculatorEventData, @NotNull CalculatorEventType calculatorEventType, @Nullable Object data) {
switch (calculatorEventType) {
case use_function:
this.finish();
break;
}
}
}
/*
* Copyright (c) 2009-2011. Created by serso aka se.solovyev.
* For more information, please, contact se.solovyev@gmail.com
* or visit http://se.solovyev.org
*/
package org.solovyev.android.calculator.math.edit;
import android.os.Bundle;
import com.actionbarsherlock.app.SherlockFragmentActivity;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.solovyev.android.calculator.*;
import org.solovyev.android.calculator.about.CalculatorFragmentType;
import org.solovyev.android.calculator.history.CalculatorHistoryActivity;
/**
* User: serso
* Date: 12/21/11
* Time: 10:33 PM
*/
public class CalculatorFunctionsActivity extends SherlockFragmentActivity implements CalculatorEventListener {
@NotNull
private final CalculatorActivityHelper activityHelper = CalculatorApplication.getInstance().createActivityHelper(R.layout.main_empty, CalculatorHistoryActivity.class.getSimpleName());
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
activityHelper.onCreate(this, savedInstanceState);
final CalculatorFragmentType fragmentType = CalculatorFragmentType.functions;
for (FunctionCategory category : FunctionCategory.getCategoriesByTabOrder()) {
activityHelper.addTab(this, fragmentType.createSubFragmentTag(category.name()), fragmentType.getFragmentClass(), AbstractMathEntityListFragment.createBundleFor(category.name()), category.getCaptionId(), R.id.main_layout);
}
}
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
activityHelper.onSaveInstanceState(this, outState);
}
@Override
protected void onResume() {
super.onResume();
activityHelper.onResume(this);
}
@Override
protected void onPause() {
this.activityHelper.onPause(this);
super.onPause();
}
@Override
protected void onDestroy() {
super.onDestroy();
this.activityHelper.onDestroy(this);
}
@Override
public void onCalculatorEvent(@NotNull CalculatorEventData calculatorEventData, @NotNull CalculatorEventType calculatorEventType, @Nullable Object data) {
switch (calculatorEventType) {
case use_function:
this.finish();
break;
}
}
}

View File

@ -1,198 +0,0 @@
/*
* Copyright (c) 2009-2011. Created by serso aka se.solovyev.
* For more information, please, contact se.solovyev@gmail.com
* or visit http://se.solovyev.org
*/
package org.solovyev.android.calculator.model;
import android.app.Application;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.res.Resources;
import android.preference.PreferenceManager;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.simpleframework.xml.Serializer;
import org.simpleframework.xml.core.Persister;
import org.solovyev.android.calculator.CalculatorMathRegistry;
import org.solovyev.android.calculator.R;
import org.solovyev.common.JBuilder;
import org.solovyev.common.math.MathEntity;
import org.solovyev.common.math.MathRegistry;
import java.io.StringWriter;
import java.util.List;
import java.util.Map;
/**
* User: serso
* Date: 10/30/11
* Time: 1:03 AM
*/
public abstract class AbstractAndroidMathRegistry<T extends MathEntity, P extends MathPersistenceEntity> implements CalculatorMathRegistry<T> {
@NotNull
private final MathRegistry<T> mathRegistry;
@NotNull
private final String prefix;
@NotNull
private final Context context;
protected AbstractAndroidMathRegistry(@NotNull MathRegistry<T> mathRegistry,
@NotNull String prefix,
@NotNull Application application) {
this.mathRegistry = mathRegistry;
this.prefix = prefix;
this.context = application;
}
@NotNull
protected abstract Map<String, String> getSubstitutes();
@Nullable
@Override
public String getDescription(@NotNull String mathEntityName) {
final String stringName;
final Map<String, String> substitutes = getSubstitutes();
final String substitute = substitutes.get(mathEntityName);
if (substitute == null) {
stringName = prefix + mathEntityName;
} else {
stringName = prefix + substitute;
}
final Resources resources = context.getResources();
final int stringId = resources.getIdentifier(stringName, "string", R.class.getPackage().getName());
try {
return resources.getString(stringId);
} catch (Resources.NotFoundException e) {
return null;
}
}
public synchronized void load() {
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
if (preferences != null) {
final Integer preferenceStringId = getPreferenceStringId();
if (preferenceStringId != null) {
final String value = preferences.getString(context.getString(preferenceStringId), null);
if (value != null) {
final Serializer serializer = new Persister();
try {
final MathEntityPersistenceContainer<P> persistenceContainer = serializer.read(getPersistenceContainerClass(), value);
for (P entity : persistenceContainer.getEntities()) {
if (!contains(entity.getName())) {
add(createBuilder(entity));
}
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
}
/*Log.d(AndroidVarsRegistry.class.getName(), vars.size() + " variables registered!");
for (Var var : vars) {
Log.d(AndroidVarsRegistry.class.getName(), var.toString());
}*/
}
@NotNull
protected abstract JBuilder<? extends T> createBuilder(@NotNull P entity);
@NotNull
protected abstract Class<? extends MathEntityPersistenceContainer<P>> getPersistenceContainerClass();
@Nullable
protected abstract Integer getPreferenceStringId();
@Override
public synchronized void save() {
final Integer preferenceStringId = getPreferenceStringId();
if (preferenceStringId != null) {
final SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context);
final SharedPreferences.Editor editor = settings.edit();
final MathEntityPersistenceContainer<P> container = createPersistenceContainer();
for (T entity : this.getEntities()) {
if (!entity.isSystem()) {
final P persistenceEntity = transform(entity);
if (persistenceEntity != null) {
container.getEntities().add(persistenceEntity);
}
}
}
final StringWriter sw = new StringWriter();
final Serializer serializer = new Persister();
try {
serializer.write(container, sw);
} catch (Exception e) {
throw new RuntimeException(e);
}
editor.putString(context.getString(preferenceStringId), sw.toString());
editor.commit();
}
}
@Nullable
protected abstract P transform(@NotNull T entity);
@NotNull
protected abstract MathEntityPersistenceContainer<P> createPersistenceContainer();
@NotNull
@Override
public List<T> getEntities() {
return mathRegistry.getEntities();
}
@NotNull
@Override
public List<T> getSystemEntities() {
return mathRegistry.getSystemEntities();
}
@Override
public T add(@NotNull JBuilder<? extends T> JBuilder) {
return mathRegistry.add(JBuilder);
}
@Override
public void remove(@NotNull T var) {
mathRegistry.remove(var);
}
@NotNull
@Override
public List<String> getNames() {
return mathRegistry.getNames();
}
@Override
public boolean contains(@NotNull String name) {
return mathRegistry.contains(name);
}
@Override
public T get(@NotNull String name) {
return mathRegistry.get(name);
}
@Override
public T getById(@NotNull Integer id) {
return mathRegistry.getById(id);
}
}

View File

@ -17,10 +17,7 @@ import jscl.math.function.Function;
import jscl.math.function.IConstant;
import jscl.math.operator.Operator;
import org.jetbrains.annotations.NotNull;
import org.solovyev.android.calculator.CalculatorEngine;
import org.solovyev.android.calculator.CalculatorEngineImpl;
import org.solovyev.android.calculator.CalculatorMathEngine;
import org.solovyev.android.calculator.CalculatorMathRegistry;
import org.solovyev.android.calculator.*;
import org.solovyev.android.prefs.BooleanPreference;
import org.solovyev.android.prefs.Preference;
import org.solovyev.android.prefs.StringPreference;
@ -109,12 +106,12 @@ public class AndroidCalculatorEngine implements CalculatorEngine, SharedPreferen
this.lock = new Object();
final JsclMathEngine engine = JsclMathEngine.instance;
final JsclMathEngine engine = JsclMathEngine.getInstance();
this.calculatorEngine = new CalculatorEngineImpl(engine,
new AndroidVarsRegistryImpl(engine.getConstantsRegistry(), application),
new AndroidFunctionsMathRegistry(engine.getFunctionsRegistry(), application),
new AndroidOperatorsMathRegistry(engine.getOperatorsRegistry(), application),
new AndroidPostfixFunctionsRegistry(engine.getPostfixFunctionsRegistry(), application),
new AndroidVarsRegistryImpl(engine.getConstantsRegistry(), new AndroidMathEntityDao<Var>(R.string.p_calc_vars, application, Vars.class)),
new AndroidFunctionsMathRegistry(engine.getFunctionsRegistry(), new AndroidMathEntityDao<AFunction>(R.string.p_calc_functions, application, Functions.class)),
new AndroidOperatorsMathRegistry(engine.getOperatorsRegistry(), new AndroidMathEntityDao<MathPersistenceEntity>(null, application, null)),
new AndroidPostfixFunctionsRegistry(engine.getPostfixFunctionsRegistry(), new AndroidMathEntityDao<MathPersistenceEntity>(null, application, null)),
this.lock);
}

View File

@ -1,180 +0,0 @@
/*
* Copyright (c) 2009-2011. Created by serso aka se.solovyev.
* For more information, please, contact se.solovyev@gmail.com
* or visit http://se.solovyev.org
*/
package org.solovyev.android.calculator.model;
import android.app.Application;
import jscl.math.function.*;
import org.jetbrains.annotations.NotNull;
import org.solovyev.android.calculator.R;
import org.solovyev.common.JBuilder;
import org.solovyev.common.collections.CollectionsUtils;
import org.solovyev.common.math.MathRegistry;
import java.util.*;
/**
* User: serso
* Date: 11/17/11
* Time: 11:28 PM
*/
public class AndroidFunctionsMathRegistry extends AbstractAndroidMathRegistry<Function, AFunction> {
public static enum Category {
trigonometric(R.string.c_fun_category_trig, 100){
@Override
boolean isInCategory(@NotNull Function function) {
return (function instanceof Trigonometric || function instanceof ArcTrigonometric) && !hyperbolic_trigonometric.isInCategory(function);
}
},
hyperbolic_trigonometric(R.string.c_fun_category_hyper_trig, 300) {
private final List<String> names = Arrays.asList("sinh", "cosh", "tanh", "coth", "asinh", "acosh", "atanh", "acoth");
@Override
boolean isInCategory(@NotNull Function function) {
return names.contains(function.getName());
}
},
comparison(R.string.c_fun_category_comparison, 200) {
@Override
boolean isInCategory(@NotNull Function function) {
return function instanceof Comparison;
}
},
my(R.string.c_fun_category_my, 0) {
@Override
boolean isInCategory(@NotNull Function function) {
return !function.isSystem();
}
},
common(R.string.c_fun_category_common, 50) {
@Override
boolean isInCategory(@NotNull Function function) {
for (Category category : values()) {
if ( category != this ) {
if ( category.isInCategory(function) ) {
return false;
}
}
}
return true;
}
};
private final int captionId;
private final int tabOrder;
Category(int captionId, int tabOrder) {
this.captionId = captionId;
this.tabOrder = tabOrder;
}
public int getCaptionId() {
return captionId;
}
abstract boolean isInCategory(@NotNull Function function);
@NotNull
public static List<Category> getCategoriesByTabOrder() {
final List<Category> result = CollectionsUtils.asList(Category.values());
Collections.sort(result, new Comparator<Category>() {
@Override
public int compare(Category category, Category category1) {
return category.tabOrder - category1.tabOrder;
}
});
// todo serso: current solution (as creating functions is not implemented yet)
result.remove(my);
return result;
}
}
@NotNull
private static final Map<String, String> substitutes = new HashMap<String, String>();
static {
substitutes.put("", "sqrt");
}
@NotNull
private static final String FUNCTION_DESCRIPTION_PREFIX = "c_fun_description_";
public AndroidFunctionsMathRegistry(@NotNull MathRegistry<Function> functionsRegistry,
@NotNull Application application) {
super(functionsRegistry, FUNCTION_DESCRIPTION_PREFIX, application);
}
@Override
public void load() {
super.load();
add(new CustomFunction.Builder(true, "log", new String[]{"base", "x"}, "ln(x)/ln(base)"));
}
@NotNull
@Override
protected Map<String, String> getSubstitutes() {
return substitutes;
}
@Override
public String getCategory(@NotNull Function function) {
for (Category category : Category.values()) {
if ( category.isInCategory(function) ) {
return category.name();
}
}
return null;
}
@NotNull
@Override
protected JBuilder<? extends Function> createBuilder(@NotNull AFunction entity) {
return new CustomFunction.Builder(entity.getName(), entity.getParameterNamesAsArray(), entity.getContent());
}
@NotNull
@Override
protected Class<? extends MathEntityPersistenceContainer<AFunction>> getPersistenceContainerClass() {
return Functions.class;
}
@Override
protected Integer getPreferenceStringId() {
return R.string.p_calc_functions;
}
@Override
protected AFunction transform(@NotNull Function entity) {
if (entity instanceof CustomFunction) {
final AFunction result = new AFunction();
result.setName(entity.getName());
result.setContent(((CustomFunction) entity).getContent());
result.setParameterNames(((CustomFunction) entity).getParameterNames());
return result;
} else {
return null;
}
}
@NotNull
@Override
protected MathEntityPersistenceContainer<AFunction> createPersistenceContainer() {
return new Functions();
}
}

View File

@ -0,0 +1,95 @@
package org.solovyev.android.calculator.model;
import android.app.Application;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.res.Resources;
import android.preference.PreferenceManager;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.simpleframework.xml.Serializer;
import org.simpleframework.xml.core.Persister;
import org.solovyev.android.calculator.MathEntityDao;
import org.solovyev.android.calculator.MathEntityPersistenceContainer;
import org.solovyev.android.calculator.MathPersistenceEntity;
import org.solovyev.android.calculator.R;
import java.io.StringWriter;
/**
* User: serso
* Date: 10/7/12
* Time: 6:46 PM
*/
public class AndroidMathEntityDao<T extends MathPersistenceEntity> implements MathEntityDao<T> {
@Nullable
private final Integer preferenceStringId;
@NotNull
private final Context context;
@Nullable
private final Class<? extends MathEntityPersistenceContainer<T>> persistenceContainerClass;
public AndroidMathEntityDao(@Nullable Integer preferenceStringId,
@NotNull Application application,
@Nullable Class<? extends MathEntityPersistenceContainer<T>> persistenceContainerClass) {
this.preferenceStringId = preferenceStringId;
this.context = application;
this.persistenceContainerClass = persistenceContainerClass;
}
@Override
public void save(@NotNull MathEntityPersistenceContainer<T> container) {
if (preferenceStringId != null) {
final SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context);
final SharedPreferences.Editor editor = settings.edit();
final StringWriter sw = new StringWriter();
final Serializer serializer = new Persister();
try {
serializer.write(container, sw);
} catch (Exception e) {
throw new RuntimeException(e);
}
editor.putString(context.getString(preferenceStringId), sw.toString());
editor.commit();
}
}
@Nullable
@Override
public MathEntityPersistenceContainer<T> load() {
if (persistenceContainerClass != null && preferenceStringId != null) {
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
if (preferences != null) {
final String value = preferences.getString(context.getString(preferenceStringId), null);
if (value != null) {
final Serializer serializer = new Persister();
try {
return serializer.read(persistenceContainerClass, value);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
}
return null;
}
@Nullable
public String getDescription(@NotNull String descriptionId) {
final Resources resources = context.getResources();
final int stringId = resources.getIdentifier(descriptionId, "string", R.class.getPackage().getName());
try {
return resources.getString(stringId);
} catch (Resources.NotFoundException e) {
return null;
}
}
}

View File

@ -1,180 +1,165 @@
/*
* Copyright (c) 2009-2011. Created by serso aka se.solovyev.
* For more information, please, contact se.solovyev@gmail.com
* or visit http://se.solovyev.org
*/
package org.solovyev.android.calculator.model;
import android.app.Application;
import jscl.math.function.ArcTrigonometric;
import jscl.math.function.Comparison;
import jscl.math.function.Trigonometric;
import jscl.math.operator.*;
import org.jetbrains.annotations.NotNull;
import org.solovyev.android.calculator.R;
import org.solovyev.common.JBuilder;
import org.solovyev.common.collections.CollectionsUtils;
import org.solovyev.common.math.MathRegistry;
import java.util.*;
/**
* User: serso
* Date: 11/17/11
* Time: 11:29 PM
*/
public class AndroidOperatorsMathRegistry extends AbstractAndroidMathRegistry<Operator, MathPersistenceEntity> {
@NotNull
private static final Map<String, String> substitutes = new HashMap<String, String>();
static {
substitutes.put("Σ", "sum");
substitutes.put("", "product");
substitutes.put("", "derivative");
substitutes.put("∫ab", "integral_ab");
substitutes.put("", "integral");
substitutes.put("Σ", "sum");
}
@NotNull
private static final String OPERATOR_DESCRIPTION_PREFIX = "c_op_description_";
protected AndroidOperatorsMathRegistry(@NotNull MathRegistry<Operator> functionsRegistry,
@NotNull Application application) {
super(functionsRegistry, OPERATOR_DESCRIPTION_PREFIX, application);
}
@NotNull
@Override
protected Map<String, String> getSubstitutes() {
return substitutes;
}
@Override
public String getCategory(@NotNull Operator operator) {
for (Category category : Category.values()) {
if ( category.isInCategory(operator) ) {
return category.name();
}
}
return null;
}
@Override
public void load() {
// not supported yet
}
@NotNull
@Override
protected JBuilder<? extends Operator> createBuilder(@NotNull MathPersistenceEntity entity) {
return null; //To change body of implemented methods use File | Settings | File Templates.
}
@NotNull
@Override
protected Class<? extends MathEntityPersistenceContainer<MathPersistenceEntity>> getPersistenceContainerClass() {
return null; //To change body of implemented methods use File | Settings | File Templates.
}
@Override
protected Integer getPreferenceStringId() {
return null; //To change body of implemented methods use File | Settings | File Templates.
}
@Override
public void save() {
// not supported yet
}
@Override
protected MathPersistenceEntity transform(@NotNull Operator entity) {
return null; //To change body of implemented methods use File | Settings | File Templates.
}
@NotNull
@Override
protected MathEntityPersistenceContainer<MathPersistenceEntity> createPersistenceContainer() {
return null; //To change body of implemented methods use File | Settings | File Templates.
}
/*
**********************************************************************
*
* STATIC
*
**********************************************************************
*/
public static enum Category {
derivatives(R.string.derivatives, 100){
@Override
boolean isInCategory(@NotNull Operator operator) {
return operator instanceof Derivative || operator instanceof Integral || operator instanceof IndefiniteIntegral;
}
},
other(R.string.other, 200) {
@Override
boolean isInCategory(@NotNull Operator operator) {
return operator instanceof Sum || operator instanceof Product;
}
},
my(R.string.c_fun_category_my, 0) {
@Override
boolean isInCategory(@NotNull Operator operator) {
return !operator.isSystem();
}
},
common(R.string.c_fun_category_common, 50) {
@Override
boolean isInCategory(@NotNull Operator operator) {
for (Category category : values()) {
if ( category != this ) {
if ( category.isInCategory(operator) ) {
return false;
}
}
}
return true;
}
};
private final int captionId;
private final int tabOrder;
Category(int captionId, int tabOrder) {
this.captionId = captionId;
this.tabOrder = tabOrder;
}
public int getCaptionId() {
return captionId;
}
abstract boolean isInCategory(@NotNull Operator operator);
@NotNull
public static List<Category> getCategoriesByTabOrder() {
final List<Category> result = CollectionsUtils.asList(Category.values());
Collections.sort(result, new Comparator<Category>() {
@Override
public int compare(Category category, Category category1) {
return category.tabOrder - category1.tabOrder;
}
});
// todo serso: current solution (as creating operators is not implemented yet)
result.remove(my);
return result;
}
}
}
/*
* Copyright (c) 2009-2011. Created by serso aka se.solovyev.
* For more information, please, contact se.solovyev@gmail.com
* or visit http://se.solovyev.org
*/
package org.solovyev.android.calculator.model;
import jscl.math.operator.*;
import org.jetbrains.annotations.NotNull;
import org.solovyev.android.calculator.*;
import org.solovyev.common.JBuilder;
import org.solovyev.common.collections.CollectionsUtils;
import org.solovyev.common.math.MathRegistry;
import java.util.*;
/**
* User: serso
* Date: 11/17/11
* Time: 11:29 PM
*/
public class AndroidOperatorsMathRegistry extends AbstractCalculatorMathRegistry<Operator, MathPersistenceEntity> {
@NotNull
private static final Map<String, String> substitutes = new HashMap<String, String>();
static {
substitutes.put("Σ", "sum");
substitutes.put("", "product");
substitutes.put("", "derivative");
substitutes.put("∫ab", "integral_ab");
substitutes.put("", "integral");
substitutes.put("Σ", "sum");
}
@NotNull
private static final String OPERATOR_DESCRIPTION_PREFIX = "c_op_description_";
protected AndroidOperatorsMathRegistry(@NotNull MathRegistry<Operator> functionsRegistry,
@NotNull MathEntityDao<MathPersistenceEntity> mathEntityDao) {
super(functionsRegistry, OPERATOR_DESCRIPTION_PREFIX, mathEntityDao);
}
@NotNull
@Override
protected Map<String, String> getSubstitutes() {
return substitutes;
}
@Override
public String getCategory(@NotNull Operator operator) {
for (Category category : Category.values()) {
if ( category.isInCategory(operator) ) {
return category.name();
}
}
return null;
}
@Override
public void load() {
// not supported yet
}
@NotNull
@Override
protected JBuilder<? extends Operator> createBuilder(@NotNull MathPersistenceEntity entity) {
return null; //To change body of implemented methods use File | Settings | File Templates.
}
@Override
public void save() {
// not supported yet
}
@Override
protected MathPersistenceEntity transform(@NotNull Operator entity) {
return null; //To change body of implemented methods use File | Settings | File Templates.
}
@NotNull
@Override
protected MathEntityPersistenceContainer<MathPersistenceEntity> createPersistenceContainer() {
return null; //To change body of implemented methods use File | Settings | File Templates.
}
/*
**********************************************************************
*
* STATIC
*
**********************************************************************
*/
public static enum Category {
derivatives(R.string.derivatives, 100){
@Override
boolean isInCategory(@NotNull Operator operator) {
return operator instanceof Derivative || operator instanceof Integral || operator instanceof IndefiniteIntegral;
}
},
other(R.string.other, 200) {
@Override
boolean isInCategory(@NotNull Operator operator) {
return operator instanceof Sum || operator instanceof Product;
}
},
my(R.string.c_fun_category_my, 0) {
@Override
boolean isInCategory(@NotNull Operator operator) {
return !operator.isSystem();
}
},
common(R.string.c_fun_category_common, 50) {
@Override
boolean isInCategory(@NotNull Operator operator) {
for (Category category : values()) {
if ( category != this ) {
if ( category.isInCategory(operator) ) {
return false;
}
}
}
return true;
}
};
private final int captionId;
private final int tabOrder;
Category(int captionId, int tabOrder) {
this.captionId = captionId;
this.tabOrder = tabOrder;
}
public int getCaptionId() {
return captionId;
}
abstract boolean isInCategory(@NotNull Operator operator);
@NotNull
public static List<Category> getCategoriesByTabOrder() {
final List<Category> result = CollectionsUtils.asList(Category.values());
Collections.sort(result, new Comparator<Category>() {
@Override
public int compare(Category category, Category category1) {
return category.tabOrder - category1.tabOrder;
}
});
// todo serso: current solution (as creating operators is not implemented yet)
result.remove(my);
return result;
}
}
}

View File

@ -1,96 +1,88 @@
/*
* Copyright (c) 2009-2011. Created by serso aka se.solovyev.
* For more information, please, contact se.solovyev@gmail.com
* or visit http://se.solovyev.org
*/
package org.solovyev.android.calculator.model;
import android.app.Application;
import jscl.math.operator.Operator;
import org.jetbrains.annotations.NotNull;
import org.solovyev.common.JBuilder;
import org.solovyev.common.math.MathRegistry;
import java.util.HashMap;
import java.util.Map;
/**
* User: serso
* Date: 11/19/11
* Time: 1:48 PM
*/
public class AndroidPostfixFunctionsRegistry extends AbstractAndroidMathRegistry<Operator, MathPersistenceEntity> {
@NotNull
private static final Map<String, String> substitutes = new HashMap<String, String>();
static {
substitutes.put("%", "percent");
substitutes.put("!", "factorial");
substitutes.put("!!", "double_factorial");
substitutes.put("°", "degree");
}
@NotNull
private static final String POSTFIX_FUNCTION_DESCRIPTION_PREFIX = "c_pf_description_";
protected AndroidPostfixFunctionsRegistry(@NotNull MathRegistry<Operator> functionsRegistry,
@NotNull Application application) {
super(functionsRegistry, POSTFIX_FUNCTION_DESCRIPTION_PREFIX, application);
}
@NotNull
@Override
protected Map<String, String> getSubstitutes() {
return substitutes;
}
@Override
public String getCategory(@NotNull Operator operator) {
for (AndroidOperatorsMathRegistry.Category category : AndroidOperatorsMathRegistry.Category.values()) {
if ( category.isInCategory(operator) ) {
return category.name();
}
}
return null;
}
@Override
public void load() {
// not supported yet
}
@NotNull
@Override
protected JBuilder<? extends Operator> createBuilder(@NotNull MathPersistenceEntity entity) {
return null; //To change body of implemented methods use File | Settings | File Templates.
}
@NotNull
@Override
protected Class<? extends MathEntityPersistenceContainer<MathPersistenceEntity>> getPersistenceContainerClass() {
return null; //To change body of implemented methods use File | Settings | File Templates.
}
@Override
protected Integer getPreferenceStringId() {
return null; //To change body of implemented methods use File | Settings | File Templates.
}
@Override
public void save() {
// not supported yet
}
@Override
protected MathPersistenceEntity transform(@NotNull Operator entity) {
return null; //To change body of implemented methods use File | Settings | File Templates.
}
@NotNull
@Override
protected MathEntityPersistenceContainer<MathPersistenceEntity> createPersistenceContainer() {
return null; //To change body of implemented methods use File | Settings | File Templates.
}
}
/*
* Copyright (c) 2009-2011. Created by serso aka se.solovyev.
* For more information, please, contact se.solovyev@gmail.com
* or visit http://se.solovyev.org
*/
package org.solovyev.android.calculator.model;
import jscl.math.operator.Operator;
import org.jetbrains.annotations.NotNull;
import org.solovyev.android.calculator.AbstractCalculatorMathRegistry;
import org.solovyev.android.calculator.MathEntityDao;
import org.solovyev.android.calculator.MathEntityPersistenceContainer;
import org.solovyev.android.calculator.MathPersistenceEntity;
import org.solovyev.common.JBuilder;
import org.solovyev.common.math.MathRegistry;
import java.util.HashMap;
import java.util.Map;
/**
* User: serso
* Date: 11/19/11
* Time: 1:48 PM
*/
public class AndroidPostfixFunctionsRegistry extends AbstractCalculatorMathRegistry<Operator, MathPersistenceEntity> {
@NotNull
private static final Map<String, String> substitutes = new HashMap<String, String>();
static {
substitutes.put("%", "percent");
substitutes.put("!", "factorial");
substitutes.put("!!", "double_factorial");
substitutes.put("°", "degree");
}
@NotNull
private static final String POSTFIX_FUNCTION_DESCRIPTION_PREFIX = "c_pf_description_";
protected AndroidPostfixFunctionsRegistry(@NotNull MathRegistry<Operator> functionsRegistry,
@NotNull MathEntityDao<MathPersistenceEntity> mathEntityDao) {
super(functionsRegistry, POSTFIX_FUNCTION_DESCRIPTION_PREFIX, mathEntityDao);
}
@NotNull
@Override
protected Map<String, String> getSubstitutes() {
return substitutes;
}
@Override
public String getCategory(@NotNull Operator operator) {
for (AndroidOperatorsMathRegistry.Category category : AndroidOperatorsMathRegistry.Category.values()) {
if ( category.isInCategory(operator) ) {
return category.name();
}
}
return null;
}
@Override
public void load() {
// not supported yet
}
@NotNull
@Override
protected JBuilder<? extends Operator> createBuilder(@NotNull MathPersistenceEntity entity) {
return null; //To change body of implemented methods use File | Settings | File Templates.
}
@Override
public void save() {
// not supported yet
}
@Override
protected MathPersistenceEntity transform(@NotNull Operator entity) {
return null; //To change body of implemented methods use File | Settings | File Templates.
}
@NotNull
@Override
protected MathEntityPersistenceContainer<MathPersistenceEntity> createPersistenceContainer() {
return null; //To change body of implemented methods use File | Settings | File Templates.
}
}

View File

@ -6,10 +6,11 @@
package org.solovyev.android.calculator.model;
import android.app.Application;
import jscl.math.function.IConstant;
import org.jetbrains.annotations.NotNull;
import org.solovyev.android.calculator.R;
import org.solovyev.android.calculator.AbstractCalculatorMathRegistry;
import org.solovyev.android.calculator.MathEntityDao;
import org.solovyev.android.calculator.MathEntityPersistenceContainer;
import org.solovyev.common.JBuilder;
import org.solovyev.common.math.MathRegistry;
@ -21,7 +22,7 @@ import java.util.Map;
* Date: 9/29/11
* Time: 4:57 PM
*/
class AndroidVarsRegistryImpl extends AbstractAndroidMathRegistry<IConstant, Var> {
class AndroidVarsRegistryImpl extends AbstractCalculatorMathRegistry<IConstant, Var> {
@NotNull
private static final Map<String, String> substitutes = new HashMap<String, String>();
@ -34,8 +35,8 @@ class AndroidVarsRegistryImpl extends AbstractAndroidMathRegistry<IConstant, Var
}
protected AndroidVarsRegistryImpl(@NotNull MathRegistry<IConstant> mathRegistry,
@NotNull Application application) {
super(mathRegistry, "c_var_description_", application);
@NotNull MathEntityDao<Var> mathEntityDao) {
super(mathRegistry, "c_var_description_", mathEntityDao);
}
@NotNull
@ -66,24 +67,13 @@ class AndroidVarsRegistryImpl extends AbstractAndroidMathRegistry<IConstant, Var
return new Var.Builder(entity);
}
@NotNull
@Override
protected Class<? extends MathEntityPersistenceContainer<Var>> getPersistenceContainerClass() {
return Vars.class;
}
@NotNull
@NotNull
@Override
protected MathEntityPersistenceContainer<Var> createPersistenceContainer() {
return new Vars();
}
@NotNull
protected Integer getPreferenceStringId() {
return R.string.p_calc_vars;
}
private void tryToAddAuxVar(@NotNull String name) {
private void tryToAddAuxVar(@NotNull String name) {
if ( !contains(name) ) {
add(new Var.Builder(name, (String)null));
}

View File

@ -14,6 +14,7 @@ import org.jetbrains.annotations.Nullable;
import org.simpleframework.xml.Element;
import org.simpleframework.xml.Root;
import org.simpleframework.xml.Transient;
import org.solovyev.android.calculator.MathPersistenceEntity;
import org.solovyev.common.JBuilder;
import org.solovyev.common.math.MathEntity;
import org.solovyev.common.text.StringUtils;

View File

@ -1,8 +1,8 @@
package org.solovyev.android.calculator.model;
import jscl.math.function.IConstant;
import org.simpleframework.xml.ElementList;
import org.simpleframework.xml.Root;
import org.solovyev.android.calculator.MathEntityPersistenceContainer;
import java.util.ArrayList;
import java.util.List;

View File

@ -6,7 +6,6 @@
package org.solovyev.android.calculator.plot;
import android.util.Log;
import jscl.math.Expression;
import jscl.math.Generic;
import jscl.math.JsclInteger;
@ -375,7 +374,7 @@ public final class PlotUtils {
// double dydx1 = dy2 / dx1;
if ( dy2 > MAX_Y_DIFF && dx2 < MAX_X_DIFF && isDifferentSign(point.getY2(), point.getY1()) && isDifferentSign(point.getDyDx1(), point.getDyDx2())) {
Log.d(CalculatorPlotActivity.class.getName(), "Singularity: " + point);
//Log.d(CalculatorPlotActivity.class.getName(), "Singularity: " + point);
//Log.d(CalculatorPlotActivity.class.getName(), String.valueOf(prevX + Math.abs(x - prevX) / 2) + ", null");
series.add(point.getX1() + point.getAbsDx2() / 2, MathHelper.NULL_VALUE);
point.clearHistory();

View File

@ -31,7 +31,7 @@ public class FromJsclNumericTextProcessorTest {
public void testCreateResultForComplexNumber() throws Exception {
final FromJsclNumericTextProcessor cm = new FromJsclNumericTextProcessor();
final JsclMathEngine me = JsclMathEngine.instance;
final JsclMathEngine me = JsclMathEngine.getInstance();
final AngleUnit defaultAngleUnits = me.getAngleUnits();
Assert.assertEquals("1.22133+23 123i", cm.process(Expression.valueOf("1.22133232+23123*i").numeric()));

View File

@ -36,7 +36,7 @@ public class NumeralBaseTest {
public void testConversion() throws Exception {
CSVReader reader = null;
try {
final MathEngine me = JsclMathEngine.instance;
final MathEngine me = JsclMathEngine.getInstance();
reader = new CSVReader(new InputStreamReader(NumeralBaseTest.class.getResourceAsStream("/org/solovyev/android/calculator/model/nb_table.csv")), '\t');

View File

@ -152,15 +152,15 @@ public class ToJsclTextProcessorTest {
public void testNumeralBases() throws Exception {
final TextProcessor<PreparedExpression, String> processor = ToJsclTextProcessor.getInstance();
final NumeralBase defaultNumeralBase = JsclMathEngine.instance.getNumeralBase();
final NumeralBase defaultNumeralBase = JsclMathEngine.getInstance().getNumeralBase();
try{
JsclMathEngine.instance.setNumeralBase(NumeralBase.bin);
Assert.assertEquals("101", JsclMathEngine.instance.evaluate("10+11"));
JsclMathEngine.getInstance().setNumeralBase(NumeralBase.bin);
Assert.assertEquals("101", JsclMathEngine.getInstance().evaluate("10+11"));
JsclMathEngine.instance.setNumeralBase(NumeralBase.hex);
JsclMathEngine.getInstance().setNumeralBase(NumeralBase.hex);
Assert.assertEquals("56CE+CAD", processor.process("56CE+CAD").getExpression());
} finally {
JsclMathEngine.instance.setNumeralBase(defaultNumeralBase);
JsclMathEngine.getInstance().setNumeralBase(defaultNumeralBase);
}
}
}

View File

@ -0,0 +1,19 @@
package org.solovyev.android.calculator.plot;
import com.xtremelabs.robolectric.RobolectricTestRunner;
import org.jetbrains.annotations.NotNull;
import org.junit.runners.model.InitializationError;
import java.io.File;
/**
* User: serso
* Date: 10/7/12
* Time: 5:36 PM
*/
public class CalculatorppTestRunner extends RobolectricTestRunner {
public CalculatorppTestRunner(@NotNull Class<?> testClass) throws InitializationError {
super(testClass, new File("calculatorpp"));
}
}

View File

@ -12,13 +12,13 @@ import junit.framework.Assert;
import org.achartengine.model.XYSeries;
import org.jetbrains.annotations.NotNull;
import org.junit.Test;
import org.junit.runner.RunWith;
/**
* User: serso
* Date: 12/5/11
* Time: 9:07 PM
*/
public class PlotUtilsTest {
@Test

538
pom.xml
View File

@ -1,265 +1,275 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.solovyev.android</groupId>
<artifactId>calculatorpp-parent</artifactId>
<packaging>pom</packaging>
<version>1.3.2</version>
<name>Calculator++</name>
<modules>
<module>calculatorpp</module>
<module>calculatorpp-test</module>
<module>calculatorpp-core</module>
</modules>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.solovyev</groupId>
<artifactId>common-core</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>org.solovyev</groupId>
<artifactId>common-text</artifactId>
<version>1.0.1</version>
</dependency>
<dependency>
<groupId>org.solovyev.android</groupId>
<artifactId>android-common-core</artifactId>
<type>apklib</type>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>org.solovyev.android</groupId>
<artifactId>android-common-ads</artifactId>
<type>apklib</type>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>org.solovyev.android</groupId>
<artifactId>android-common-view</artifactId>
<type>apklib</type>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>org.solovyev.android</groupId>
<artifactId>android-common-preferences</artifactId>
<type>apklib</type>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>org.solovyev.android</groupId>
<artifactId>android-common-menu</artifactId>
<type>apklib</type>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>org.solovyev.android</groupId>
<artifactId>android-common-sherlock</artifactId>
<version>1.0.0</version>
<type>apklib</type>
</dependency>
<dependency>
<groupId>com.actionbarsherlock</groupId>
<artifactId>library</artifactId>
<version>4.1.0</version>
<type>apklib</type>
</dependency>
<dependency>
<groupId>org.solovyev</groupId>
<artifactId>jscl</artifactId>
<version>0.0.2</version>
<exclusions>
<exclusion>
<artifactId>xercesImpl</artifactId>
<groupId>xerces</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.solovyev.android</groupId>
<artifactId>android-common-other</artifactId>
<type>apklib</type>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.2</version>
</dependency>
<dependency>
<groupId>com.intellij</groupId>
<artifactId>annotations</artifactId>
<version>7.0.3</version>
</dependency>
<dependency>
<groupId>com.google.android</groupId>
<artifactId>android</artifactId>
<version>4.0.1.2</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.google.android</groupId>
<artifactId>support-v4</artifactId>
<version>r7</version>
</dependency>
<dependency>
<groupId>com.google.android</groupId>
<artifactId>android-test</artifactId>
<version>2.3.1</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>11.0.2</version>
</dependency>
<dependency>
<groupId>org.simpleframework</groupId>
<artifactId>simple-xml</artifactId>
<version>2.6.1</version>
<exclusions>
<exclusion>
<artifactId>stax-api</artifactId>
<groupId>stax</groupId>
</exclusion>
<exclusion>
<artifactId>xpp3</artifactId>
<groupId>xpp3</groupId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>com.electriccloud</groupId>
<artifactId>javac2-maven-plugin</artifactId>
<version>1.0.1</version>
<executions>
<execution>
<id>@NotNull Instrumentation</id>
<goals>
<goal>instrument</goal>
</goals>
<!--compile phase instead of process-classes because of proguard.
@NotNull instrumentation will be done now after compilation and before proguard-->
<phase>compile</phase>
</execution>
</executions>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jarsigner-plugin</artifactId>
<version>1.2</version>
</plugin>
<plugin>
<groupId>com.jayway.maven.plugins.android.generation2</groupId>
<artifactId>android-maven-plugin</artifactId>
<version>3.1.1</version>
<configuration>
<sourceDirectories>
<sourceDirectory>${project.basedir}/src/main/java</sourceDirectory>
</sourceDirectories>
<sdk>
<platform>15</platform>
</sdk>
<emulator>
<avd>23</avd>
<wait>10000</wait>
<!--<options>-no-skin</options>-->
</emulator>
<zipalign>
<verbose>true</verbose>
</zipalign>
<undeployBeforeDeploy>true</undeployBeforeDeploy>
</configuration>
</plugin>
<plugin>
<groupId>com.pyx4me</groupId>
<artifactId>proguard-maven-plugin</artifactId>
<version>2.0.4</version>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.5</version>
</plugin>
</plugins>
</pluginManagement>
</build>
<profiles>
<profile>
<!-- the standard profile runs instrumentation tests -->
<id>standard</id>
</profile>
<profile>
<!-- the release profile does sign, proguard, zipalign -->
<id>release</id>
<!-- via this activation the profile is automatically used when the release is done with the maven release
plugin -->
<activation>
<property>
<name>performRelease</name>
<value>true</value>
</property>
</activation>
</profile>
</profiles>
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.solovyev.android</groupId>
<artifactId>calculatorpp-parent</artifactId>
<packaging>pom</packaging>
<version>1.3.2</version>
<name>Calculator++</name>
<modules>
<module>calculatorpp</module>
<module>calculatorpp-test</module>
<module>calculatorpp-core</module>
</modules>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.solovyev</groupId>
<artifactId>common-core</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>org.solovyev</groupId>
<artifactId>common-text</artifactId>
<version>1.0.1</version>
</dependency>
<dependency>
<groupId>org.solovyev.android</groupId>
<artifactId>android-common-core</artifactId>
<type>apklib</type>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>org.solovyev.android</groupId>
<artifactId>android-common-ads</artifactId>
<type>apklib</type>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>org.solovyev.android</groupId>
<artifactId>android-common-view</artifactId>
<type>apklib</type>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>org.solovyev.android</groupId>
<artifactId>android-common-preferences</artifactId>
<type>apklib</type>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>org.solovyev.android</groupId>
<artifactId>android-common-menu</artifactId>
<type>apklib</type>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>org.solovyev.android</groupId>
<artifactId>android-common-sherlock</artifactId>
<version>1.0.0</version>
<type>apklib</type>
</dependency>
<dependency>
<groupId>com.actionbarsherlock</groupId>
<artifactId>library</artifactId>
<version>4.1.0</version>
<type>apklib</type>
</dependency>
<dependency>
<groupId>org.solovyev</groupId>
<artifactId>jscl</artifactId>
<version>0.0.3</version>
<exclusions>
<exclusion>
<artifactId>xercesImpl</artifactId>
<groupId>xerces</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.solovyev.android</groupId>
<artifactId>android-common-other</artifactId>
<type>apklib</type>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.2</version>
</dependency>
<dependency>
<groupId>com.intellij</groupId>
<artifactId>annotations</artifactId>
<version>7.0.3</version>
</dependency>
<dependency>
<groupId>com.google.android</groupId>
<artifactId>android</artifactId>
<version>4.0.1.2</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.google.android</groupId>
<artifactId>support-v4</artifactId>
<version>r7</version>
</dependency>
<dependency>
<groupId>com.google.android</groupId>
<artifactId>android-test</artifactId>
<version>2.3.1</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>11.0.2</version>
</dependency>
<dependency>
<groupId>org.simpleframework</groupId>
<artifactId>simple-xml</artifactId>
<version>2.6.1</version>
<exclusions>
<exclusion>
<artifactId>stax-api</artifactId>
<groupId>stax</groupId>
</exclusion>
<exclusion>
<artifactId>xpp3</artifactId>
<groupId>xpp3</groupId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>com.electriccloud</groupId>
<artifactId>javac2-maven-plugin</artifactId>
<version>1.0.1</version>
<executions>
<execution>
<id>@NotNull Instrumentation</id>
<goals>
<goal>instrument</goal>
</goals>
<!--compile phase instead of process-classes because of proguard.
@NotNull instrumentation will be done now after compilation and before proguard-->
<phase>compile</phase>
</execution>
</executions>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jarsigner-plugin</artifactId>
<version>1.2</version>
</plugin>
<plugin>
<groupId>com.jayway.maven.plugins.android.generation2</groupId>
<artifactId>android-maven-plugin</artifactId>
<version>3.1.1</version>
<configuration>
<sourceDirectories>
<sourceDirectory>${project.basedir}/src/main/java</sourceDirectory>
</sourceDirectories>
<sdk>
<platform>15</platform>
</sdk>
<emulator>
<avd>23</avd>
<wait>10000</wait>
<!--<options>-no-skin</options>-->
</emulator>
<zipalign>
<verbose>true</verbose>
</zipalign>
<undeployBeforeDeploy>true</undeployBeforeDeploy>
</configuration>
</plugin>
<plugin>
<groupId>com.pyx4me</groupId>
<artifactId>proguard-maven-plugin</artifactId>
<version>2.0.4</version>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.5</version>
</plugin>
<!-- as some classes are singletons we must run each test in separate JVM-->
<!-- <plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.2</version>
<configuration>
<forkMode>perTest</forkMode>
</configuration>
</plugin>-->
</plugins>
</pluginManagement>
</build>
<profiles>
<profile>
<!-- the standard profile runs instrumentation tests -->
<id>standard</id>
</profile>
<profile>
<!-- the release profile does sign, proguard, zipalign -->
<id>release</id>
<!-- via this activation the profile is automatically used when the release is done with the maven release
plugin -->
<activation>
<property>
<name>performRelease</name>
<value>true</value>
</property>
</activation>
</profile>
</profiles>
</project>