[Major] Updates to Parameter interface

This commit is contained in:
Robert von Burg 2017-05-10 12:23:35 +02:00
parent 43eb6c7298
commit 7ce6375288
14 changed files with 68 additions and 31 deletions

View File

@ -73,13 +73,18 @@ public class BooleanParameter extends AbstractParameter<Boolean> {
/** /**
* Sets the value to false * Sets the value to false
* *
* @see Parameter#clearValue() * @see Parameter#clear()
*/ */
@Override @Override
public void clearValue() { public void clear() {
this.value = false; this.value = false;
} }
@Override
public boolean isEmpty() {
return !this.value;
}
@Override @Override
public String getType() { public String getType() {
return StrolchValueType.BOOLEAN.getType(); return StrolchValueType.BOOLEAN.getType();

View File

@ -28,6 +28,7 @@ import li.strolch.utils.iso8601.ISO8601FormatFactory;
public class DateParameter extends AbstractParameter<Date> { public class DateParameter extends AbstractParameter<Date> {
private static final long serialVersionUID = 0L; private static final long serialVersionUID = 0L;
private static final Date EMPTY_VALUE = ISO8601FormatFactory.getInstance().getDateFormat().parse("-");
private Date value; private Date value;
@ -75,11 +76,16 @@ public class DateParameter extends AbstractParameter<Date> {
/** /**
* Sets the value to 1970-01-01 (unix time 0) * Sets the value to 1970-01-01 (unix time 0)
* *
* @see Parameter#clearValue() * @see Parameter#clear()
*/ */
@Override @Override
public void clearValue() { public void clear() {
this.value = ISO8601FormatFactory.getInstance().getDateFormat().parse("-"); this.value = EMPTY_VALUE;
}
@Override
public boolean isEmpty() {
return this.value.equals(EMPTY_VALUE);
} }
@Override @Override

View File

@ -68,13 +68,18 @@ public class DurationParameter extends AbstractParameter<Long> {
/** /**
* Sets the value to 0 * Sets the value to 0
* *
* @see Parameter#clearValue() * @see Parameter#clear()
*/ */
@Override @Override
public void clearValue() { public void clear() {
this.value = 0L; this.value = 0L;
} }
@Override
public boolean isEmpty() {
return this.value == 0L;
}
@Override @Override
public void setValueFromString(String valueAsString) { public void setValueFromString(String valueAsString) {
setValue(parseFromString(valueAsString)); setValue(parseFromString(valueAsString));

View File

@ -107,12 +107,12 @@ public class FloatListParameter extends AbstractParameter<List<Double>> implemen
} }
@Override @Override
public void clearValue() { public void clear() {
this.value.clear(); this.value.clear();
} }
@Override @Override
public boolean isValueEmpty() { public boolean isEmpty() {
return this.value.isEmpty(); return this.value.isEmpty();
} }

View File

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

View File

@ -107,12 +107,12 @@ public class IntegerListParameter extends AbstractParameter<List<Integer>> imple
} }
@Override @Override
public void clearValue() { public void clear() {
this.value.clear(); this.value.clear();
} }
@Override @Override
public boolean isValueEmpty() { public boolean isEmpty() {
return this.value.isEmpty(); return this.value.isEmpty();
} }

View File

@ -73,13 +73,18 @@ public class IntegerParameter extends AbstractParameter<Integer> {
/** /**
* Sets the value to 0 * Sets the value to 0
* *
* @see Parameter#clearValue() * @see Parameter#clear()
*/ */
@Override @Override
public void clearValue() { public void clear() {
this.value = 0; this.value = 0;
} }
@Override
public boolean isEmpty() {
return this.value == 0;
}
@Override @Override
public void setValueFromString(String valueAsString) { public void setValueFromString(String valueAsString) {
setValue(parseFromString(valueAsString)); setValue(parseFromString(valueAsString));

View File

@ -48,12 +48,12 @@ public interface ListParameter<E> extends Parameter<List<E>> {
/** /**
* Clears the list of values, i.e the list of values is empty after this call * Clears the list of values, i.e the list of values is empty after this call
*/ */
public void clearValue(); public void clear();
/** /**
* Returns true if the list of values is empty, false if not * Returns true if the list of values is empty, false if not
* *
* @returns true if the list of values is empty, false if not * @returns true if the list of values is empty, false if not
*/ */
public boolean isValueEmpty(); public boolean isEmpty();
} }

View File

@ -107,12 +107,12 @@ public class LongListParameter extends AbstractParameter<List<Long>> implements
} }
@Override @Override
public void clearValue() { public void clear() {
this.value.clear(); this.value.clear();
} }
@Override @Override
public boolean isValueEmpty() { public boolean isEmpty() {
return this.value.isEmpty(); return this.value.isEmpty();
} }

View File

@ -68,13 +68,18 @@ public class LongParameter extends AbstractParameter<Long> {
/** /**
* Sets the value to 0 * Sets the value to 0
* *
* @see Parameter#clearValue() * @see Parameter#clear()
*/ */
@Override @Override
public void clearValue() { public void clear() {
this.value = 0L; this.value = 0L;
} }
@Override
public boolean isEmpty() {
return this.value == 0L;
}
@Override @Override
public void setValueFromString(String valueAsString) { public void setValueFromString(String valueAsString) {
setValue(parseFromString(valueAsString)); setValue(parseFromString(valueAsString));

View File

@ -45,7 +45,7 @@ public interface Parameter<T> extends StrolchElement, Comparable<Parameter<?>> {
* *
* @return * @return
*/ */
public <U extends T> U getValue(); public <U extends T> U getValue();
/** /**
* the value of the parameter * the value of the parameter
@ -57,7 +57,13 @@ public interface Parameter<T> extends StrolchElement, Comparable<Parameter<?>> {
/** /**
* Clears the value, dependent on the concrete class * Clears the value, dependent on the concrete class
*/ */
public void clearValue(); public void clear();
/**
* @return true if the value is empty, i.e. if the value is the same as the value which would be set if
* {@link #clear()} was called
*/
public boolean isEmpty();
/** /**
* get the hidden attribute * get the hidden attribute

View File

@ -107,12 +107,12 @@ public class StringListParameter extends AbstractParameter<List<String>> impleme
} }
@Override @Override
public void clearValue() { public void clear() {
this.value.clear(); this.value.clear();
} }
@Override @Override
public boolean isValueEmpty() { public boolean isEmpty() {
return this.value.isEmpty(); return this.value.isEmpty();
} }

View File

@ -74,10 +74,10 @@ public class StringParameter extends AbstractParameter<String> {
/** /**
* Sets the value to the empty string * Sets the value to the empty string
* *
* @see Parameter#clearValue() * @see Parameter#clear()
*/ */
@Override @Override
public void clearValue() { public void clear() {
this.value = ""; this.value = "";
} }

View File

@ -482,7 +482,7 @@ public class ModelTest {
assertEquals("a, b", stringListP.getValueAsString()); assertEquals("a, b", stringListP.getValueAsString());
stringListP.setValueFromString("a,b"); stringListP.setValueFromString("a,b");
assertEquals("a, b", stringListP.getValueAsString()); assertEquals("a, b", stringListP.getValueAsString());
stringListP.clearValue(); stringListP.clear();
assertEquals("", stringListP.getValueAsString()); assertEquals("", stringListP.getValueAsString());
stringListP.addValue("a"); stringListP.addValue("a");
assertEquals("a", stringListP.getValueAsString()); assertEquals("a", stringListP.getValueAsString());
@ -499,7 +499,7 @@ public class ModelTest {
assertEquals("4, 45", intListP.getValueAsString()); assertEquals("4, 45", intListP.getValueAsString());
intListP.setValueFromString("4,45"); intListP.setValueFromString("4,45");
assertEquals("4, 45", intListP.getValueAsString()); assertEquals("4, 45", intListP.getValueAsString());
intListP.clearValue(); intListP.clear();
assertEquals("", intListP.getValueAsString()); assertEquals("", intListP.getValueAsString());
intListP.addValue(55); intListP.addValue(55);
assertEquals("55", intListP.getValueAsString()); assertEquals("55", intListP.getValueAsString());
@ -516,7 +516,7 @@ public class ModelTest {
assertEquals("4.2, 4.1", floatListP.getValueAsString()); assertEquals("4.2, 4.1", floatListP.getValueAsString());
floatListP.setValueFromString("4.2,4.1"); floatListP.setValueFromString("4.2,4.1");
assertEquals("4.2, 4.1", floatListP.getValueAsString()); assertEquals("4.2, 4.1", floatListP.getValueAsString());
floatListP.clearValue(); floatListP.clear();
assertEquals("", floatListP.getValueAsString()); assertEquals("", floatListP.getValueAsString());
floatListP.addValue(55.5); floatListP.addValue(55.5);
assertEquals("55.5", floatListP.getValueAsString()); assertEquals("55.5", floatListP.getValueAsString());
@ -533,7 +533,7 @@ public class ModelTest {
assertEquals("4, 4", longListP.getValueAsString()); assertEquals("4, 4", longListP.getValueAsString());
longListP.setValueFromString("4,4"); longListP.setValueFromString("4,4");
assertEquals("4, 4", longListP.getValueAsString()); assertEquals("4, 4", longListP.getValueAsString());
longListP.clearValue(); longListP.clear();
assertEquals("", longListP.getValueAsString()); assertEquals("", longListP.getValueAsString());
longListP.addValue(55L); longListP.addValue(55L);
assertEquals("55", longListP.getValueAsString()); assertEquals("55", longListP.getValueAsString());