prefs
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* 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.common;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.solovyev.common.utils.*;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* User: serso
|
||||
* Date: 9/21/11
|
||||
* Time: 12:02 AM
|
||||
*/
|
||||
public abstract class AbstractIntervalMapper<T> implements Mapper<Interval<T>> {
|
||||
|
||||
@Override
|
||||
public String formatValue(@Nullable Interval<T> interval) throws IllegalArgumentException {
|
||||
if (interval != null) {
|
||||
return CollectionsUtils.formatValue(Arrays.asList(interval.getLeftBorder(), interval.getRightBorder()), ";", getFormatter());
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected abstract Formatter<T> getFormatter();
|
||||
|
||||
@Override
|
||||
public Interval<T> parseValue(@Nullable String s) throws IllegalArgumentException {
|
||||
final List<T> list = CollectionsUtils.split(s, ";", getParser());
|
||||
|
||||
assert list.size() == 2;
|
||||
return new IntervalImpl<T>(list.get(0), list.get(1));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected abstract Parser<T> getParser();
|
||||
}
|
37
src/main/java/org/solovyev/common/FloatIntervalMapper.java
Normal file
37
src/main/java/org/solovyev/common/FloatIntervalMapper.java
Normal file
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* 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.common;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.solovyev.common.math.ValueOfFormatter;
|
||||
import org.solovyev.common.utils.Formatter;
|
||||
import org.solovyev.common.utils.Parser;
|
||||
|
||||
/**
|
||||
* User: serso
|
||||
* Date: 9/21/11
|
||||
* Time: 12:06 AM
|
||||
*/
|
||||
public class FloatIntervalMapper extends AbstractIntervalMapper<Float> {
|
||||
@NotNull
|
||||
@Override
|
||||
protected Formatter<Float> getFormatter() {
|
||||
return new ValueOfFormatter<Float>();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected Parser<Float> getParser() {
|
||||
return new Parser<Float>() {
|
||||
@Override
|
||||
public Float parseValue(@Nullable String s) throws IllegalArgumentException {
|
||||
return Float.valueOf(s);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
35
src/main/java/org/solovyev/common/IntegerIntervalMapper.java
Normal file
35
src/main/java/org/solovyev/common/IntegerIntervalMapper.java
Normal file
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* 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.common;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.solovyev.common.math.ValueOfFormatter;
|
||||
import org.solovyev.common.utils.*;
|
||||
|
||||
/**
|
||||
* User: serso
|
||||
* Date: 9/20/11
|
||||
* Time: 11:56 PM
|
||||
*/
|
||||
public class IntegerIntervalMapper extends AbstractIntervalMapper<Integer> {
|
||||
|
||||
@NotNull
|
||||
protected Formatter<Integer> getFormatter() {
|
||||
return new ValueOfFormatter<Integer>();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected Parser<Integer> getParser() {
|
||||
return new Parser<Integer>() {
|
||||
@Override
|
||||
public Integer parseValue(@Nullable String s) throws IllegalArgumentException {
|
||||
return Integer.valueOf(s);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
23
src/main/java/org/solovyev/common/math/ValueOfFormatter.java
Normal file
23
src/main/java/org/solovyev/common/math/ValueOfFormatter.java
Normal file
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* 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.common.math;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.solovyev.common.utils.Formatter;
|
||||
|
||||
/**
|
||||
* User: serso
|
||||
* Date: 9/20/11
|
||||
* Time: 10:52 PM
|
||||
*/
|
||||
public class ValueOfFormatter<T> implements Formatter<T>{
|
||||
|
||||
@Override
|
||||
public String formatValue(@Nullable T t) throws IllegalArgumentException {
|
||||
return String.valueOf(t);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user