version update

This commit is contained in:
Sergey Solovyev
2013-02-02 20:21:05 +04:00
parent cafa6b01ed
commit 8d84e24ca9
76 changed files with 282 additions and 874 deletions

View File

@@ -10,7 +10,7 @@ import jscl.NumeralBase;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.solovyev.android.calculator.math.MathType;
import org.solovyev.common.text.StringUtils;
import org.solovyev.common.text.Strings;
/**
* User: serso
@@ -48,7 +48,7 @@ public abstract class AbstractNumberBuilder {
}
private boolean spaceBefore(@NotNull MathType.Result mathTypeResult) {
return numberBuilder == null && StringUtils.isEmpty(mathTypeResult.getMatch().trim());
return numberBuilder == null && Strings.isEmpty(mathTypeResult.getMatch().trim());
}
private boolean numeralBaseInTheStart(@NotNull MathType mathType) {

View File

@@ -4,7 +4,7 @@ import jscl.math.Generic;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.solovyev.android.calculator.jscl.JsclOperation;
import org.solovyev.common.text.StringUtils;
import org.solovyev.common.text.Strings;
/**
* User: serso
@@ -89,7 +89,7 @@ public class CalculatorDisplayViewStateImpl implements CalculatorDisplayViewStat
@NotNull
@Override
public String getText() {
return StringUtils.getNotEmpty(isValid() ? stringResult : errorMessage, "");
return Strings.getNotEmpty(isValid() ? stringResult : errorMessage, "");
}
@Override

View File

@@ -5,7 +5,7 @@ import org.jetbrains.annotations.Nullable;
import org.solovyev.android.calculator.history.CalculatorHistoryState;
import org.solovyev.android.calculator.history.EditorHistoryState;
import org.solovyev.common.gui.CursorControl;
import org.solovyev.common.text.StringUtils;
import org.solovyev.common.text.Strings;
/**
* User: Solovyev_S
@@ -93,7 +93,7 @@ public class CalculatorEditorImpl implements CalculatorEditor {
case use_history_state:
final CalculatorHistoryState calculatorHistoryState = (CalculatorHistoryState)data;
final EditorHistoryState editorState = calculatorHistoryState.getEditorState();
this.setText(StringUtils.getNotEmpty(editorState.getText(), ""), editorState.getCursorPosition());
this.setText(Strings.getNotEmpty(editorState.getText(), ""), editorState.getCursorPosition());
break;
}
}

View File

@@ -4,7 +4,7 @@ import jscl.AngleUnit;
import jscl.text.msg.Messages;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.solovyev.common.collections.CollectionsUtils;
import org.solovyev.common.collections.Collections;
import java.util.List;
@@ -40,7 +40,7 @@ public enum CalculatorFixableError implements FixableError {
private final List<String> messageCodes;
CalculatorFixableError(@Nullable String... messageCodes) {
this.messageCodes = CollectionsUtils.asList(messageCodes);
this.messageCodes = Collections.asList(messageCodes);
}
@Nullable

View File

@@ -18,7 +18,7 @@ import org.solovyev.android.calculator.model.Functions;
import org.solovyev.android.calculator.model.MathEntityBuilder;
import org.solovyev.common.JBuilder;
import org.solovyev.common.math.MathRegistry;
import org.solovyev.common.text.StringUtils;
import org.solovyev.common.text.Strings;
import java.util.Arrays;
import java.util.HashMap;
@@ -101,7 +101,7 @@ public class CalculatorFunctionsMathRegistry extends AbstractCalculatorMathRegis
result = ((CustomFunction) function).getDescription();
}
if (StringUtils.isEmpty(result) ) {
if (Strings.isEmpty(result) ) {
result = super.getDescription(functionName);
}

View File

@@ -21,9 +21,9 @@ import org.solovyev.common.msg.ListMessageRegistry;
import org.solovyev.common.msg.Message;
import org.solovyev.common.msg.MessageRegistry;
import org.solovyev.common.msg.MessageType;
import org.solovyev.common.text.StringUtils;
import org.solovyev.math.units.ConversionException;
import org.solovyev.math.units.ConversionUtils;
import org.solovyev.common.text.Strings;
import org.solovyev.common.units.ConversionException;
import org.solovyev.common.units.Conversions;
import java.util.ArrayList;
import java.util.List;
@@ -209,7 +209,7 @@ public class CalculatorImpl implements Calculator, CalculatorEventListener {
expression = expression.trim();
if (StringUtils.isEmpty(expression)) {
if (Strings.isEmpty(expression)) {
fireCalculatorEvent(newCalculationEventData(operation, expression, sequenceId), CalculatorEventType.calculation_result, CalculatorOutputImpl.newEmptyOutput(operation));
} else {
preparedExpression = prepareExpression(expression);
@@ -367,7 +367,7 @@ public class CalculatorImpl implements Calculator, CalculatorEventListener {
if (from != to) {
String fromString = generic.toString();
if (!StringUtils.isEmpty(fromString)) {
if (!Strings.isEmpty(fromString)) {
try {
fromString = ToJsclTextProcessor.getInstance().process(fromString).getExpression();
} catch (CalculatorParseException e) {
@@ -375,7 +375,8 @@ public class CalculatorImpl implements Calculator, CalculatorEventListener {
}
}
result = ConversionUtils.doConversion(CalculatorNumeralBase.getConverter(), fromString, CalculatorNumeralBase.valueOf(from), CalculatorNumeralBase.valueOf(to));
result = Conversions.doConversion(CalculatorNumeralBase.getConverter(), fromString, CalculatorNumeralBase.valueOf(from), CalculatorNumeralBase.valueOf(to));
} else {
result = generic.toString();
}
@@ -531,7 +532,7 @@ public class CalculatorImpl implements Calculator, CalculatorEventListener {
final CalculatorDisplayViewState newState = displayChangeEventData.getNewValue();
if (newState.isValid()) {
final String result = newState.getStringResult();
if ( !StringUtils.isEmpty(result) ) {
if ( !Strings.isEmpty(result) ) {
final CalculatorMathRegistry<IConstant> varsRegistry = Locator.getInstance().getEngine().getVarsRegistry();
final IConstant ansVar = varsRegistry.get(CalculatorVarsRegistry.ANS);

View File

@@ -3,7 +3,7 @@ package org.solovyev.android.calculator;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.solovyev.android.calculator.math.MathType;
import org.solovyev.common.text.StringUtils;
import org.solovyev.common.text.Strings;
/**
* User: serso
@@ -22,7 +22,7 @@ public class CalculatorKeyboardImpl implements CalculatorKeyboard {
@Override
public void buttonPressed(@Nullable final String text) {
if (!StringUtils.isEmpty(text)) {
if (!Strings.isEmpty(text)) {
assert text != null;
// process special buttons
@@ -105,7 +105,7 @@ public class CalculatorKeyboardImpl implements CalculatorKeyboard {
final CalculatorDisplayViewState displayViewState = Locator.getInstance().getDisplay().getViewState();
if (displayViewState.isValid()) {
final CharSequence text = displayViewState.getText();
if (!StringUtils.isEmpty(text)) {
if (!Strings.isEmpty(text)) {
Locator.getInstance().getClipboard().setText(text);
Locator.getInstance().getNotifier().showMessage(CalculatorMessage.newInfoMessage(CalculatorMessages.result_copied));
}

View File

@@ -5,10 +5,9 @@ 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 org.solovyev.common.collections.Collections;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
@@ -75,9 +74,9 @@ public enum FunctionCategory {
@NotNull
public static List<FunctionCategory> getCategoriesByTabOrder() {
final List<FunctionCategory> result = CollectionsUtils.asList(FunctionCategory.values());
final List<FunctionCategory> result = Collections.asList(FunctionCategory.values());
Collections.sort(result, new Comparator<FunctionCategory>() {
java.util.Collections.sort(result, new Comparator<FunctionCategory>() {
@Override
public int compare(FunctionCategory category, FunctionCategory category1) {
return category.tabOrder - category1.tabOrder;

View File

@@ -2,9 +2,11 @@ package org.solovyev.android.calculator;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.solovyev.common.utils.ListListenersContainer;
import org.solovyev.common.listeners.JListeners;
import org.solovyev.common.listeners.Listeners;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
/**
@@ -18,7 +20,7 @@ public class ListCalculatorEventContainer implements CalculatorEventContainer {
private static final String TAG = "CalculatorEventData";
@NotNull
private final ListListenersContainer<CalculatorEventListener> listeners = new ListListenersContainer<CalculatorEventListener>();
private final JListeners<CalculatorEventListener> listeners = Listeners.newWeakRefListeners();
@Override
public void addCalculatorEventListener(@NotNull CalculatorEventListener calculatorEventListener) {
@@ -37,7 +39,7 @@ public class ListCalculatorEventContainer implements CalculatorEventContainer {
@Override
public void fireCalculatorEvents(@NotNull List<CalculatorEvent> calculatorEvents) {
final List<CalculatorEventListener> listeners = this.listeners.getListeners();
final Collection<CalculatorEventListener> listeners = this.listeners.getListeners();
//final CalculatorLogger logger = Locator.getInstance().getLogger();

View File

@@ -2,9 +2,8 @@ package org.solovyev.android.calculator;
import jscl.math.operator.*;
import org.jetbrains.annotations.NotNull;
import org.solovyev.common.collections.CollectionsUtils;
import org.solovyev.common.collections.Collections;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
@@ -61,9 +60,9 @@ public enum OperatorCategory {
@NotNull
public static List<OperatorCategory> getCategoriesByTabOrder() {
final List<OperatorCategory> result = CollectionsUtils.asList(OperatorCategory.values());
final List<OperatorCategory> result = Collections.asList(OperatorCategory.values());
Collections.sort(result, new Comparator<OperatorCategory>() {
java.util.Collections.sort(result, new Comparator<OperatorCategory>() {
@Override
public int compare(OperatorCategory category, OperatorCategory category1) {
return category.tabOrder - category1.tabOrder;

View File

@@ -11,9 +11,9 @@ import jscl.math.function.IConstant;
import org.jetbrains.annotations.NotNull;
import org.solovyev.android.calculator.math.MathType;
import org.solovyev.android.calculator.text.TextProcessor;
import org.solovyev.common.StartsWithFinder;
import org.solovyev.common.collections.CollectionsUtils;
import org.solovyev.common.collections.Collections;
import org.solovyev.common.msg.MessageType;
import org.solovyev.common.search.StartsWithFinder;
import java.util.ArrayList;
import java.util.List;
@@ -47,7 +47,7 @@ public class ToJsclTextProcessor implements TextProcessor<PreparedExpression, St
@NotNull
private static StringBuilder processExpression(@NotNull String s) throws CalculatorParseException {
final StartsWithFinder startsWithFinder = new StartsWithFinder(s, 0);
final StartsWithFinder startsWithFinder = StartsWithFinder.newInstance(s);
final StringBuilder result = new StringBuilder();
MathType.Result mathTypeResult = null;
@@ -75,7 +75,7 @@ public class ToJsclTextProcessor implements TextProcessor<PreparedExpression, St
if (mathTypeBefore != null &&
(mathTypeBefore.getMathType() == MathType.function || mathTypeBefore.getMathType() == MathType.operator) &&
CollectionsUtils.find(MathType.openGroupSymbols, startsWithFinder) != null) {
Collections.find(MathType.openGroupSymbols, startsWithFinder) != null) {
final String functionName = mathTypeBefore.getMatch();
final Function function = Locator.getInstance().getEngine().getFunctionsRegistry().get(functionName);
if ( function == null || function.getMinParameters() > 0 ) {
@@ -96,18 +96,18 @@ public class ToJsclTextProcessor implements TextProcessor<PreparedExpression, St
depth++;
}
final StartsWithFinder startsWithFinder = new StartsWithFinder(s, 0);
final StartsWithFinder startsWithFinder = StartsWithFinder.newInstance(s);
final StringBuilder result = new StringBuilder();
for (int i = 0; i < s.length(); i++) {
startsWithFinder.setI(i);
int offset = 0;
String functionName = CollectionsUtils.find(MathType.function.getTokens(), startsWithFinder);
String functionName = Collections.find(MathType.function.getTokens(), startsWithFinder);
if (functionName == null) {
String operatorName = CollectionsUtils.find(MathType.operator.getTokens(), startsWithFinder);
String operatorName = Collections.find(MathType.operator.getTokens(), startsWithFinder);
if (operatorName == null) {
String varName = CollectionsUtils.find(Locator.getInstance().getEngine().getVarsRegistry().getNames(), startsWithFinder);
String varName = Collections.find(Locator.getInstance().getEngine().getVarsRegistry().getNames(), startsWithFinder);
if (varName != null) {
final IConstant var = Locator.getInstance().getEngine().getVarsRegistry().get(varName);
if (var != null) {

View File

@@ -2,9 +2,8 @@ package org.solovyev.android.calculator;
import jscl.math.function.IConstant;
import org.jetbrains.annotations.NotNull;
import org.solovyev.common.collections.CollectionsUtils;
import org.solovyev.common.collections.Collections;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
@@ -39,9 +38,9 @@ public enum VarCategory {
@NotNull
public static List<VarCategory> getCategoriesByTabOrder() {
final List<VarCategory> result = CollectionsUtils.asList(VarCategory.values());
final List<VarCategory> result = Collections.asList(VarCategory.values());
Collections.sort(result, new Comparator<VarCategory>() {
java.util.Collections.sort(result, new Comparator<VarCategory>() {
@Override
public int compare(VarCategory category, VarCategory category1) {
return category.tabOrder - category1.tabOrder;

View File

@@ -15,7 +15,7 @@ import org.solovyev.android.calculator.CalculatorDisplay;
import org.solovyev.android.calculator.CalculatorDisplayViewState;
import org.solovyev.android.calculator.CalculatorDisplayViewStateImpl;
import org.solovyev.android.calculator.jscl.JsclOperation;
import org.solovyev.common.text.StringUtils;
import org.solovyev.common.text.Strings;
/**
* User: serso
@@ -65,9 +65,9 @@ public class CalculatorDisplayHistoryState implements Cloneable {
public void setValuesFromHistory(@NotNull CalculatorDisplay display) {
if ( this.isValid() ) {
display.setViewState(CalculatorDisplayViewStateImpl.newValidState(this.getJsclOperation(), this.getGenericResult(), StringUtils.getNotEmpty(this.getEditorState().getText(), ""), this.getEditorState().getCursorPosition()));
display.setViewState(CalculatorDisplayViewStateImpl.newValidState(this.getJsclOperation(), this.getGenericResult(), Strings.getNotEmpty(this.getEditorState().getText(), ""), this.getEditorState().getCursorPosition()));
} else {
display.setViewState(CalculatorDisplayViewStateImpl.newErrorState(this.getJsclOperation(), StringUtils.getNotEmpty(this.getErrorMessage(), "")));
display.setViewState(CalculatorDisplayViewStateImpl.newErrorState(this.getJsclOperation(), Strings.getNotEmpty(this.getErrorMessage(), "")));
}
}

View File

@@ -3,7 +3,6 @@ package org.solovyev.android.calculator.history;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.solovyev.android.calculator.*;
import org.solovyev.common.collections.CollectionsUtils;
import org.solovyev.common.history.HistoryAction;
import org.solovyev.common.history.HistoryHelper;
import org.solovyev.common.history.SimpleHistoryHelper;
@@ -26,7 +25,7 @@ public class CalculatorHistoryImpl implements CalculatorHistory {
private final AtomicInteger counter = new AtomicInteger(0);
@NotNull
private final HistoryHelper<CalculatorHistoryState> history = new SimpleHistoryHelper<CalculatorHistoryState>();
private final HistoryHelper<CalculatorHistoryState> history = SimpleHistoryHelper.newInstance();
@NotNull
private final List<CalculatorHistoryState> savedHistory = new ArrayList<CalculatorHistoryState>();
@@ -123,7 +122,7 @@ public class CalculatorHistoryImpl implements CalculatorHistory {
final List<CalculatorHistoryState> result = new LinkedList<CalculatorHistoryState>();
CalculatorHistoryState laterState = null;
for (CalculatorHistoryState state : CollectionsUtils.reversed(states)) {
for (CalculatorHistoryState state : org.solovyev.common.collections.Collections.reversed(states)) {
if ( laterState != null ) {
final String laterEditorText = laterState.getEditorState().getText();
final String editorText = state.getEditorState().getText();

View File

@@ -12,7 +12,7 @@ import org.simpleframework.xml.Root;
import org.solovyev.android.calculator.CalculatorDisplayViewState;
import org.solovyev.android.calculator.CalculatorEditor;
import org.solovyev.android.calculator.CalculatorEditorViewState;
import org.solovyev.common.text.StringUtils;
import org.solovyev.common.text.Strings;
@Root
public class EditorHistoryState implements Cloneable{
@@ -49,7 +49,7 @@ public class EditorHistoryState implements Cloneable{
}
public void setValuesFromHistory(@NotNull CalculatorEditor editor) {
editor.setText(StringUtils.getNotEmpty(this.getText(), ""));
editor.setText(Strings.getNotEmpty(this.getText(), ""));
editor.setSelection(this.getCursorPosition());
}

View File

@@ -13,7 +13,7 @@ import org.jetbrains.annotations.Nullable;
import org.solovyev.android.calculator.CalculatorParseException;
import org.solovyev.android.calculator.Locator;
import org.solovyev.common.JPredicate;
import org.solovyev.common.collections.CollectionsUtils;
import org.solovyev.common.collections.Collections;
import java.util.*;
@@ -190,7 +190,7 @@ public enum MathType {
boolean needMultiplicationSignAfter,
@NotNull MathGroupType groupType,
@NotNull String... tokens) {
this(priority, needMultiplicationSignBefore, needMultiplicationSignAfter, groupType, CollectionsUtils.asList(tokens));
this(priority, needMultiplicationSignBefore, needMultiplicationSignAfter, groupType, Collections.asList(tokens));
}
MathType(@NotNull Integer priority,
@@ -202,7 +202,7 @@ public enum MathType {
this.needMultiplicationSignBefore = needMultiplicationSignBefore;
this.needMultiplicationSignAfter = needMultiplicationSignAfter;
this.groupType = groupType;
this.tokens = Collections.unmodifiableList(tokens);
this.tokens = java.util.Collections.unmodifiableList(tokens);
}
@NotNull
@@ -219,7 +219,7 @@ public enum MathType {
final MathType mathType = getType(s.toString(), result).getMathType();
if (CollectionsUtils.contains(mathType, digit, dot, grouping_separator, power_10)) {
if (Collections.contains(mathType, digit, dot, grouping_separator, power_10)) {
// continue
} else if (mathType == close_group_symbol) {
numberOfOpenGroups++;
@@ -246,7 +246,7 @@ public enum MathType {
if (i > 0) {
final EndsWithFinder endsWithFinder = new EndsWithFinder(s);
endsWithFinder.setI(i + 1);
if (!CollectionsUtils.contains(function.getTokens(), FilterType.included, endsWithFinder)) {
if (!Collections.contains(function.getTokens(), FilterType.included, endsWithFinder)) {
MathType type = getType(s.toString(), i).getMathType();
if (type != constant) {
return true;
@@ -350,7 +350,7 @@ public enum MathType {
final StartsWithFinder startsWithFinder = new StartsWithFinder(text, i);
for (MathType mathType : getMathTypesByPriority()) {
final String s = CollectionsUtils.find(mathType.getTokens(), startsWithFinder);
final String s = Collections.find(mathType.getTokens(), startsWithFinder);
if (s != null) {
if ( s.length() == 1 ) {
if (hexMode || JsclMathEngine.getInstance().getNumeralBase() == NumeralBase.hex) {
@@ -373,14 +373,14 @@ public enum MathType {
@NotNull
private static List<MathType> getMathTypesByPriority() {
if (mathTypesByPriority == null) {
final List<MathType> result = CollectionsUtils.asList(MathType.values());
final List<MathType> result = Collections.asList(MathType.values());
Collections.sort(result, new Comparator<MathType>() {
@Override
public int compare(MathType l, MathType r) {
return l.priority.compareTo(r.priority);
}
});
java.util.Collections.sort(result, new Comparator<MathType>() {
@Override
public int compare(MathType l, MathType r) {
return l.priority.compareTo(r.priority);
}
});
mathTypesByPriority = result;
}

View File

@@ -19,7 +19,7 @@ import org.solovyev.android.calculator.MathPersistenceEntity;
import org.solovyev.common.math.MathEntity;
import org.solovyev.common.msg.Message;
import org.solovyev.common.msg.MessageType;
import org.solovyev.common.text.StringUtils;
import org.solovyev.common.text.Strings;
import java.io.Serializable;
import java.util.ArrayList;
@@ -109,7 +109,7 @@ public class AFunction implements IFunction, MathPersistenceEntity, Serializable
@NotNull IFunction source) {
target.name = source.getName();
target.content = source.getContent();
target.description = StringUtils.getNotEmpty(source.getDescription(), "");
target.description = Strings.getNotEmpty(source.getDescription(), "");
target.system = source.isSystem();
if (source.isIdDefined()) {
target.id = source.getId();
@@ -285,7 +285,7 @@ public class AFunction implements IFunction, MathPersistenceEntity, Serializable
throw new CreationException(e);
}
result.system = system;
result.description = StringUtils.getNotEmpty(description, "");
result.description = Strings.getNotEmpty(description, "");
result.parameterNames = new ArrayList<String>(parameterNames);
return result;

View File

@@ -17,7 +17,7 @@ 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;
import org.solovyev.common.text.Strings;
/**
* User: serso
@@ -226,7 +226,7 @@ public class Var implements IConstant, MathPersistenceEntity {
@Override
public boolean isDefined() {
return !StringUtils.isEmpty(value);
return !Strings.isEmpty(value);
}
@Override

View File

@@ -4,7 +4,7 @@ import jscl.math.Generic;
import jscl.math.function.Constant;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.solovyev.common.text.StringUtils;
import org.solovyev.common.text.Strings;
public class XyFunction implements FunctionEvaluator {
@@ -71,7 +71,7 @@ public class XyFunction implements FunctionEvaluator {
this.arity--;
}
this.id = this.expressionString + "_" + StringUtils.getNotEmpty(this.xVariableName, "") + "_" + StringUtils.getNotEmpty(this.yVariableName, "");
this.id = this.expressionString + "_" + Strings.getNotEmpty(this.xVariableName, "") + "_" + Strings.getNotEmpty(this.yVariableName, "");
}

View File

@@ -2,10 +2,10 @@ package org.solovyev.android.calculator.units;
import jscl.NumeralBase;
import org.jetbrains.annotations.NotNull;
import org.solovyev.math.units.Unit;
import org.solovyev.math.units.UnitConverter;
import org.solovyev.math.units.UnitImpl;
import org.solovyev.math.units.UnitType;
import org.solovyev.common.units.Unit;
import org.solovyev.common.units.UnitConverter;
import org.solovyev.common.units.UnitImpl;
import org.solovyev.common.units.UnitType;
import java.math.BigInteger;

View File

@@ -1,16 +0,0 @@
package org.solovyev.common;
import org.jetbrains.annotations.NotNull;
import java.util.concurrent.Executor;
import java.util.concurrent.TimeUnit;
/**
* User: serso
* Date: 12/1/12
* Time: 4:10 PM
*/
public interface DelayedExecutor extends Executor {
void execute(@NotNull Runnable command, long delay, @NotNull TimeUnit delayUnit);
}

