[Major] Added Parameter.clearValue() and list parameters use , as sep

This commit is contained in:
Robert von Burg 2017-03-02 14:59:03 +01:00
parent fbc019e7fb
commit 62a441e038
14 changed files with 153 additions and 17 deletions

View File

@ -69,6 +69,16 @@ public class BooleanParameter extends AbstractParameter<Boolean> {
setValue(parseFromString(valueAsString));
}
/**
* Sets the value to false
*
* @see Parameter#clearValue()
*/
@Override
public void clearValue() {
this.value = false;
}
@Override
public String getType() {
return StrolchValueType.BOOLEAN.getType();

View File

@ -71,6 +71,16 @@ public class DateParameter extends AbstractParameter<Date> {
setValue(parseFromString(valueAsString));
}
/**
* Sets the value to 1970-01-01 (unix time 0)
*
* @see Parameter#clearValue()
*/
@Override
public void clearValue() {
this.value = ISO8601FormatFactory.getInstance().getDateFormat().parse("-");
}
@Override
public String getType() {
return StrolchValueType.DATE.getType();
@ -95,7 +105,7 @@ public class DateParameter extends AbstractParameter<Date> {
public static Date parseFromString(String valueS) {
return ISO8601FormatFactory.getInstance().getDateFormat().parse(valueS);
}
@Override
public int compareTo(Parameter<?> o) {
DBC.PRE.assertEquals("Not same Parameter types!", this.getType(), o.getType());

View File

@ -64,6 +64,16 @@ public class DurationParameter extends AbstractParameter<Long> {
this.value = value;
}
/**
* Sets the value to 0
*
* @see Parameter#clearValue()
*/
@Override
public void clearValue() {
this.value = 0L;
}
@Override
public void setValueFromString(String valueAsString) {
setValue(parseFromString(valueAsString));

View File

@ -67,7 +67,8 @@ public class FloatListParameter extends AbstractParameter<List<Double>> implemen
sb.append(iter.next());
if (iter.hasNext()) {
sb.append(VALUE_SEPARATOR);
sb.append(VALUE_SEPARATOR2);
sb.append(" ");
}
}
@ -140,7 +141,12 @@ public class FloatListParameter extends AbstractParameter<List<Double>> implemen
return Collections.emptyList();
}
String[] valueArr = value.split(VALUE_SEPARATOR);
String[] valueArr;
if (value.contains(VALUE_SEPARATOR1))
valueArr = value.split(VALUE_SEPARATOR1);
else
valueArr = value.split(VALUE_SEPARATOR2);
List<Double> values = new ArrayList<>();
for (String val : valueArr) {
values.add(Double.valueOf(val.trim()));

View File

@ -65,6 +65,16 @@ public class FloatParameter extends AbstractParameter<Double> {
this.value = value;
}
/**
* Sets the value to 0
*
* @see Parameter#clearValue()
*/
@Override
public void clearValue() {
this.value = 0.0D;
}
@Override
public void setValueFromString(String valueAsString) {
setValue(parseFromString(valueAsString));

View File

@ -67,7 +67,8 @@ public class IntegerListParameter extends AbstractParameter<List<Integer>> imple
sb.append(iter.next());
if (iter.hasNext()) {
sb.append(VALUE_SEPARATOR);
sb.append(VALUE_SEPARATOR2);
sb.append(" ");
}
}
@ -140,7 +141,12 @@ public class IntegerListParameter extends AbstractParameter<List<Integer>> imple
return Collections.emptyList();
}
String[] valueArr = value.split(VALUE_SEPARATOR);
String[] valueArr;
if (value.contains(VALUE_SEPARATOR1))
valueArr = value.split(VALUE_SEPARATOR1);
else
valueArr = value.split(VALUE_SEPARATOR2);
List<Integer> values = new ArrayList<>();
for (String val : valueArr) {
values.add(Integer.valueOf(val.trim()));

View File

@ -69,6 +69,16 @@ public class IntegerParameter extends AbstractParameter<Integer> {
this.value = value;
}
/**
* Sets the value to 0
*
* @see Parameter#clearValue()
*/
@Override
public void clearValue() {
this.value = 0;
}
@Override
public void setValueFromString(String valueAsString) {
setValue(parseFromString(valueAsString));

View File

@ -18,12 +18,14 @@ package li.strolch.model.parameter;
import java.util.List;
/**
* A {@link Parameter} which supports a list of elements.
*
* @author Robert von Burg <eitch@eitchnet.ch>
*
*/
public interface ListParameter<E> extends Parameter<List<E>> {
public static final String VALUE_SEPARATOR = ";"; //$NON-NLS-1$
public static final String VALUE_SEPARATOR1 = ";"; //$NON-NLS-1$
public static final String VALUE_SEPARATOR2 = ","; //$NON-NLS-1$
/**
* Adds a single value to the {@link List} of values
@ -44,7 +46,7 @@ public interface ListParameter<E> extends Parameter<List<E>> {
public boolean removeValue(E value);
/**
* Clears the list of values
* Clears the list of values, i.e the list of values is empty after this call
*/
public void clearValue();

View File

@ -67,7 +67,8 @@ public class LongListParameter extends AbstractParameter<List<Long>> implements
sb.append(iter.next());
if (iter.hasNext()) {
sb.append(VALUE_SEPARATOR);
sb.append(VALUE_SEPARATOR2);
sb.append(" ");
}
}
@ -140,7 +141,12 @@ public class LongListParameter extends AbstractParameter<List<Long>> implements
return Collections.emptyList();
}
String[] valueArr = value.split(VALUE_SEPARATOR);
String[] valueArr;
if (value.contains(VALUE_SEPARATOR1))
valueArr = value.split(VALUE_SEPARATOR1);
else
valueArr = value.split(VALUE_SEPARATOR2);
List<Long> values = new ArrayList<>();
for (String val : valueArr) {
values.add(Long.valueOf(val.trim()));

View File

@ -64,6 +64,16 @@ public class LongParameter extends AbstractParameter<Long> {
this.value = value;
}
/**
* Sets the value to 0
*
* @see Parameter#clearValue()
*/
@Override
public void clearValue() {
this.value = 0L;
}
@Override
public void setValueFromString(String valueAsString) {
setValue(parseFromString(valueAsString));
@ -93,7 +103,7 @@ public class LongParameter extends AbstractParameter<Long> {
public static Long parseFromString(String valueS) {
return Long.valueOf(valueS);
}
@Override
public int compareTo(Parameter<?> o) {
DBC.PRE.assertEquals("Not same Parameter types!", this.getType(), o.getType());

View File

@ -54,6 +54,11 @@ public interface Parameter<T> extends StrolchElement, Comparable<Parameter<?>> {
*/
public void setValue(T value);
/**
* Clears the value, dependent on the concrete class
*/
public void clearValue();
/**
* get the hidden attribute
*
@ -141,12 +146,12 @@ public interface Parameter<T> extends StrolchElement, Comparable<Parameter<?>> {
@Override
public boolean equals(Object obj);
@Override
public int compareTo(Parameter<?> o);
@Override
public Parameter<T> getClone();
public <U> U accept(ParameterVisitor visitor);
public <U> U accept(ParameterVisitor visitor);
}

View File

@ -67,7 +67,8 @@ public class StringListParameter extends AbstractParameter<List<String>> impleme
sb.append(iter.next());
if (iter.hasNext()) {
sb.append(VALUE_SEPARATOR);
sb.append(VALUE_SEPARATOR2);
sb.append(" ");
}
}
@ -140,7 +141,12 @@ public class StringListParameter extends AbstractParameter<List<String>> impleme
return Collections.emptyList();
}
String[] valueArr = value.split(VALUE_SEPARATOR);
String[] valueArr;
if (value.contains(VALUE_SEPARATOR1))
valueArr = value.split(VALUE_SEPARATOR1);
else
valueArr = value.split(VALUE_SEPARATOR2);
List<String> values = new ArrayList<>();
for (String val : valueArr) {
values.add(val.trim());

View File

@ -25,10 +25,9 @@ import li.strolch.utils.dbc.DBC;
*/
public class StringParameter extends AbstractParameter<String> {
public static final String UNDEFINED_VALUE = "-"; //$NON-NLS-1$
private static final long serialVersionUID = 0L;
private String value = UNDEFINED_VALUE;
private String value = "";
/**
* Empty constructor
@ -71,6 +70,16 @@ public class StringParameter extends AbstractParameter<String> {
this.value = value;
}
/**
* Sets the value to the empty string
*
* @see Parameter#clearValue()
*/
@Override
public void clearValue() {
this.value = "";
}
@Override
public void setValueFromString(String valueAsString) {
setValue(valueAsString);

View File

@ -421,6 +421,15 @@ public class ModelTest {
stringList.add("Hello");
stringList.add("World");
assertEquals(stringList, stringListP.getValue());
assertEquals("Hello, World", stringListP.getValueAsString());
stringListP.setValueFromString("a;b");
assertEquals("a, b", stringListP.getValueAsString());
stringListP.setValueFromString("a,b");
assertEquals("a, b", stringListP.getValueAsString());
stringListP.clearValue();
assertEquals("", stringListP.getValueAsString());
stringListP.addValue("a");
assertEquals("a", stringListP.getValueAsString());
IntegerListParameter intListP = bag.getParameter(PARAM_LIST_INTEGER_ID);
assertNotNull("IntegerList Param missing with id " + PARAM_LIST_INTEGER_ID, intListP);
@ -429,6 +438,15 @@ public class ModelTest {
intList.add(10);
intList.add(15);
assertEquals(intList, intListP.getValue());
assertEquals("5, 10, 15", intListP.getValueAsString());
intListP.setValueFromString("4;45");
assertEquals("4, 45", intListP.getValueAsString());
intListP.setValueFromString("4,45");
assertEquals("4, 45", intListP.getValueAsString());
intListP.clearValue();
assertEquals("", intListP.getValueAsString());
intListP.addValue(55);
assertEquals("55", intListP.getValueAsString());
FloatListParameter floatListP = bag.getParameter(PARAM_LIST_FLOAT_ID);
assertNotNull("FloatList Param missing with id " + PARAM_LIST_FLOAT_ID, floatListP);
@ -437,6 +455,15 @@ public class ModelTest {
floatList.add(11.0);
floatList.add(16.0);
assertEquals(floatList, floatListP.getValue());
assertEquals("6.0, 11.0, 16.0", floatListP.getValueAsString());
floatListP.setValueFromString("4.2;4.1");
assertEquals("4.2, 4.1", floatListP.getValueAsString());
floatListP.setValueFromString("4.2,4.1");
assertEquals("4.2, 4.1", floatListP.getValueAsString());
floatListP.clearValue();
assertEquals("", floatListP.getValueAsString());
floatListP.addValue(55.5);
assertEquals("55.5", floatListP.getValueAsString());
LongListParameter longListP = bag.getParameter(PARAM_LIST_LONG_ID);
assertNotNull("LongList Param missing with id " + PARAM_LIST_LONG_ID, longListP);
@ -445,6 +472,15 @@ public class ModelTest {
longList.add(12L);
longList.add(17L);
assertEquals(longList, longListP.getValue());
assertEquals("7, 12, 17", longListP.getValueAsString());
longListP.setValueFromString("4;4");
assertEquals("4, 4", longListP.getValueAsString());
longListP.setValueFromString("4,4");
assertEquals("4, 4", longListP.getValueAsString());
longListP.clearValue();
assertEquals("", longListP.getValueAsString());
longListP.addValue(55L);
assertEquals("55", longListP.getValueAsString());
}
/**