Consider below JSON:
"collection1" :
{
"list1" : ["val1","val2","val3"]
"list2" : ["val1","val2","val3"]
},
"collection2" :
{
"list1" : ["val1","val2","val3"]
"list2" : ["val1","val2","val3"]
},
I want to return true if there is no value for both collection1 and collection2. Now whether there is "no value" can be determined by many ways:
- both
collection1andcollection2arenull - all
collection1,collection2.list1andcollection2.list2arenull collection1isnullandcollection2.list1andcollection2.list2contains no elements orcollection2.list1isnullandcollection2.list2contains no elements orcollection2.list2isnullandcollection2.list1contains no elements
You can realise this can lead to many combinations. I can obiviously translate this directly to if-else blocks, but am finding it boring, or may be I am just bored, my head isnt working and really need some coffee because I am not able to guess anything simpler, smaller (possibly few liner if one liner is not possible) and concise on such a simple/dull thing. Or am I just wasting my time and over thinking? Ans simply convert that to if-else block and leave?
I am writing code in groovy, so Java solution will also work.
Aucun commentaire:
Enregistrer un commentaire