View File

@@ -1,35 +0,0 @@
package org.solovyev.common;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.solovyev.common.text.CollectionTransformations;
import org.solovyev.common.text.Mapper;
import java.util.List;
public class ListMapper<T> implements Mapper<List<T>> {
@NotNull
private final Mapper<T> nestedMapper;
private ListMapper(@NotNull Mapper<T> nestedMapper) {
this.nestedMapper = nestedMapper;
}
@NotNull
private static <T> Mapper<List<T>> newInstance(@NotNull Mapper<T> nestedMapper) {
return new ListMapper<T>(nestedMapper);
}
@Nullable
@Override
public String formatValue(@Nullable List<T> value) throws IllegalArgumentException {
return CollectionTransformations.formatValue(value, ";", nestedMapper);
}
@Nullable
@Override
public List<T> parseValue(@Nullable String value) throws IllegalArgumentException {
return CollectionTransformations.split(value, ";", nestedMapper);
}
}

View File

@@ -1,77 +0,0 @@
package org.solovyev.common.utils;
import com.google.common.base.Predicate;
import com.google.common.collect.Iterables;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
/**
* User: Solovyev_S
* Date: 20.09.12
* Time: 16:43
*/
// todo serso: move to common
public class ListListenersContainer<T> {
@NotNull
private final List<WeakReference<T>> listeners = new ArrayList<WeakReference<T>>();
public void addListener(@NotNull final T listener) {
synchronized (listeners) {
boolean contains = Iterables.any(listeners, new WeakReferencePredicate<T>(listener));
if (!contains) {
listeners.add(new WeakReference<T>(listener));
}
}
}
public void removeListener(@NotNull T listener) {
synchronized (listeners) {
Iterables.removeIf(listeners, new WeakReferencePredicate<T>(listener));
}
}
@NotNull
public List<T> getListeners() {
final List<T> localListeners;
synchronized (listeners) {
localListeners = new ArrayList<T>(listeners.size());
// copy listeners and remove garbage collected references
for ( Iterator<WeakReference<T>> it = listeners.iterator(); it.hasNext(); ) {
final WeakReference<T> r = it.next();
final T t = r.get();
if ( t == null ) {
it.remove();
} else {
localListeners.add(t);
}
}
}
return localListeners;
}
private static class WeakReferencePredicate<T> implements Predicate<WeakReference<T>> {
@NotNull
private final T t;
public WeakReferencePredicate(T t) {
this.t = t;
}
@Override
public boolean apply(@Nullable WeakReference<T> r) {
final T t = r != null ? r.get() : null;
return this.t.equals(t);
}
}
}

