From aed1250912476f47fd772b0cedd20c850cdcff6e Mon Sep 17 00:00:00 2001 From: Christof Rabensteiner Date: Thu, 18 Apr 2019 11:05:31 +0200 Subject: 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 --- .../java/at/gv/egiz/moazs/util/NullCoalesce.java | 33 ++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 src/main/java/at/gv/egiz/moazs/util/NullCoalesce.java (limited to 'src/main/java/at/gv/egiz/moazs/util') 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 + * @return a if a != null, otherwise b. + */ + public static Optional coalesce(T a, T b) { + return a != null ? ofNullable(a) : ofNullable(b); + } + + public static Optional coalesce(T a, T b, T c) { + return a != null ? ofNullable(a) : coalesce(b,c); + } + + public static Optional coalesce(T a, T b, T c, T d) { + return a != null ? ofNullable(a) : coalesce(b,c,d); + } + +} -- cgit v1.2.3