ПРИМЕЧАНИЕ: ваша строка кода не является правильным:
Для вызова метода фильтрации:
Collection<Ojects> ojects = filter(String name, Integer age, Integer number);
Также есть много деталей, отсутствующих в вашем вопросе, но используйте в качестве руководства: проверьте, являются ли все условия для фильтра нулевыми и возвращают все остальные элементы фильтра:
public Collection<Ojects> filter(String name, Integer age, Integer number) {
// return all object if no filter
if (name == null && age == null && number == null) {
Collection<Ojects> allOjects = // get all objects from where you wish
return allOjects;
}
// do the filters
Collection<Ojects> filteredOjects = new ....
// filter by name
if (name != null && name.lenght > 0) {
// do the filter and put the matching ones in filtered objects
}
// filter by age
if (age != null && age < 0) {
// do the filter and put the matching ones in filtered objects
}
// filter by number
if (name != null // conditions you need) {
// do the filter and put the matching ones in filtered objects
}
return filteredObjects
}
Если вы не фильтруете, когда параметры не указаны, вы вернете все объекты ...
Что вы имеете в виду «в случае пустого»? Что было бы нулевым? Какие данные вы возвращаете? – copeg
, по крайней мере, вы могли бы скопировать все домашние задания здесь, чтобы понять, что это такое! – Lrrr