View File

@@ -1,15 +0,0 @@
package org.solovyev.math.units;
/**
* User: Solovyev_S
* Date: 24.09.12
* Time: 16:01
*/
public final class ConversionException extends Exception {
public ConversionException() {
}
public ConversionException(Throwable throwable) {
super(throwable);
}
}

View File

@@ -1,38 +0,0 @@
package org.solovyev.math.units;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.solovyev.common.text.StringUtils;
/**
* User: Solovyev_S
* Date: 24.09.12
* Time: 16:01
*/
public class ConversionUtils {
@NotNull
public static String doConversion(@NotNull UnitConverter<String> converter,
@Nullable String from,
@NotNull UnitType<String> fromUnitType,
@NotNull UnitType<String> toUnitType) throws ConversionException {
final String result;
if (StringUtils.isEmpty(from)) {
result = "";
} else {
String to = null;
try {
if (converter.isSupported(fromUnitType, toUnitType)) {
to = converter.convert(UnitImpl.newInstance(from, fromUnitType), toUnitType).getValue();
}
} catch (RuntimeException e) {
throw new ConversionException(e);
}
result = to;
}
return result;
}
}

View File

@@ -1,17 +0,0 @@
package org.solovyev.math.units;
import org.jetbrains.annotations.NotNull;
/**
* User: serso
* Date: 4/21/12
* Time: 7:54 PM
*/
public interface Unit<V> {
@NotNull
V getValue();
@NotNull
UnitType<V> getUnitType();
}

