lundi 14 décembre 2020

summarize if-statement and read if conditions from another object like String[] (Dynamic If)

i have complex object(the name of that object is:"input") that have a lot of fields and i want check null each fields. now i have below unclean code :

if ( (input.getAction().isEmpty() || input.getAction().isBlank()) ||
            (input.getSubAction().isEmpty() || input.getSubAction().isBlank()) ||
            (input.getLob().isEmpty() || input.getLob().isBlank()) ||
            (input.getBusinessType().isEmpty() || input.getBusinessType().isBlank()) || ... )

as you can see i have more conditions check .

First : i want summarize this code (i know i could create simple method for each item checking and also could use java.util.Objects.isNull api and object == null if you have better ways i wondering to know that )

Second : i want read if-conditions parameters from another object like String[] which i read this object for example from application.properties similar i want create Dynamic If-Statement :) . see below semicode :

  String[] params = {"action" , "subAction" ,"lob", ...};
   if(input."params[0].isEmpty() || input."params[1]".isEmpty() || ...)

i appreciate you .

Aucun commentaire:

Enregistrer un commentaire