I have a method that receives an Object of type List
of a class of its own that is called Pallet. The class Pallet
has a creation date, an article, an id, a warehouse ... etc.
The method
filterPalletWithDataretorna (List list, ListParametersFilter parameters);
returns another list with the pallets that have been filtered by the fields that I received in the object ListParametersFilter
public List<Pallet> filterPalletWithData(List<Pallet> list, ListParametersFilter parameters){
//aqui va mi codigo de filtrado
}
What I'm doing is:
public List<Pallet> filterPalletWithData(List<Pallet> list, ListParametersFilter parameters) {
List<Pallet> returnedPalets = new ArrayList<>();
returnedPalets.clear();
//por ppc
if (parameters.getId() >= 0)
for (Pallet p : list) {
if (p.getIdNum() == parameters.getId())
returnedPalets.add(p);
}
if (parameters.getOrderNum() >= 0)
for (Pallet p : list) {
if (p.getNum() == parameters.getOrderNum()) {
returnedPalets.add(p)
}
}
......
}
This is the class ListParametersFilter
public class ListParametersFilter {
private int id;
private int orderNum;
private long manufacturedArticle;
private long plantation;
private long crop;
private long crew;
private long customer;
private long pallet;
private long box;
private String since;
private String until;
public ListParametersFilter(int id, int orderNum,
long manufacturedArticle, long plantation,
long crop, long crew, long customer, long pallet,
long box, String since, String until) {
this.id= id;
this.orderNum = orderNum;
this.manufacturedArticle = manufacturedArticle;
this.plantation = plantation;
this.crop = crop;
this.crew = crew;
this.customer = customer;
this.pallet = pallet;
this.box = box;
this.since = since;
this.until = until;
}
public ListParametersFilter(){}
//Getters && setters
This is adding the pallets to a list that I then return, it only works if the filtering field is unique, for example by
id
but the problem comes when the filtering is multiple, that is, what happens if the user wants to filter by
store + id + article + date.
How can I implement that?