View File

@@ -1,42 +0,0 @@
package org.solovyev.math.units;
import org.jetbrains.annotations.NotNull;
/**
* User: serso
* Date: 4/21/12
* Time: 7:53 PM
*/
public interface UnitConverter<T> {
boolean isSupported(@NotNull UnitType<?> from, @NotNull UnitType<T> to);
@NotNull
Unit<T> convert(@NotNull Unit<?> from, @NotNull UnitType<T> toType);
public static class Dummy implements UnitConverter<Object> {
@NotNull
private static final Dummy instance = new Dummy();
@NotNull
public static <T> UnitConverter<T> getInstance() {
return (UnitConverter<T>)instance;
}
private Dummy() {
}
@Override
public boolean isSupported(@NotNull UnitType<?> from, @NotNull UnitType<Object> to) {
return false;
}
@NotNull
@Override
public Unit<Object> convert(@NotNull Unit<?> from, @NotNull UnitType<Object> toType) {
throw new IllegalArgumentException();
}
}
}

View File

@@ -1,42 +0,0 @@
package org.solovyev.math.units;
import org.jetbrains.annotations.NotNull;
/**
* User: serso
* Date: 4/21/12
* Time: 8:01 PM
*/
public class UnitImpl<V> implements Unit<V> {
@NotNull
private V value;
@NotNull
private UnitType<V> unitType;
private UnitImpl() {
}
@NotNull
public static <V> Unit<V> newInstance(@NotNull V value, @NotNull UnitType<V> unitType) {
final UnitImpl<V> result = new UnitImpl<V>();
result.value = value;
result.unitType = unitType;
return result;
}
@NotNull
@Override
public V getValue() {
return this.value;
}
@NotNull
@Override
public UnitType<V> getUnitType() {
return unitType;
}
}

View File

@@ -1,16 +0,0 @@
package org.solovyev.math.units;
import org.jetbrains.annotations.NotNull;
/**
* User: serso
* Date: 4/21/12
* Time: 7:55 PM
*/
public interface UnitType<V> {
@NotNull
Class<V> getUnitValueClass();
boolean equals(@NotNull Object o);
}