java - Implement a filter which in case of null return all the data -


how implement filter in case of null returns data? example if name null should excluded filter. way in head make 100k lines of code , test of combinations. stupid. dont want this. sure there better way.

collection<ojects> filter(string name, integer age, integer number) ; 

note: line of code not correct:

to call filter method:

collection<ojects> ojects = filter(string name, integer age, integer number); 

also there lot of details missing in question, use guide: check if conditions filter null , return elements else filter:

public collection<ojects> filter(string name, integer age, integer number) {     // return object if no filter     if (name == null && age == null && number == null) {         collection<ojects> allojects = // objects wish         return allojects;     }      // filters     collection<ojects> filteredojects = new ....      // filter name     if (name != null && name.lenght > 0) {         // filter , put matching ones in filtered objects     }      // filter age     if (age != null && age < 0) {         // filter , put matching ones in filtered objects     }      // filter number     if (name != null // conditions need) {         // filter , put matching ones in filtered objects     }       return filteredobjects } 

if don't filter when parameters not given return objects...


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -