Java Multiple comparision in java -
pardon me if stupid question.. wondering if there support following comparison in java:
(a, b, c .... != null)  in place : 
(a != null && b != null && c != null && d ! null , on ..)   i trying make code more readable code unreadable due multiple condition in single statement.
code :
variable = (rest.host != null && rest.payload != null      && rest.lockqueue != null && rest.endpoint != null ) || rest.default.setstate      || rest.scheduler.locked && rest.scheduler.queue.isfull()      && lastpayload.getactivity.status.executing ? onexecute(rest.payload) : wait(time);       
if elements in collection, use collection.stream().allmatch(x -> x != null). actually, there's predicate that: collection.stream().allmatch(objects::nonnull).
if elements aren't in collection, can still use arrays.aslist() create ad-hoc list them. so, in case: 
arrays.aslist(rest.host, rest.payload, rest.lockqueue, rest.endpoint).stream().allmatch(objects::nonnull)   edit: actually, mentioned in answer, there method creates stream directly, namely stream.of(...). so: 
stream.of(rest.host, rest.payload, rest.lockqueue, rest.endpoint).allmatch(objects::nonnull)      
Comments
Post a Comment