From cd1c597b61310db33e1050c2e130db4cab8b7641 Mon Sep 17 00:00:00 2001 From: Mateusz Warowny Date: Fri, 17 Feb 2023 13:28:26 +0100 Subject: [PATCH] JAL-4131 Replace usages of requireNonNullElse --- src/jalview/analysis/SeqsetUtils.java | 5 ++--- src/jalview/ws/params/simple/BooleanOption.java | 8 +++----- src/jalview/ws/params/simple/DoubleParameter.java | 5 ++--- src/jalview/ws/params/simple/IntegerParameter.java | 7 +++---- src/jalview/ws/params/simple/LogarithmicParameter.java | 6 ++---- src/jalview/ws/params/simple/Option.java | 3 +-- src/jalview/ws2/actions/annotation/AnnotationTask.java | 4 +--- .../ws2/client/slivka/SlivkaParamStoreFactory.java | 14 +++++++------- src/jalview/ws2/gui/AlignmentServiceGuiHandler.java | 4 +--- src/jalview/ws2/gui/WebServicesMenuManager.java | 5 ++--- 10 files changed, 24 insertions(+), 37 deletions(-) diff --git a/src/jalview/analysis/SeqsetUtils.java b/src/jalview/analysis/SeqsetUtils.java index 5a246f8..adb70e3 100755 --- a/src/jalview/analysis/SeqsetUtils.java +++ b/src/jalview/analysis/SeqsetUtils.java @@ -36,7 +36,6 @@ import java.util.Hashtable; import java.util.Iterator; import java.util.List; import java.util.Map; -import java.util.Objects; import java.util.Optional; import java.util.Vector; import static java.lang.String.format; @@ -79,8 +78,8 @@ public class SeqsetUtils ArrayList feats = new ArrayList<>( seq.getFeatures().getAllFeatures()); sqinfo.features = Optional.of(feats); - sqinfo.pdbId = Optional.of(Objects.requireNonNullElse( - seq.getAllPDBEntries(), new ArrayList<>())); + var pdbEntries = seq.getAllPDBEntries(); + sqinfo.pdbId = Optional.of(pdbEntries != null ? pdbEntries : new ArrayList<>()); } if (seq.hasHMMProfile()) { diff --git a/src/jalview/ws/params/simple/BooleanOption.java b/src/jalview/ws/params/simple/BooleanOption.java index cd492cf..87e4ad1 100644 --- a/src/jalview/ws/params/simple/BooleanOption.java +++ b/src/jalview/ws/params/simple/BooleanOption.java @@ -24,8 +24,6 @@ import java.net.URL; import java.util.Arrays; import java.util.List; -import static java.util.Objects.requireNonNullElse; - public class BooleanOption extends Option { public static class Builder extends Option.Builder @@ -38,12 +36,12 @@ public class BooleanOption extends Option public void setDefaultValue(Boolean defaultValue) { - this.defaultValue = requireNonNullElse(defaultValue, false); + this.defaultValue = defaultValue != null ? defaultValue : false; } public void setValue(Boolean value) { - this.value = requireNonNullElse(value, false); + this.value = value != null ? value : false; } public void setReprValue(String reprValue) @@ -72,7 +70,7 @@ public class BooleanOption extends Option protected BooleanOption(Builder builder) { super(builder); - String reprValue = requireNonNullElse(builder.reprValue, name); + String reprValue = builder.reprValue != null ? builder.reprValue : name; defvalue = builder.defaultValue ? reprValue : null; value = builder.value ? reprValue : null; possibleVals = List.of(reprValue); diff --git a/src/jalview/ws/params/simple/DoubleParameter.java b/src/jalview/ws/params/simple/DoubleParameter.java index 68029a3..97c5fe1 100644 --- a/src/jalview/ws/params/simple/DoubleParameter.java +++ b/src/jalview/ws/params/simple/DoubleParameter.java @@ -2,7 +2,6 @@ package jalview.ws.params.simple; import jalview.ws.params.ParameterI; import jalview.ws.params.ValueConstrainI; -import static java.util.Objects.requireNonNullElse; /** * @@ -56,12 +55,12 @@ public class DoubleParameter extends Option implements ParameterI public void setMin(Double min) { - this.min = requireNonNullElse(min, Double.POSITIVE_INFINITY); + this.min = min != null ? min : Double.POSITIVE_INFINITY; } public void setMax(Double max) { - this.max = requireNonNullElse(max, Double.NEGATIVE_INFINITY); + this.max = max != null ? max : Double.NEGATIVE_INFINITY; } public void setBounds(Double min, Double max) diff --git a/src/jalview/ws/params/simple/IntegerParameter.java b/src/jalview/ws/params/simple/IntegerParameter.java index af6c881..e154194 100644 --- a/src/jalview/ws/params/simple/IntegerParameter.java +++ b/src/jalview/ws/params/simple/IntegerParameter.java @@ -22,7 +22,6 @@ package jalview.ws.params.simple; import jalview.ws.params.ParameterI; import jalview.ws.params.ValueConstrainI; -import static java.util.Objects.requireNonNullElse; /** * @author jimp @@ -67,12 +66,12 @@ public class IntegerParameter extends Option implements ParameterI public void setMin(Integer min) { - this.min = requireNonNullElse(min, Integer.MAX_VALUE); + this.min = min != null ? min : Integer.MAX_VALUE; } public void setMax(Integer max) - { - this.max = requireNonNullElse(max, Integer.MIN_VALUE); + { + this.max = max != null ? max : Integer.MIN_VALUE; } public void setBounds(Integer min, Integer max) diff --git a/src/jalview/ws/params/simple/LogarithmicParameter.java b/src/jalview/ws/params/simple/LogarithmicParameter.java index 12a7be1..b4e2e50 100644 --- a/src/jalview/ws/params/simple/LogarithmicParameter.java +++ b/src/jalview/ws/params/simple/LogarithmicParameter.java @@ -1,7 +1,5 @@ package jalview.ws.params.simple; -import static java.util.Objects.requireNonNullElse; - import jalview.ws.params.ParameterI; import jalview.ws.params.ValueConstrainI; @@ -58,12 +56,12 @@ public class LogarithmicParameter extends Option implements ParameterI public void setMin(Double min) { - this.min = requireNonNullElse(min, Double.POSITIVE_INFINITY); + this.min = min != null ? min : Double.POSITIVE_INFINITY; } public void setMax(Double max) { - this.max = requireNonNullElse(max, Double.NEGATIVE_INFINITY); + this.max = max != null ? max : Double.NEGATIVE_INFINITY; } public void setBounds(Double min, Double max) diff --git a/src/jalview/ws/params/simple/Option.java b/src/jalview/ws/params/simple/Option.java index 44f9f5d..d6f3e7c 100644 --- a/src/jalview/ws/params/simple/Option.java +++ b/src/jalview/ws/params/simple/Option.java @@ -26,7 +26,6 @@ import java.net.URL; import java.util.ArrayList; import java.util.List; import static java.util.Objects.requireNonNull; -import static java.util.Objects.requireNonNullElse; public class Option implements OptionI { @@ -143,7 +142,7 @@ public class Option implements OptionI { requireNonNull(builder.name); name = builder.name; - label = requireNonNullElse(builder.label, name); + label = builder.label != null ? builder.label : name; description = builder.description; required = builder.required; defvalue = builder.defaultValue; diff --git a/src/jalview/ws2/actions/annotation/AnnotationTask.java b/src/jalview/ws2/actions/annotation/AnnotationTask.java index 165e132..271d9ed 100644 --- a/src/jalview/ws2/actions/annotation/AnnotationTask.java +++ b/src/jalview/ws2/actions/annotation/AnnotationTask.java @@ -43,8 +43,6 @@ import jalview.ws2.client.api.AnnotationWebServiceClientI; import jalview.ws2.helpers.DelegateJobEventListener; import jalview.ws2.helpers.TaskEventSupport; -import static java.util.Objects.requireNonNullElse; - public class AnnotationTask implements TaskI { private final long uid = MathUtils.getUID(); @@ -185,7 +183,7 @@ public class AnnotationTask implements TaskI private void updateOurAnnots(List newAnnots) { - List oldAnnots = requireNonNullElse(ourAnnots, Collections.emptyList()); + List oldAnnots = ourAnnots != null ? ourAnnots : Collections.emptyList(); ourAnnots = newAnnots; AlignmentI alignment = viewport.getAlignment(); for (AlignmentAnnotation an : oldAnnots) diff --git a/src/jalview/ws2/client/slivka/SlivkaParamStoreFactory.java b/src/jalview/ws2/client/slivka/SlivkaParamStoreFactory.java index a848798..fba6d2b 100644 --- a/src/jalview/ws2/client/slivka/SlivkaParamStoreFactory.java +++ b/src/jalview/ws2/client/slivka/SlivkaParamStoreFactory.java @@ -1,7 +1,5 @@ package jalview.ws2.client.slivka; -import static java.util.Objects.requireNonNullElse; - import java.io.File; import java.net.MalformedURLException; import java.net.URL; @@ -31,6 +29,7 @@ import uk.ac.dundee.compbio.slivkaclient.SlivkaService; class SlivkaParamStoreFactory { private final SlivkaService service; + private final ParamManager manager; SlivkaParamStoreFactory(SlivkaService service, ParamManager manager) @@ -38,7 +37,7 @@ class SlivkaParamStoreFactory this.service = service; this.manager = manager; } - + ParamDatastoreI createParamDatastore() { URL url = null; @@ -57,7 +56,7 @@ class SlivkaParamStoreFactory List arguments = createPresetArguments(Collections.emptyMap()); return new SimpleParamDatastore(url, arguments, presets, manager); } - + WsParamSetI createPreset(SlivkaService.Preset preset) { var builder = SimpleParamSet.newBuilder(); @@ -156,7 +155,7 @@ class SlivkaParamStoreFactory private List