lundi 30 septembre 2019

What is the best way to refactor multiple conditions in an if statement?

I have an if statement with lots of conditions inside, but the conditions are fairly different. It looks really bulky. I'm not sure if there is a way to do it.

// rqstCriteria is a List
// anotherCriteria is a List
// key# are the different values that I want to see if it has
if (
rqstCriteria.contains(key1) || 
rqstCriteria.contains(key2) || 
rqstCriteria.contains(key3) || 
rqstCriteria.contains(key4) || 
rqstCriteria.contains(key5) && 
(anotherCriteria != null && 
  (anotherCriteria.contains(key1) || 
   anotherCriteria.contains(key2) || 
   anotherCriteria.contains(key3) || 
   anotherCriteria.contains(key4) || 
   anotherCriteria.contains(key5))
{...} 

Aucun commentaire:

Enregistrer un commentaire