registries

This commit is contained in:
Sergey Solovyev 2012-10-07 20:02:41 +04:00
parent 4134204e67
commit 52e6b4b79d
8 changed files with 162 additions and 126 deletions

View File

@ -22,7 +22,7 @@ import java.util.Map;
* Date: 11/17/11
* Time: 11:28 PM
*/
public class AndroidFunctionsMathRegistry extends AbstractCalculatorMathRegistry<Function, AFunction> {
public class CalculatorFunctionsMathRegistry extends AbstractCalculatorMathRegistry<Function, AFunction> {
@NotNull
private static final Map<String, String> substitutes = new HashMap<String, String>();
@ -33,7 +33,7 @@ public class AndroidFunctionsMathRegistry extends AbstractCalculatorMathRegistry
@NotNull
private static final String FUNCTION_DESCRIPTION_PREFIX = "c_fun_description_";
public AndroidFunctionsMathRegistry(@NotNull MathRegistry<Function> functionsRegistry,
public CalculatorFunctionsMathRegistry(@NotNull MathRegistry<Function> functionsRegistry,
@NotNull MathEntityDao<AFunction> mathEntityDao) {
super(functionsRegistry, FUNCTION_DESCRIPTION_PREFIX, mathEntityDao);
}

View File

@ -18,7 +18,7 @@ import java.util.*;
* Date: 11/17/11
* Time: 11:29 PM
*/
public class AndroidOperatorsMathRegistry extends AbstractCalculatorMathRegistry<Operator, MathPersistenceEntity> {
public class CalculatorOperatorsMathRegistry extends AbstractCalculatorMathRegistry<Operator, MathPersistenceEntity> {
@NotNull
private static final Map<String, String> substitutes = new HashMap<String, String>();
@ -34,7 +34,7 @@ public class AndroidOperatorsMathRegistry extends AbstractCalculatorMathRegistry
@NotNull
private static final String OPERATOR_DESCRIPTION_PREFIX = "c_op_description_";
public AndroidOperatorsMathRegistry(@NotNull MathRegistry<Operator> functionsRegistry,
public CalculatorOperatorsMathRegistry(@NotNull MathRegistry<Operator> functionsRegistry,
@NotNull MathEntityDao<MathPersistenceEntity> mathEntityDao) {
super(functionsRegistry, OPERATOR_DESCRIPTION_PREFIX, mathEntityDao);
}

View File

@ -14,6 +14,7 @@ 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.AndroidVarCategory;
import org.solovyev.android.calculator.model.VarCategory;
/**
@ -55,7 +56,13 @@ public class CalculatorVarsActivity extends SherlockFragmentActivity implements
}
activityHelper.addTab(this, fragmentType.createSubFragmentTag(category.name()), fragmentType.getFragmentClass(), fragmentParameters, category.getCaptionId(), R.id.main_layout);
final AndroidVarCategory androidVarCategory = AndroidVarCategory.valueOf(category);
if (androidVarCategory != null) {
activityHelper.addTab(this, fragmentType.createSubFragmentTag(category.name()), fragmentType.getFragmentClass(), fragmentParameters, androidVarCategory.getCaptionId(), R.id.main_layout);
} else {
activityHelper.logError("Unable to find android var category for " + category);
}
}
}

View File

@ -108,10 +108,10 @@ public class AndroidCalculatorEngine implements CalculatorEngine, SharedPreferen
final JsclMathEngine engine = JsclMathEngine.getInstance();
this.calculatorEngine = new CalculatorEngineImpl(engine,
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)),
new CalculatorVarsRegistry(engine.getConstantsRegistry(), new AndroidMathEntityDao<Var>(R.string.p_calc_vars, application, Vars.class)),
new CalculatorFunctionsMathRegistry(engine.getFunctionsRegistry(), new AndroidMathEntityDao<AFunction>(R.string.p_calc_functions, application, Functions.class)),
new CalculatorOperatorsMathRegistry(engine.getOperatorsRegistry(), new AndroidMathEntityDao<MathPersistenceEntity>(null, application, null)),
new CalculatorPostfixFunctionsRegistry(engine.getPostfixFunctionsRegistry(), new AndroidMathEntityDao<MathPersistenceEntity>(null, application, null)),
this.lock);
}

View File

@ -0,0 +1,37 @@
package org.solovyev.android.calculator.model;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.solovyev.android.calculator.R;
/**
* User: serso
* Date: 10/7/12
* Time: 7:56 PM
*/
public enum AndroidVarCategory {
system(R.string.c_var_system),
my(R.string.c_var_my);
private final int captionId;
AndroidVarCategory(int captionId) {
this.captionId = captionId;
}
public int getCaptionId() {
return captionId;
}
@Nullable
public static AndroidVarCategory valueOf(@NotNull VarCategory varCategory) {
for (AndroidVarCategory androidVarCategory : values()) {
if ( androidVarCategory.name().equals(varCategory.name()) ) {
return androidVarCategory;
}
}
return null;
}
}

View File

@ -20,7 +20,7 @@ import java.util.Map;
* Date: 11/19/11
* Time: 1:48 PM
*/
public class AndroidPostfixFunctionsRegistry extends AbstractCalculatorMathRegistry<Operator, MathPersistenceEntity> {
public class CalculatorPostfixFunctionsRegistry extends AbstractCalculatorMathRegistry<Operator, MathPersistenceEntity> {
@NotNull
private static final Map<String, String> substitutes = new HashMap<String, String>();
@ -34,7 +34,7 @@ public class AndroidPostfixFunctionsRegistry extends AbstractCalculatorMathRegis
@NotNull
private static final String POSTFIX_FUNCTION_DESCRIPTION_PREFIX = "c_pf_description_";
protected AndroidPostfixFunctionsRegistry(@NotNull MathRegistry<Operator> functionsRegistry,
protected CalculatorPostfixFunctionsRegistry(@NotNull MathRegistry<Operator> functionsRegistry,
@NotNull MathEntityDao<MathPersistenceEntity> mathEntityDao) {
super(functionsRegistry, POSTFIX_FUNCTION_DESCRIPTION_PREFIX, mathEntityDao);
}

View File

@ -22,7 +22,7 @@ import java.util.Map;
* Date: 9/29/11
* Time: 4:57 PM
*/
class AndroidVarsRegistryImpl extends AbstractCalculatorMathRegistry<IConstant, Var> {
class CalculatorVarsRegistry extends AbstractCalculatorMathRegistry<IConstant, Var> {
@NotNull
private static final Map<String, String> substitutes = new HashMap<String, String>();
@ -34,7 +34,7 @@ class AndroidVarsRegistryImpl extends AbstractCalculatorMathRegistry<IConstant,
substitutes.put("NaN", "nan");
}
protected AndroidVarsRegistryImpl(@NotNull MathRegistry<IConstant> mathRegistry,
protected CalculatorVarsRegistry(@NotNull MathRegistry<IConstant> mathRegistry,
@NotNull MathEntityDao<Var> mathEntityDao) {
super(mathRegistry, "c_var_description_", mathEntityDao);
}

View File

@ -2,7 +2,6 @@ package org.solovyev.android.calculator.model;
import jscl.math.function.IConstant;
import org.jetbrains.annotations.NotNull;
import org.solovyev.android.calculator.R;
import org.solovyev.common.collections.CollectionsUtils;
import java.util.Collections;
@ -16,33 +15,26 @@ import java.util.List;
*/
public enum VarCategory {
system(R.string.c_var_system, 100){
system(100){
@Override
boolean isInCategory(@NotNull IConstant var) {
return var.isSystem();
}
},
my(R.string.c_var_my, 0) {
my(0) {
@Override
boolean isInCategory(@NotNull IConstant var) {
return !var.isSystem();
}
};
private final int captionId;
private final int tabOrder;
VarCategory(int captionId, int tabOrder) {
this.captionId = captionId;
VarCategory(int tabOrder) {
this.tabOrder = tabOrder;
}
public int getCaptionId() {
return captionId;
}
abstract boolean isInCategory(@NotNull IConstant var);
@NotNull