aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/gv/egiz/moazs/util
diff options
context:
space:
mode:
authorChristof Rabensteiner <christof.rabensteiner@iaik.tugraz.at>2019-04-18 11:05:31 +0200
committerChristof Rabensteiner <christof.rabensteiner@iaik.tugraz.at>2019-04-18 14:48:17 +0200
commitaed1250912476f47fd772b0cedd20c850cdcff6e (patch)
treee7fe6aed56b12e53a9b2a7eef62d339e7d23b8b2 /src/main/java/at/gv/egiz/moazs/util
parent4215362c64064947cea880d55c4aae7894304783 (diff)
downloadmoa-zs-aed1250912476f47fd772b0cedd20c850cdcff6e.tar.gz
moa-zs-aed1250912476f47fd772b0cedd20c850cdcff6e.tar.bz2
moa-zs-aed1250912476f47fd772b0cedd20c850cdcff6e.zip
Change App2mzs Interface and Init Delivery Pipeline
- Change app2mzs interface: output message from app2mzs:DeliveryRequest was app2mzs:DeliveryResponse, now its msg:DeliveryRequestStatus. Reason: ZD returns msg:DeliveryRequestStatus which is signed. Moazs does not convert msg:DeliveryRequestStatus into app2mzs:DeliveryResponse because the conversion woudl break the signature. - App2MzsService: Make beans final and inject them with constructor; Refactor DeliveryRequestHandler into App2MZSService. - DeliveryPipeline: Add Interface and a "SameThreadImplementation" that executes the pipeline in the same threat and can be used in single mode. - DeliveryRepository: Augment interface for storing and retrieving request status objects; Add in-memory-implementation for status objects. - Utils: Add helper function for coalescing multiple values
Diffstat (limited to 'src/main/java/at/gv/egiz/moazs/util')
-rw-r--r--src/main/java/at/gv/egiz/moazs/util/NullCoalesce.java33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/main/java/at/gv/egiz/moazs/util/NullCoalesce.java b/src/main/java/at/gv/egiz/moazs/util/NullCoalesce.java
new file mode 100644
index 0000000..4377140
--- /dev/null
+++ b/src/main/java/at/gv/egiz/moazs/util/NullCoalesce.java
@@ -0,0 +1,33 @@
+package at.gv.egiz.moazs.util;
+
+import java.util.Optional;
+
+import static java.util.Optional.ofNullable;
+
+/**
+ * Helper function for coalescing nullables value without cluttering code with if-else cascades
+ * @author les2
+ * @source https://stackoverflow.com/questions/2768054/how-to-get-the-first-non-null-value-in-java
+ */
+public class NullCoalesce {
+
+ /**
+ * @return the first not-null value
+ * @param a
+ * @param b
+ * @param <T>
+ * @return a if a != null, otherwise b.
+ */
+ public static <T> Optional<T> coalesce(T a, T b) {
+ return a != null ? ofNullable(a) : ofNullable(b);
+ }
+
+ public static <T> Optional<T> coalesce(T a, T b, T c) {
+ return a != null ? ofNullable(a) : coalesce(b,c);
+ }
+
+ public static <T> Optional<T> coalesce(T a, T b, T c, T d) {
+ return a != null ? ofNullable(a) : coalesce(b,c,d);
+ }
+
+}