mardi 11 février 2020

How to deal with a huge number of query params' if/else statement (e.g. filter)

A Java's web service is intended to be developed that should deal with 10 @QueryParam at least, every query param should accept a List of 4 values at minimum. That is to say, assuming I have 10 query param, every param has 4 values I will end up with 40 if-else statements (minimally) trying to construct all possible compilations.

e.g:

public Response getMethod(
        @QueryParam("a") List<String> a,
        @QueryParam("b") List<String> b,
        @QueryParam("c") List<String> c,
        @QueryParam("d") List<String> d,
        @QueryParam("e") List<String> e

       // ... etc
){

 if (a != null && b == null && c == null ...)
 {
    // bla bla bla - 1
 } 

 else if (a != null && b != null && c == null ...) 
 {
    // bla bla bla - 2
 }

....

My question is how to deal with such situations ? i.e. is there any shortcuts / patterns to minimize the work load here ?

Aucun commentaire:

Enregistrer un commentaire