From 74a5e140df11e8ef21c457eef43844eb901f77b9 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Mon, 26 Nov 2018 18:03:58 +0100 Subject: [PATCH] [Minor] Assert ListParameters do not get null values added --- .../model/parameter/FloatListParameter.java | 25 +++++++++++++------ .../model/parameter/IntegerListParameter.java | 17 ++++++++++--- .../model/parameter/LongListParameter.java | 16 +++++++++--- .../model/parameter/StringListParameter.java | 22 +++++++++++----- 4 files changed, 59 insertions(+), 21 deletions(-) diff --git a/li.strolch.model/src/main/java/li/strolch/model/parameter/FloatListParameter.java b/li.strolch.model/src/main/java/li/strolch/model/parameter/FloatListParameter.java index c565f9e99..5c6976969 100644 --- a/li.strolch.model/src/main/java/li/strolch/model/parameter/FloatListParameter.java +++ b/li.strolch.model/src/main/java/li/strolch/model/parameter/FloatListParameter.java @@ -46,13 +46,13 @@ public class FloatListParameter extends AbstractParameter> implemen * the id * @param name * the name - * @param value - * the value + * @param values + * the values */ - public FloatListParameter(String id, String name, List value) { + public FloatListParameter(String id, String name, List values) { super(id, name); - setValue(value); + setValue(values); } @Override @@ -83,10 +83,13 @@ public class FloatListParameter extends AbstractParameter> implemen } @Override - public void setValue(List value) { + public void setValue(List values) { assertNotReadonly(); - validateValue(value); - this.value = new ArrayList<>(value); + validateValue(values); + for (Double value : values) { + DBC.PRE.assertNotNull("null values not allowed!", value); + } + this.value = new ArrayList<>(values); } @Override @@ -103,19 +106,24 @@ public class FloatListParameter extends AbstractParameter> implemen @Override public void addValue(Double value) { assertNotReadonly(); + DBC.PRE.assertNotNull("null values not allowed!", value); this.value.add(value); } @Override public void addAllValues(List values) { assertNotReadonly(); - this.value.addAll(values); + for (Double value : values) { + DBC.PRE.assertNotNull("null values not allowed!", value); + this.value.add(value); + } } @Override public void addAllValuesIfNotContains(List values) { assertNotReadonly(); for (Double value : values) { + DBC.PRE.assertNotNull("null values not allowed!", value); if (!this.value.contains(value)) this.value.add(value); } @@ -124,6 +132,7 @@ public class FloatListParameter extends AbstractParameter> implemen @Override public boolean addValueIfNotContains(Double value) { assertNotReadonly(); + DBC.PRE.assertNotNull("null values not allowed!", value); if (this.value.contains(value)) return false; diff --git a/li.strolch.model/src/main/java/li/strolch/model/parameter/IntegerListParameter.java b/li.strolch.model/src/main/java/li/strolch/model/parameter/IntegerListParameter.java index 37a3814a3..d5aad4337 100644 --- a/li.strolch.model/src/main/java/li/strolch/model/parameter/IntegerListParameter.java +++ b/li.strolch.model/src/main/java/li/strolch/model/parameter/IntegerListParameter.java @@ -83,10 +83,13 @@ public class IntegerListParameter extends AbstractParameter> imple } @Override - public void setValue(List value) { + public void setValue(List values) { assertNotReadonly(); - validateValue(value); - this.value = new ArrayList<>(value); + validateValue(values); + for (Integer value : values) { + DBC.PRE.assertNotNull("null values not allowed!", value); + } + this.value = new ArrayList<>(values); } @Override @@ -103,19 +106,24 @@ public class IntegerListParameter extends AbstractParameter> imple @Override public void addValue(Integer value) { assertNotReadonly(); + DBC.PRE.assertNotNull("null values not allowed!", value); this.value.add(value); } @Override public void addAllValues(List values) { assertNotReadonly(); - this.value.addAll(values); + for (Integer value : values) { + DBC.PRE.assertNotNull("null values not allowed!", value); + this.value.add(value); + } } @Override public void addAllValuesIfNotContains(List values) { assertNotReadonly(); for (Integer value : values) { + DBC.PRE.assertNotNull("null values not allowed!", value); if (!this.value.contains(value)) this.value.add(value); } @@ -124,6 +132,7 @@ public class IntegerListParameter extends AbstractParameter> imple @Override public boolean addValueIfNotContains(Integer value) { assertNotReadonly(); + DBC.PRE.assertNotNull("null values not allowed!", value); if (this.value.contains(value)) return false; diff --git a/li.strolch.model/src/main/java/li/strolch/model/parameter/LongListParameter.java b/li.strolch.model/src/main/java/li/strolch/model/parameter/LongListParameter.java index c5636c066..795870797 100644 --- a/li.strolch.model/src/main/java/li/strolch/model/parameter/LongListParameter.java +++ b/li.strolch.model/src/main/java/li/strolch/model/parameter/LongListParameter.java @@ -83,10 +83,13 @@ public class LongListParameter extends AbstractParameter> implements } @Override - public void setValue(List value) { + public void setValue(List values) { assertNotReadonly(); - validateValue(value); - this.value = new ArrayList<>(value); + validateValue(values); + for (Long value : values) { + DBC.PRE.assertNotNull("null values not allowed!", value); + } + this.value = new ArrayList<>(values); } @Override @@ -103,12 +106,17 @@ public class LongListParameter extends AbstractParameter> implements @Override public void addValue(Long value) { assertNotReadonly(); + DBC.PRE.assertNotNull("null values not allowed!", value); this.value.add(value); } @Override public void addAllValues(List values) { assertNotReadonly(); + for (Long value : values) { + DBC.PRE.assertNotNull("null values not allowed!", value); + this.value.add(value); + } this.value.addAll(values); } @@ -116,6 +124,7 @@ public class LongListParameter extends AbstractParameter> implements public void addAllValuesIfNotContains(List values) { assertNotReadonly(); for (Long value : values) { + DBC.PRE.assertNotNull("null values not allowed!", value); if (!this.value.contains(value)) this.value.add(value); } @@ -124,6 +133,7 @@ public class LongListParameter extends AbstractParameter> implements @Override public boolean addValueIfNotContains(Long value) { assertNotReadonly(); + DBC.PRE.assertNotNull("null values not allowed!", value); if (this.value.contains(value)) return false; diff --git a/li.strolch.model/src/main/java/li/strolch/model/parameter/StringListParameter.java b/li.strolch.model/src/main/java/li/strolch/model/parameter/StringListParameter.java index 236650aa1..9e0eebc7f 100644 --- a/li.strolch.model/src/main/java/li/strolch/model/parameter/StringListParameter.java +++ b/li.strolch.model/src/main/java/li/strolch/model/parameter/StringListParameter.java @@ -83,10 +83,13 @@ public class StringListParameter extends AbstractParameter> impleme } @Override - public void setValue(List value) { + public void setValue(List values) { assertNotReadonly(); - validateValue(value); - this.value = new ArrayList<>(value); + validateValue(values); + for (String value : values) { + DBC.PRE.assertNotEmpty("empty values not allowed!", value); + } + this.value = new ArrayList<>(values); } @Override @@ -103,19 +106,24 @@ public class StringListParameter extends AbstractParameter> impleme @Override public void addValue(String value) { assertNotReadonly(); + DBC.PRE.assertNotEmpty("empty values not allowed!", value); this.value.add(value); } @Override public void addAllValues(List values) { assertNotReadonly(); - this.value.addAll(values); + for (String value : values) { + DBC.PRE.assertNotEmpty("empty values not allowed!", value); + this.value.add(value); + } } @Override public void addAllValuesIfNotContains(List values) { assertNotReadonly(); for (String value : values) { + DBC.PRE.assertNotEmpty("empty values not allowed!", value); if (!this.value.contains(value)) this.value.add(value); } @@ -124,6 +132,7 @@ public class StringListParameter extends AbstractParameter> impleme @Override public boolean addValueIfNotContains(String value) { assertNotReadonly(); + DBC.PRE.assertNotEmpty("empty values not allowed!", value); if (this.value.contains(value)) return false; @@ -213,7 +222,9 @@ public class StringListParameter extends AbstractParameter> impleme List values = new ArrayList<>(); for (String val : valueArr) { - values.add(val.trim()); + String trim = val.trim(); + if (!trim.isEmpty()) + values.add(trim); } return values; } @@ -223,5 +234,4 @@ public class StringListParameter extends AbstractParameter> impleme DBC.PRE.assertEquals("Not same Parameter types!", this.getType(), o.getType()); return Integer.compare(this.getValue().size(), ((StringListParameter) o).getValue().size()); } - }