[New] Added new helper methods to Parameters
This commit is contained in:
parent
9566c89b2c
commit
185e7950e4
|
@ -69,6 +69,12 @@ public class BooleanParameter extends AbstractParameter<Boolean> {
|
||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setValue(Parameter<Boolean> parameter) {
|
||||||
|
assertNotReadonly();
|
||||||
|
this.value = parameter.getValue();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setValueFromString(String valueAsString) {
|
public void setValueFromString(String valueAsString) {
|
||||||
setValue(parseFromString(valueAsString));
|
setValue(parseFromString(valueAsString));
|
||||||
|
@ -85,11 +91,29 @@ public class BooleanParameter extends AbstractParameter<Boolean> {
|
||||||
this.value = false;
|
this.value = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return true if the value is false
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean isEmpty() {
|
public boolean isEmpty() {
|
||||||
return !this.value;
|
return !this.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isEqualTo(Parameter<Boolean> otherValue) {
|
||||||
|
return this.value.equals(otherValue.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isEqualTo(Boolean otherValue) {
|
||||||
|
return this.value.equals(otherValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void flip() {
|
||||||
|
assertNotReadonly();
|
||||||
|
this.value = !this.value;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getType() {
|
public String getType() {
|
||||||
return StrolchValueType.BOOLEAN.getType();
|
return StrolchValueType.BOOLEAN.getType();
|
||||||
|
@ -125,5 +149,4 @@ public class BooleanParameter extends AbstractParameter<Boolean> {
|
||||||
DBC.PRE.assertEquals("Not same Parameter types!", this.getType(), o.getType());
|
DBC.PRE.assertEquals("Not same Parameter types!", this.getType(), o.getType());
|
||||||
return this.getValue().compareTo(((BooleanParameter) o).getValue());
|
return this.getValue().compareTo(((BooleanParameter) o).getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,9 @@
|
||||||
*/
|
*/
|
||||||
package li.strolch.model.parameter;
|
package li.strolch.model.parameter;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.time.ZoneId;
|
||||||
|
import java.time.ZonedDateTime;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
import li.strolch.model.StrolchValueType;
|
import li.strolch.model.StrolchValueType;
|
||||||
|
@ -72,6 +75,12 @@ public class DateParameter extends AbstractParameter<Date> {
|
||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setValue(Parameter<Date> parameter) {
|
||||||
|
assertNotReadonly();
|
||||||
|
this.value = parameter.getValue();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setValueFromString(String valueAsString) {
|
public void setValueFromString(String valueAsString) {
|
||||||
setValue(parseFromString(valueAsString));
|
setValue(parseFromString(valueAsString));
|
||||||
|
@ -93,6 +102,40 @@ public class DateParameter extends AbstractParameter<Date> {
|
||||||
return this.value.equals(EMPTY_VALUE);
|
return this.value.equals(EMPTY_VALUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isEqualTo(Parameter<Date> otherValue) {
|
||||||
|
return this.value.equals(otherValue.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isEqualTo(Date otherValue) {
|
||||||
|
return this.value.equals(otherValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isEqualTo(LocalDateTime otherValue) {
|
||||||
|
return this.value.equals(Date.from(otherValue.atZone(ZoneId.systemDefault()).toInstant()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isEqualTo(ZonedDateTime otherValue) {
|
||||||
|
return this.value.equals(Date.from(otherValue.toInstant()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public ZonedDateTime toZonedDateTime() {
|
||||||
|
return ZonedDateTime.ofInstant(this.value.toInstant(), ZoneId.systemDefault());
|
||||||
|
}
|
||||||
|
|
||||||
|
public LocalDateTime toLocalDateTime() {
|
||||||
|
return LocalDateTime.ofInstant(this.value.toInstant(), ZoneId.systemDefault());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setValueFromLocalDateTime(LocalDateTime localDateTime) {
|
||||||
|
this.value = Date.from(localDateTime.atZone(ZoneId.systemDefault()).toInstant());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setValueFromZonedDateTime(ZonedDateTime zonedDateTime) {
|
||||||
|
this.value = Date.from(zonedDateTime.toInstant());
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getType() {
|
public String getType() {
|
||||||
return StrolchValueType.DATE.getType();
|
return StrolchValueType.DATE.getType();
|
||||||
|
@ -128,5 +171,4 @@ public class DateParameter extends AbstractParameter<Date> {
|
||||||
DBC.PRE.assertEquals("Not same Parameter types!", this.getType(), o.getType());
|
DBC.PRE.assertEquals("Not same Parameter types!", this.getType(), o.getType());
|
||||||
return this.getValue().compareTo(((DateParameter) o).getValue());
|
return this.getValue().compareTo(((DateParameter) o).getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -69,6 +69,12 @@ public class DurationParameter extends AbstractParameter<Long> {
|
||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setValue(Parameter<Long> parameter) {
|
||||||
|
assertNotReadonly();
|
||||||
|
this.value = parameter.getValue();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the value to 0
|
* Sets the value to 0
|
||||||
*
|
*
|
||||||
|
@ -85,6 +91,16 @@ public class DurationParameter extends AbstractParameter<Long> {
|
||||||
return this.value == 0L;
|
return this.value == 0L;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isEqualTo(Parameter<Long> otherValue) {
|
||||||
|
return this.value.equals(otherValue.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isEqualTo(Long otherValue) {
|
||||||
|
return this.value.equals(otherValue);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setValueFromString(String valueAsString) {
|
public void setValueFromString(String valueAsString) {
|
||||||
setValue(parseFromString(valueAsString));
|
setValue(parseFromString(valueAsString));
|
||||||
|
|
|
@ -91,6 +91,12 @@ public class FloatListParameter extends AbstractParameter<List<Double>> implemen
|
||||||
this.value = new ArrayList<>(value);
|
this.value = new ArrayList<>(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setValue(Parameter<List<Double>> parameter) {
|
||||||
|
assertNotReadonly();
|
||||||
|
this.value = new ArrayList<>(parameter.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setValueFromString(String valueAsString) {
|
public void setValueFromString(String valueAsString) {
|
||||||
setValue(parseFromString(valueAsString));
|
setValue(parseFromString(valueAsString));
|
||||||
|
@ -102,6 +108,17 @@ public class FloatListParameter extends AbstractParameter<List<Double>> implemen
|
||||||
this.value.add(value);
|
this.value.add(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean addValueIfNotContains(Double value) {
|
||||||
|
assertNotReadonly();
|
||||||
|
|
||||||
|
if (this.value.contains(value))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
this.value.add(value);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean removeValue(Double value) {
|
public boolean removeValue(Double value) {
|
||||||
assertNotReadonly();
|
assertNotReadonly();
|
||||||
|
@ -119,6 +136,16 @@ public class FloatListParameter extends AbstractParameter<List<Double>> implemen
|
||||||
return this.value.isEmpty();
|
return this.value.isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isEqualTo(Parameter<List<Double>> otherValue) {
|
||||||
|
return this.value.equals(otherValue.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isEqualTo(List<Double> otherValue) {
|
||||||
|
return this.value.equals(otherValue);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int size() {
|
public int size() {
|
||||||
return this.value.size();
|
return this.value.size();
|
||||||
|
@ -129,6 +156,11 @@ public class FloatListParameter extends AbstractParameter<List<Double>> implemen
|
||||||
return this.value.contains(value);
|
return this.value.contains(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean containsAll(List<Double> values) {
|
||||||
|
return this.value.containsAll(values);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getType() {
|
public String getType() {
|
||||||
return StrolchValueType.FLOAT_LIST.getType();
|
return StrolchValueType.FLOAT_LIST.getType();
|
||||||
|
@ -178,5 +210,4 @@ public class FloatListParameter extends AbstractParameter<List<Double>> implemen
|
||||||
DBC.PRE.assertEquals("Not same Parameter types!", this.getType(), o.getType());
|
DBC.PRE.assertEquals("Not same Parameter types!", this.getType(), o.getType());
|
||||||
return Integer.compare(this.getValue().size(), ((FloatListParameter) o).getValue().size());
|
return Integer.compare(this.getValue().size(), ((FloatListParameter) o).getValue().size());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,6 +70,12 @@ public class FloatParameter extends AbstractParameter<Double> {
|
||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setValue(Parameter<Double> parameter) {
|
||||||
|
assertNotReadonly();
|
||||||
|
this.value = parameter.getValue();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the value to 0
|
* Sets the value to 0
|
||||||
*
|
*
|
||||||
|
@ -81,11 +87,54 @@ public class FloatParameter extends AbstractParameter<Double> {
|
||||||
this.value = 0.0D;
|
this.value = 0.0D;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return true if the value == 0.0D
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean isEmpty() {
|
public boolean isEmpty() {
|
||||||
return this.value == 0.0D;
|
return this.value == 0.0D;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isEqualTo(Parameter<Double> otherValue) {
|
||||||
|
return this.value.equals(otherValue.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isEqualTo(Double otherValue) {
|
||||||
|
return this.value.equals(otherValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void add(double value) {
|
||||||
|
assertNotReadonly();
|
||||||
|
this.value += value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void subtract(double value) {
|
||||||
|
assertNotReadonly();
|
||||||
|
this.value -= value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void multiply(double value) {
|
||||||
|
assertNotReadonly();
|
||||||
|
this.value *= value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void divide(double value) {
|
||||||
|
assertNotReadonly();
|
||||||
|
this.value /= value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void increment() {
|
||||||
|
assertNotReadonly();
|
||||||
|
this.value++;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void decrement() {
|
||||||
|
assertNotReadonly();
|
||||||
|
this.value--;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setValueFromString(String valueAsString) {
|
public void setValueFromString(String valueAsString) {
|
||||||
setValue(parseFromString(valueAsString));
|
setValue(parseFromString(valueAsString));
|
||||||
|
@ -126,5 +175,4 @@ public class FloatParameter extends AbstractParameter<Double> {
|
||||||
DBC.PRE.assertEquals("Not same Parameter types!", this.getType(), o.getType());
|
DBC.PRE.assertEquals("Not same Parameter types!", this.getType(), o.getType());
|
||||||
return this.getValue().compareTo(((FloatParameter) o).getValue());
|
return this.getValue().compareTo(((FloatParameter) o).getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -91,6 +91,12 @@ public class IntegerListParameter extends AbstractParameter<List<Integer>> imple
|
||||||
this.value = new ArrayList<>(value);
|
this.value = new ArrayList<>(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setValue(Parameter<List<Integer>> parameter) {
|
||||||
|
assertNotReadonly();
|
||||||
|
this.value = new ArrayList<>(parameter.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setValueFromString(String valueAsString) {
|
public void setValueFromString(String valueAsString) {
|
||||||
setValue(parseFromString(valueAsString));
|
setValue(parseFromString(valueAsString));
|
||||||
|
@ -102,6 +108,17 @@ public class IntegerListParameter extends AbstractParameter<List<Integer>> imple
|
||||||
this.value.add(value);
|
this.value.add(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean addValueIfNotContains(Integer value) {
|
||||||
|
assertNotReadonly();
|
||||||
|
|
||||||
|
if (this.value.contains(value))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
this.value.add(value);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean removeValue(Integer value) {
|
public boolean removeValue(Integer value) {
|
||||||
assertNotReadonly();
|
assertNotReadonly();
|
||||||
|
@ -119,6 +136,16 @@ public class IntegerListParameter extends AbstractParameter<List<Integer>> imple
|
||||||
return this.value.isEmpty();
|
return this.value.isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isEqualTo(Parameter<List<Integer>> otherValue) {
|
||||||
|
return this.value.equals(otherValue.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isEqualTo(List<Integer> otherValue) {
|
||||||
|
return this.value.equals(otherValue);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int size() {
|
public int size() {
|
||||||
return this.value.size();
|
return this.value.size();
|
||||||
|
@ -129,6 +156,11 @@ public class IntegerListParameter extends AbstractParameter<List<Integer>> imple
|
||||||
return this.value.contains(value);
|
return this.value.contains(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean containsAll(List<Integer> values) {
|
||||||
|
return this.value.containsAll(values);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getType() {
|
public String getType() {
|
||||||
return StrolchValueType.INTEGER_LIST.getType();
|
return StrolchValueType.INTEGER_LIST.getType();
|
||||||
|
|
|
@ -78,6 +78,12 @@ public class IntegerParameter extends AbstractParameter<Integer> {
|
||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setValue(Parameter<Integer> parameter) {
|
||||||
|
assertNotReadonly();
|
||||||
|
this.value = parameter.getValue();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the value to 0
|
* Sets the value to 0
|
||||||
*
|
*
|
||||||
|
@ -89,11 +95,54 @@ public class IntegerParameter extends AbstractParameter<Integer> {
|
||||||
this.value = 0;
|
this.value = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return true if the value == 0
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean isEmpty() {
|
public boolean isEmpty() {
|
||||||
return this.value == 0;
|
return this.value == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isEqualTo(Parameter<Integer> otherValue) {
|
||||||
|
return this.value.equals(otherValue.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isEqualTo(Integer otherValue) {
|
||||||
|
return this.value.equals(otherValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void add(int value) {
|
||||||
|
assertNotReadonly();
|
||||||
|
this.value += value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void subtract(int value) {
|
||||||
|
assertNotReadonly();
|
||||||
|
this.value -= value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void multiply(int value) {
|
||||||
|
assertNotReadonly();
|
||||||
|
this.value *= value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void divide(int value) {
|
||||||
|
assertNotReadonly();
|
||||||
|
this.value /= value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void increment() {
|
||||||
|
assertNotReadonly();
|
||||||
|
this.value++;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void decrement() {
|
||||||
|
assertNotReadonly();
|
||||||
|
this.value--;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setValueFromString(String valueAsString) {
|
public void setValueFromString(String valueAsString) {
|
||||||
setValue(parseFromString(valueAsString));
|
setValue(parseFromString(valueAsString));
|
||||||
|
@ -124,5 +173,4 @@ public class IntegerParameter extends AbstractParameter<Integer> {
|
||||||
DBC.PRE.assertEquals("Not same Parameter types!", this.getType(), o.getType());
|
DBC.PRE.assertEquals("Not same Parameter types!", this.getType(), o.getType());
|
||||||
return this.getValue().compareTo(((IntegerParameter) o).getValue());
|
return this.getValue().compareTo(((IntegerParameter) o).getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,6 +35,14 @@ public interface ListParameter<E> extends Parameter<List<E>> {
|
||||||
*/
|
*/
|
||||||
public void addValue(E value);
|
public void addValue(E value);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a single value to the {@link List} of values if the current list does not already contain the value
|
||||||
|
*
|
||||||
|
* @param value
|
||||||
|
* the value to add
|
||||||
|
*/
|
||||||
|
public boolean addValueIfNotContains(E value);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes a single value from the {@link List} of values
|
* Removes a single value from the {@link List} of values
|
||||||
*
|
*
|
||||||
|
@ -73,4 +81,14 @@ public interface ListParameter<E> extends Parameter<List<E>> {
|
||||||
* @return true if the list of values contains the given element, false if not
|
* @return true if the list of values contains the given element, false if not
|
||||||
*/
|
*/
|
||||||
public boolean contains(E value);
|
public boolean contains(E value);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true if the list of values contains all of the given elements, false if not
|
||||||
|
*
|
||||||
|
* @param values
|
||||||
|
* the values to check if they are contained in the list of values
|
||||||
|
*
|
||||||
|
* @return true if the list of values contains all of the given elements, false if not
|
||||||
|
*/
|
||||||
|
public boolean containsAll(List<E> values);
|
||||||
}
|
}
|
||||||
|
|
|
@ -91,6 +91,12 @@ public class LongListParameter extends AbstractParameter<List<Long>> implements
|
||||||
this.value = new ArrayList<>(value);
|
this.value = new ArrayList<>(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setValue(Parameter<List<Long>> parameter) {
|
||||||
|
assertNotReadonly();
|
||||||
|
this.value = new ArrayList<>(parameter.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setValueFromString(String valueAsString) {
|
public void setValueFromString(String valueAsString) {
|
||||||
setValue(parseFromString(valueAsString));
|
setValue(parseFromString(valueAsString));
|
||||||
|
@ -102,6 +108,17 @@ public class LongListParameter extends AbstractParameter<List<Long>> implements
|
||||||
this.value.add(value);
|
this.value.add(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean addValueIfNotContains(Long value) {
|
||||||
|
assertNotReadonly();
|
||||||
|
|
||||||
|
if (this.value.contains(value))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
this.value.add(value);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean removeValue(Long value) {
|
public boolean removeValue(Long value) {
|
||||||
assertNotReadonly();
|
assertNotReadonly();
|
||||||
|
@ -119,6 +136,16 @@ public class LongListParameter extends AbstractParameter<List<Long>> implements
|
||||||
return this.value.isEmpty();
|
return this.value.isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isEqualTo(Parameter<List<Long>> otherValue) {
|
||||||
|
return this.value.equals(otherValue.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isEqualTo(List<Long> otherValue) {
|
||||||
|
return this.value.equals(otherValue);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int size() {
|
public int size() {
|
||||||
return this.value.size();
|
return this.value.size();
|
||||||
|
@ -129,6 +156,11 @@ public class LongListParameter extends AbstractParameter<List<Long>> implements
|
||||||
return this.value.contains(value);
|
return this.value.contains(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean containsAll(List<Long> values) {
|
||||||
|
return this.value.containsAll(values);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getType() {
|
public String getType() {
|
||||||
return StrolchValueType.LONG_LIST.getType();
|
return StrolchValueType.LONG_LIST.getType();
|
||||||
|
|
|
@ -68,8 +68,14 @@ public class LongParameter extends AbstractParameter<Long> {
|
||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setValue(Parameter<Long> parameter) {
|
||||||
|
assertNotReadonly();
|
||||||
|
this.value = parameter.getValue();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the value to 0
|
* Sets the value to 0L
|
||||||
*
|
*
|
||||||
* @see Parameter#clear()
|
* @see Parameter#clear()
|
||||||
*/
|
*/
|
||||||
|
@ -79,11 +85,54 @@ public class LongParameter extends AbstractParameter<Long> {
|
||||||
this.value = 0L;
|
this.value = 0L;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return true if the value == 0L
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean isEmpty() {
|
public boolean isEmpty() {
|
||||||
return this.value == 0L;
|
return this.value == 0L;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isEqualTo(Parameter<Long> otherValue) {
|
||||||
|
return this.value.equals(otherValue.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isEqualTo(Long otherValue) {
|
||||||
|
return this.value.equals(otherValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void add(long value) {
|
||||||
|
assertNotReadonly();
|
||||||
|
this.value += value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void subtract(long value) {
|
||||||
|
assertNotReadonly();
|
||||||
|
this.value -= value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void multiply(long value) {
|
||||||
|
assertNotReadonly();
|
||||||
|
this.value *= value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void divide(long value) {
|
||||||
|
assertNotReadonly();
|
||||||
|
this.value /= value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void increment() {
|
||||||
|
assertNotReadonly();
|
||||||
|
this.value++;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void decrement() {
|
||||||
|
assertNotReadonly();
|
||||||
|
this.value--;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setValueFromString(String valueAsString) {
|
public void setValueFromString(String valueAsString) {
|
||||||
setValue(parseFromString(valueAsString));
|
setValue(parseFromString(valueAsString));
|
||||||
|
|
|
@ -48,24 +48,52 @@ public interface Parameter<T> extends StrolchElement, Comparable<Parameter<?>> {
|
||||||
public <U extends T> U getValue();
|
public <U extends T> U getValue();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* the value of the parameter
|
* set the value of the parameter
|
||||||
*
|
*
|
||||||
* @param value
|
* @param value
|
||||||
* the new value
|
* the new value
|
||||||
*/
|
*/
|
||||||
public void setValue(T value);
|
public void setValue(T value);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* set the value of the parameter from another value, i.e. copying the value
|
||||||
|
*
|
||||||
|
* @param parameter
|
||||||
|
* the parameter from which to copy the new value
|
||||||
|
*/
|
||||||
|
public void setValue(Parameter<T> parameter);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clears the value, dependent on the concrete class
|
* Clears the value, dependent on the concrete class
|
||||||
*/
|
*/
|
||||||
public void clear();
|
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
|
* @return true if the value is empty, i.e. if the value is the same as the value which would be set if {@link
|
||||||
* {@link #clear()} was called
|
* #clear()} was called
|
||||||
*/
|
*/
|
||||||
public boolean isEmpty();
|
public boolean isEmpty();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true if the given parameter's value is equal to the current value
|
||||||
|
*
|
||||||
|
* @param otherValue
|
||||||
|
* the value to check on equality
|
||||||
|
*
|
||||||
|
* @return true if the given parameter's value is equal to the current value
|
||||||
|
*/
|
||||||
|
public boolean isEqualTo(Parameter<T> otherValue);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true if the given value is equal to the current value
|
||||||
|
*
|
||||||
|
* @param otherValue
|
||||||
|
* the value to check on equality
|
||||||
|
*
|
||||||
|
* @return true if the given value is equal to the current value
|
||||||
|
*/
|
||||||
|
public boolean isEqualTo(T otherValue);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* get the hidden attribute
|
* get the hidden attribute
|
||||||
*
|
*
|
||||||
|
|
|
@ -91,6 +91,12 @@ public class StringListParameter extends AbstractParameter<List<String>> impleme
|
||||||
this.value = new ArrayList<>(value);
|
this.value = new ArrayList<>(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setValue(Parameter<List<String>> parameter) {
|
||||||
|
assertNotReadonly();
|
||||||
|
this.value = new ArrayList<>(parameter.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setValueFromString(String valueAsString) {
|
public void setValueFromString(String valueAsString) {
|
||||||
setValue(parseFromString(valueAsString));
|
setValue(parseFromString(valueAsString));
|
||||||
|
@ -102,6 +108,17 @@ public class StringListParameter extends AbstractParameter<List<String>> impleme
|
||||||
this.value.add(value);
|
this.value.add(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean addValueIfNotContains(String value) {
|
||||||
|
assertNotReadonly();
|
||||||
|
|
||||||
|
if (this.value.contains(value))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
this.value.add(value);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean removeValue(String value) {
|
public boolean removeValue(String value) {
|
||||||
assertNotReadonly();
|
assertNotReadonly();
|
||||||
|
@ -119,6 +136,16 @@ public class StringListParameter extends AbstractParameter<List<String>> impleme
|
||||||
return this.value.isEmpty();
|
return this.value.isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isEqualTo(Parameter<List<String>> otherValue) {
|
||||||
|
return this.value.equals(otherValue.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isEqualTo(List<String> otherValue) {
|
||||||
|
return this.value.equals(otherValue);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int size() {
|
public int size() {
|
||||||
return this.value.size();
|
return this.value.size();
|
||||||
|
@ -129,6 +156,11 @@ public class StringListParameter extends AbstractParameter<List<String>> impleme
|
||||||
return this.value.contains(value);
|
return this.value.contains(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean containsAll(List<String> values) {
|
||||||
|
return this.value.containsAll(values);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getType() {
|
public String getType() {
|
||||||
return StrolchValueType.STRING_LIST.getType();
|
return StrolchValueType.STRING_LIST.getType();
|
||||||
|
|
|
@ -78,6 +78,12 @@ public class StringParameter extends AbstractParameter<String> {
|
||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setValue(Parameter<String> parameter) {
|
||||||
|
assertNotReadonly();
|
||||||
|
this.value = parameter.getValue();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the value to the empty string
|
* Sets the value to the empty string
|
||||||
*
|
*
|
||||||
|
@ -92,10 +98,21 @@ public class StringParameter extends AbstractParameter<String> {
|
||||||
/**
|
/**
|
||||||
* @return true if the string is empty
|
* @return true if the string is empty
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public boolean isEmpty() {
|
public boolean isEmpty() {
|
||||||
return this.value.isEmpty();
|
return this.value.isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isEqualTo(Parameter<String> otherValue) {
|
||||||
|
return this.value.equals(otherValue.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isEqualTo(String otherValue) {
|
||||||
|
return this.value.equals(otherValue);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setValueFromString(String valueAsString) {
|
public void setValueFromString(String valueAsString) {
|
||||||
setValue(valueAsString);
|
setValue(valueAsString);
|
||||||
|
@ -122,5 +139,4 @@ public class StringParameter extends AbstractParameter<String> {
|
||||||
DBC.PRE.assertEquals("Not same Parameter types!", this.getType(), o.getType());
|
DBC.PRE.assertEquals("Not same Parameter types!", this.getType(), o.getType());
|
||||||
return this.getValue().compareToIgnoreCase(((StringParameter) o).getValue());
|
return this.getValue().compareToIgnoreCase(((StringParameter) o).getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,316 @@
|
||||||
|
package li.strolch.model.parameter;
|
||||||
|
|
||||||
|
import static java.util.Arrays.asList;
|
||||||
|
import static java.util.Collections.emptyList;
|
||||||
|
import static li.strolch.model.ModelGenerator.*;
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.time.ZonedDateTime;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
import li.strolch.model.ModelGenerator;
|
||||||
|
import li.strolch.model.Resource;
|
||||||
|
import li.strolch.utils.iso8601.ISO8601FormatFactory;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class ParameterTest {
|
||||||
|
|
||||||
|
private Resource resource;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void before() {
|
||||||
|
this.resource = ModelGenerator.createResource("test", "Test", "Test");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testStringParam() {
|
||||||
|
|
||||||
|
StringParameter other = new StringParameter("other", "other", "ab");
|
||||||
|
StringParameter p = resource.getParameter(BAG_ID, PARAM_STRING_ID, true);
|
||||||
|
|
||||||
|
assertEquals("Strolch", p.getValue());
|
||||||
|
|
||||||
|
p.clear();
|
||||||
|
assertTrue(p.isEmpty());
|
||||||
|
assertEquals("", p.getValue());
|
||||||
|
|
||||||
|
p.setValue(other);
|
||||||
|
assertTrue(p.isEqualTo(other.getValue()));
|
||||||
|
assertTrue(p.isEqualTo(other));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testIntegerParam() {
|
||||||
|
|
||||||
|
IntegerParameter other = new IntegerParameter("other", "other", 42);
|
||||||
|
IntegerParameter p = resource.getParameter(BAG_ID, PARAM_INTEGER_ID, true);
|
||||||
|
|
||||||
|
assertEquals(Integer.valueOf(77), p.getValue());
|
||||||
|
|
||||||
|
p.clear();
|
||||||
|
assertTrue(p.isEmpty());
|
||||||
|
assertEquals(Integer.valueOf(0), p.getValue());
|
||||||
|
|
||||||
|
p.setValue(other);
|
||||||
|
assertTrue(p.isEqualTo(other.getValue()));
|
||||||
|
assertTrue(p.isEqualTo(other));
|
||||||
|
|
||||||
|
p.add(2);
|
||||||
|
assertEquals(Integer.valueOf(44), p.getValue());
|
||||||
|
p.subtract(1);
|
||||||
|
assertEquals(Integer.valueOf(43), p.getValue());
|
||||||
|
p.multiply(2);
|
||||||
|
assertEquals(Integer.valueOf(86), p.getValue());
|
||||||
|
p.divide(2);
|
||||||
|
assertEquals(Integer.valueOf(43), p.getValue());
|
||||||
|
p.increment();
|
||||||
|
assertEquals(Integer.valueOf(44), p.getValue());
|
||||||
|
p.decrement();
|
||||||
|
assertEquals(Integer.valueOf(43), p.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testLongParam() {
|
||||||
|
|
||||||
|
LongParameter other = new LongParameter("other", "other", 4242424242424242L);
|
||||||
|
LongParameter p = resource.getParameter(BAG_ID, PARAM_LONG_ID, true);
|
||||||
|
|
||||||
|
assertEquals(Long.valueOf(4453234566L), p.getValue());
|
||||||
|
|
||||||
|
p.clear();
|
||||||
|
assertTrue(p.isEmpty());
|
||||||
|
assertEquals(Long.valueOf(0L), p.getValue());
|
||||||
|
|
||||||
|
p.setValue(other);
|
||||||
|
assertTrue(p.isEqualTo(other.getValue()));
|
||||||
|
assertTrue(p.isEqualTo(other));
|
||||||
|
|
||||||
|
p.add(2);
|
||||||
|
assertEquals(Long.valueOf(4242424242424244L), p.getValue());
|
||||||
|
p.subtract(1);
|
||||||
|
assertEquals(Long.valueOf(4242424242424243L), p.getValue());
|
||||||
|
p.multiply(2);
|
||||||
|
assertEquals(Long.valueOf(8484848484848486L), p.getValue());
|
||||||
|
p.divide(2);
|
||||||
|
assertEquals(Long.valueOf(4242424242424243L), p.getValue());
|
||||||
|
p.increment();
|
||||||
|
assertEquals(Long.valueOf(4242424242424244L), p.getValue());
|
||||||
|
p.decrement();
|
||||||
|
assertEquals(Long.valueOf(4242424242424243L), p.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testBooleanParam() {
|
||||||
|
|
||||||
|
BooleanParameter other = new BooleanParameter("other", "other", true);
|
||||||
|
BooleanParameter p = resource.getParameter(BAG_ID, PARAM_BOOLEAN_ID, true);
|
||||||
|
|
||||||
|
assertEquals(Boolean.TRUE, p.getValue());
|
||||||
|
|
||||||
|
p.clear();
|
||||||
|
assertTrue(p.isEmpty());
|
||||||
|
assertEquals(Boolean.FALSE, p.getValue());
|
||||||
|
|
||||||
|
p.setValue(other);
|
||||||
|
assertTrue(p.isEqualTo(other.getValue()));
|
||||||
|
assertTrue(p.isEqualTo(other));
|
||||||
|
|
||||||
|
p.flip();
|
||||||
|
assertEquals(Boolean.FALSE, p.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testFloatParam() {
|
||||||
|
|
||||||
|
FloatParameter other = new FloatParameter("other", "other", 42.42D);
|
||||||
|
FloatParameter p = resource.getParameter(BAG_ID, PARAM_FLOAT_ID, true);
|
||||||
|
|
||||||
|
assertEquals(Double.valueOf(44.3), p.getValue());
|
||||||
|
|
||||||
|
p.clear();
|
||||||
|
assertTrue(p.isEmpty());
|
||||||
|
assertEquals(Double.valueOf(0.0D), p.getValue());
|
||||||
|
|
||||||
|
p.setValue(other);
|
||||||
|
assertTrue(p.isEqualTo(other.getValue()));
|
||||||
|
assertTrue(p.isEqualTo(other));
|
||||||
|
|
||||||
|
p.add(2.1D);
|
||||||
|
assertEquals(Double.valueOf(44.52D), p.getValue());
|
||||||
|
p.subtract(1.2D);
|
||||||
|
assertEquals(Double.valueOf(43.32D), p.getValue());
|
||||||
|
p.multiply(2.2D);
|
||||||
|
assertEquals(Double.valueOf(95.304D), p.getValue());
|
||||||
|
p.divide(2.4D);
|
||||||
|
assertEquals(Double.valueOf(39.71D), p.getValue());
|
||||||
|
p.increment();
|
||||||
|
assertEquals(Double.valueOf(40.71D), p.getValue());
|
||||||
|
p.decrement();
|
||||||
|
assertEquals(Double.valueOf(39.71D), p.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDateParam() {
|
||||||
|
|
||||||
|
DateParameter other = new DateParameter("other", "other", new Date(42L));
|
||||||
|
DateParameter p = resource.getParameter(BAG_ID, PARAM_DATE_ID, true);
|
||||||
|
|
||||||
|
assertEquals(new Date(1354295525628L), p.getValue());
|
||||||
|
|
||||||
|
p.clear();
|
||||||
|
assertTrue(p.isEmpty());
|
||||||
|
assertEquals(new Date(0L), p.getValue());
|
||||||
|
|
||||||
|
p.setValue(other);
|
||||||
|
assertTrue(p.isEqualTo(other.getValue()));
|
||||||
|
assertTrue(p.isEqualTo(other));
|
||||||
|
|
||||||
|
LocalDateTime now = LocalDateTime.now();
|
||||||
|
p.setValueFromLocalDateTime(now);
|
||||||
|
LocalDateTime localDateTime = p.toLocalDateTime();
|
||||||
|
assertEquals(now, localDateTime);
|
||||||
|
|
||||||
|
assertTrue(p.isEqualTo(now));
|
||||||
|
|
||||||
|
ZonedDateTime now1 = ZonedDateTime.now();
|
||||||
|
p.setValueFromZonedDateTime(now1);
|
||||||
|
ZonedDateTime zonedDateTime = p.toZonedDateTime();
|
||||||
|
assertEquals(now1, zonedDateTime);
|
||||||
|
assertTrue(p.isEqualTo(now1));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDurationParam() {
|
||||||
|
|
||||||
|
DurationParameter other = new DurationParameter("other", "other", 42L);
|
||||||
|
DurationParameter p = resource.getParameter(BAG_ID, PARAM_DURATION_ID, true);
|
||||||
|
|
||||||
|
assertEquals(Long.valueOf(ISO8601FormatFactory.getInstance().getDurationFormat().parse("P1D")), p.getValue());
|
||||||
|
|
||||||
|
p.clear();
|
||||||
|
assertTrue(p.isEmpty());
|
||||||
|
assertEquals(Long.valueOf(0L), p.getValue());
|
||||||
|
|
||||||
|
p.setValue(other);
|
||||||
|
assertTrue(p.isEqualTo(other.getValue()));
|
||||||
|
assertTrue(p.isEqualTo(other));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testStringListParam() {
|
||||||
|
|
||||||
|
StringListParameter other = new StringListParameter("other", "other", asList("ab", "ba"));
|
||||||
|
StringListParameter p = resource.getParameter(BAG_ID, PARAM_LIST_STRING_ID, true);
|
||||||
|
|
||||||
|
assertEquals(asList("Hello", "World"), p.getValue());
|
||||||
|
|
||||||
|
p.clear();
|
||||||
|
assertTrue(p.isEmpty());
|
||||||
|
assertEquals(emptyList(), p.getValue());
|
||||||
|
|
||||||
|
p.setValue(other);
|
||||||
|
assertTrue(p.isEqualTo(other.getValue()));
|
||||||
|
assertTrue(p.isEqualTo(other));
|
||||||
|
|
||||||
|
p.addValue("ca");
|
||||||
|
assertEquals(asList("ab", "ba", "ca"), p.getValue());
|
||||||
|
p.removeValue("ba");
|
||||||
|
assertEquals(asList("ab", "ca"), p.getValue());
|
||||||
|
assertTrue(p.contains("ab"));
|
||||||
|
assertFalse(p.contains("ba"));
|
||||||
|
|
||||||
|
p.addValueIfNotContains("ba");
|
||||||
|
p.addValueIfNotContains("ba");
|
||||||
|
assertTrue(p.containsAll(asList("ab", "ba", "ca")));
|
||||||
|
assertEquals(asList("ab", "ca", "ba"), p.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testIntegerListParam() {
|
||||||
|
|
||||||
|
IntegerListParameter other = new IntegerListParameter("other", "other", asList(42, 43));
|
||||||
|
IntegerListParameter p = resource.getParameter(BAG_ID, PARAM_LIST_INTEGER_ID, true);
|
||||||
|
|
||||||
|
assertEquals(asList(5, 10, 15), p.getValue());
|
||||||
|
|
||||||
|
p.clear();
|
||||||
|
assertTrue(p.isEmpty());
|
||||||
|
assertEquals(emptyList(), p.getValue());
|
||||||
|
|
||||||
|
p.setValue(other);
|
||||||
|
assertTrue(p.isEqualTo(other.getValue()));
|
||||||
|
assertTrue(p.isEqualTo(other));
|
||||||
|
|
||||||
|
p.addValue(44);
|
||||||
|
assertEquals(asList(42, 43, 44), p.getValue());
|
||||||
|
p.removeValue(43);
|
||||||
|
assertEquals(asList(42, 44), p.getValue());
|
||||||
|
assertTrue(p.contains(44));
|
||||||
|
assertFalse(p.contains(43));
|
||||||
|
|
||||||
|
p.addValueIfNotContains(43);
|
||||||
|
p.addValueIfNotContains(43);
|
||||||
|
assertTrue(p.containsAll(asList(42, 43, 44)));
|
||||||
|
assertEquals(asList(42, 44, 43), p.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testLongListParam() {
|
||||||
|
|
||||||
|
LongListParameter other = new LongListParameter("other", "other", asList(4242424242424242L, 4343434343434343L));
|
||||||
|
LongListParameter p = resource.getParameter(BAG_ID, PARAM_LIST_LONG_ID, true);
|
||||||
|
|
||||||
|
assertEquals(asList(7L, 12L, 17L), p.getValue());
|
||||||
|
|
||||||
|
p.clear();
|
||||||
|
assertTrue(p.isEmpty());
|
||||||
|
assertEquals(emptyList(), p.getValue());
|
||||||
|
|
||||||
|
p.setValue(other);
|
||||||
|
assertTrue(p.isEqualTo(other.getValue()));
|
||||||
|
assertTrue(p.isEqualTo(other));
|
||||||
|
|
||||||
|
p.addValue(5656565656565656L);
|
||||||
|
assertEquals(asList(4242424242424242L, 4343434343434343L, 5656565656565656L), p.getValue());
|
||||||
|
p.removeValue(4343434343434343L);
|
||||||
|
assertEquals(asList(4242424242424242L, 5656565656565656L), p.getValue());
|
||||||
|
assertTrue(p.contains(5656565656565656L));
|
||||||
|
assertFalse(p.contains(4343434343434343L));
|
||||||
|
|
||||||
|
p.addValueIfNotContains(4343434343434343L);
|
||||||
|
p.addValueIfNotContains(4343434343434343L);
|
||||||
|
assertTrue(p.containsAll(asList(4242424242424242L, 5656565656565656L, 4343434343434343L)));
|
||||||
|
assertEquals(asList(4242424242424242L, 5656565656565656L, 4343434343434343L), p.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testFloatListParam() {
|
||||||
|
|
||||||
|
FloatListParameter other = new FloatListParameter("other", "other", asList(42.42D, 43.43D));
|
||||||
|
FloatListParameter p = resource.getParameter(BAG_ID, PARAM_LIST_FLOAT_ID, true);
|
||||||
|
|
||||||
|
assertEquals(asList(6.0, 11.0, 16.0), p.getValue());
|
||||||
|
|
||||||
|
p.clear();
|
||||||
|
assertTrue(p.isEmpty());
|
||||||
|
assertEquals(emptyList(), p.getValue());
|
||||||
|
|
||||||
|
p.setValue(other);
|
||||||
|
assertTrue(p.isEqualTo(other.getValue()));
|
||||||
|
assertTrue(p.isEqualTo(other));
|
||||||
|
|
||||||
|
p.addValue(88.88D);
|
||||||
|
assertEquals(asList(42.42D, 43.43D, 88.88D), p.getValue());
|
||||||
|
p.removeValue(43.43D);
|
||||||
|
assertEquals(asList(42.42D, 88.88D), p.getValue());
|
||||||
|
assertTrue(p.contains(88.88D));
|
||||||
|
assertFalse(p.contains(43.43D));
|
||||||
|
|
||||||
|
p.addValueIfNotContains(43.43D);
|
||||||
|
p.addValueIfNotContains(43.43D);
|
||||||
|
assertTrue(p.containsAll(asList(42.42D, 88.88D, 43.43D)));
|
||||||
|
assertEquals(asList(42.42D, 88.88D, 43.43D), p.getValue());
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue