[Minor] Assert ListParameters do not get null values added

This commit is contained in:
Robert von Burg 2018-11-26 18:03:58 +01:00
parent cb633081eb
commit 74a5e140df
4 changed files with 59 additions and 21 deletions

View File

@ -46,13 +46,13 @@ public class FloatListParameter extends AbstractParameter<List<Double>> implemen
* the id * the id
* @param name * @param name
* the name * the name
* @param value * @param values
* the value * the values
*/ */
public FloatListParameter(String id, String name, List<Double> value) { public FloatListParameter(String id, String name, List<Double> values) {
super(id, name); super(id, name);
setValue(value); setValue(values);
} }
@Override @Override
@ -83,10 +83,13 @@ public class FloatListParameter extends AbstractParameter<List<Double>> implemen
} }
@Override @Override
public void setValue(List<Double> value) { public void setValue(List<Double> values) {
assertNotReadonly(); assertNotReadonly();
validateValue(value); validateValue(values);
this.value = new ArrayList<>(value); for (Double value : values) {
DBC.PRE.assertNotNull("null values not allowed!", value);
}
this.value = new ArrayList<>(values);
} }
@Override @Override
@ -103,19 +106,24 @@ public class FloatListParameter extends AbstractParameter<List<Double>> implemen
@Override @Override
public void addValue(Double value) { public void addValue(Double value) {
assertNotReadonly(); assertNotReadonly();
DBC.PRE.assertNotNull("null values not allowed!", value);
this.value.add(value); this.value.add(value);
} }
@Override @Override
public void addAllValues(List<Double> values) { public void addAllValues(List<Double> values) {
assertNotReadonly(); assertNotReadonly();
this.value.addAll(values); for (Double value : values) {
DBC.PRE.assertNotNull("null values not allowed!", value);
this.value.add(value);
}
} }
@Override @Override
public void addAllValuesIfNotContains(List<Double> values) { public void addAllValuesIfNotContains(List<Double> values) {
assertNotReadonly(); assertNotReadonly();
for (Double value : values) { for (Double value : values) {
DBC.PRE.assertNotNull("null values not allowed!", value);
if (!this.value.contains(value)) if (!this.value.contains(value))
this.value.add(value); this.value.add(value);
} }
@ -124,6 +132,7 @@ public class FloatListParameter extends AbstractParameter<List<Double>> implemen
@Override @Override
public boolean addValueIfNotContains(Double value) { public boolean addValueIfNotContains(Double value) {
assertNotReadonly(); assertNotReadonly();
DBC.PRE.assertNotNull("null values not allowed!", value);
if (this.value.contains(value)) if (this.value.contains(value))
return false; return false;

View File

@ -83,10 +83,13 @@ public class IntegerListParameter extends AbstractParameter<List<Integer>> imple
} }
@Override @Override
public void setValue(List<Integer> value) { public void setValue(List<Integer> values) {
assertNotReadonly(); assertNotReadonly();
validateValue(value); validateValue(values);
this.value = new ArrayList<>(value); for (Integer value : values) {
DBC.PRE.assertNotNull("null values not allowed!", value);
}
this.value = new ArrayList<>(values);
} }
@Override @Override
@ -103,19 +106,24 @@ public class IntegerListParameter extends AbstractParameter<List<Integer>> imple
@Override @Override
public void addValue(Integer value) { public void addValue(Integer value) {
assertNotReadonly(); assertNotReadonly();
DBC.PRE.assertNotNull("null values not allowed!", value);
this.value.add(value); this.value.add(value);
} }
@Override @Override
public void addAllValues(List<Integer> values) { public void addAllValues(List<Integer> values) {
assertNotReadonly(); assertNotReadonly();
this.value.addAll(values); for (Integer value : values) {
DBC.PRE.assertNotNull("null values not allowed!", value);
this.value.add(value);
}
} }
@Override @Override
public void addAllValuesIfNotContains(List<Integer> values) { public void addAllValuesIfNotContains(List<Integer> values) {
assertNotReadonly(); assertNotReadonly();
for (Integer value : values) { for (Integer value : values) {
DBC.PRE.assertNotNull("null values not allowed!", value);
if (!this.value.contains(value)) if (!this.value.contains(value))
this.value.add(value); this.value.add(value);
} }
@ -124,6 +132,7 @@ public class IntegerListParameter extends AbstractParameter<List<Integer>> imple
@Override @Override
public boolean addValueIfNotContains(Integer value) { public boolean addValueIfNotContains(Integer value) {
assertNotReadonly(); assertNotReadonly();
DBC.PRE.assertNotNull("null values not allowed!", value);
if (this.value.contains(value)) if (this.value.contains(value))
return false; return false;

View File

@ -83,10 +83,13 @@ public class LongListParameter extends AbstractParameter<List<Long>> implements
} }
@Override @Override
public void setValue(List<Long> value) { public void setValue(List<Long> values) {
assertNotReadonly(); assertNotReadonly();
validateValue(value); validateValue(values);
this.value = new ArrayList<>(value); for (Long value : values) {
DBC.PRE.assertNotNull("null values not allowed!", value);
}
this.value = new ArrayList<>(values);
} }
@Override @Override
@ -103,12 +106,17 @@ public class LongListParameter extends AbstractParameter<List<Long>> implements
@Override @Override
public void addValue(Long value) { public void addValue(Long value) {
assertNotReadonly(); assertNotReadonly();
DBC.PRE.assertNotNull("null values not allowed!", value);
this.value.add(value); this.value.add(value);
} }
@Override @Override
public void addAllValues(List<Long> values) { public void addAllValues(List<Long> values) {
assertNotReadonly(); assertNotReadonly();
for (Long value : values) {
DBC.PRE.assertNotNull("null values not allowed!", value);
this.value.add(value);
}
this.value.addAll(values); this.value.addAll(values);
} }
@ -116,6 +124,7 @@ public class LongListParameter extends AbstractParameter<List<Long>> implements
public void addAllValuesIfNotContains(List<Long> values) { public void addAllValuesIfNotContains(List<Long> values) {
assertNotReadonly(); assertNotReadonly();
for (Long value : values) { for (Long value : values) {
DBC.PRE.assertNotNull("null values not allowed!", value);
if (!this.value.contains(value)) if (!this.value.contains(value))
this.value.add(value); this.value.add(value);
} }
@ -124,6 +133,7 @@ public class LongListParameter extends AbstractParameter<List<Long>> implements
@Override @Override
public boolean addValueIfNotContains(Long value) { public boolean addValueIfNotContains(Long value) {
assertNotReadonly(); assertNotReadonly();
DBC.PRE.assertNotNull("null values not allowed!", value);
if (this.value.contains(value)) if (this.value.contains(value))
return false; return false;

View File

@ -83,10 +83,13 @@ public class StringListParameter extends AbstractParameter<List<String>> impleme
} }
@Override @Override
public void setValue(List<String> value) { public void setValue(List<String> values) {
assertNotReadonly(); assertNotReadonly();
validateValue(value); validateValue(values);
this.value = new ArrayList<>(value); for (String value : values) {
DBC.PRE.assertNotEmpty("empty values not allowed!", value);
}
this.value = new ArrayList<>(values);
} }
@Override @Override
@ -103,19 +106,24 @@ public class StringListParameter extends AbstractParameter<List<String>> impleme
@Override @Override
public void addValue(String value) { public void addValue(String value) {
assertNotReadonly(); assertNotReadonly();
DBC.PRE.assertNotEmpty("empty values not allowed!", value);
this.value.add(value); this.value.add(value);
} }
@Override @Override
public void addAllValues(List<String> values) { public void addAllValues(List<String> values) {
assertNotReadonly(); assertNotReadonly();
this.value.addAll(values); for (String value : values) {
DBC.PRE.assertNotEmpty("empty values not allowed!", value);
this.value.add(value);
}
} }
@Override @Override
public void addAllValuesIfNotContains(List<String> values) { public void addAllValuesIfNotContains(List<String> values) {
assertNotReadonly(); assertNotReadonly();
for (String value : values) { for (String value : values) {
DBC.PRE.assertNotEmpty("empty values not allowed!", value);
if (!this.value.contains(value)) if (!this.value.contains(value))
this.value.add(value); this.value.add(value);
} }
@ -124,6 +132,7 @@ public class StringListParameter extends AbstractParameter<List<String>> impleme
@Override @Override
public boolean addValueIfNotContains(String value) { public boolean addValueIfNotContains(String value) {
assertNotReadonly(); assertNotReadonly();
DBC.PRE.assertNotEmpty("empty values not allowed!", value);
if (this.value.contains(value)) if (this.value.contains(value))
return false; return false;
@ -213,7 +222,9 @@ public class StringListParameter extends AbstractParameter<List<String>> impleme
List<String> values = new ArrayList<>(); List<String> values = new ArrayList<>();
for (String val : valueArr) { for (String val : valueArr) {
values.add(val.trim()); String trim = val.trim();
if (!trim.isEmpty())
values.add(trim);
} }
return values; return values;
} }
@ -223,5 +234,4 @@ public class StringListParameter extends AbstractParameter<List<String>> impleme
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(), ((StringListParameter) o).getValue().size()); return Integer.compare(this.getValue().size(), ((StringListParameter) o).getValue().size());
} }
} }