java - Filter list according to given Object's fields (which could be null) -
is there sophisticated way filter through list of objects when have filterobject..
public class filterlistofbets { private final string userid; private final long betid; private final int minbettime; private final int maxbettime; // constructor , methods .. }
.. , list of bets containing of fields, ..
public class bet { private final long betid; private final string userid; private final long bettime; }
.. thing (if not all) of filterlistobject's fields may set null. result depends on fields have been set. in end want have list filteredlist contains objects match criteria.
if i, instance, knew values set, i'd loop through list:
for (bet bet : listofbets) { if (betfilter.getuserid == bet.getuserid && betfilter.getbetid == bet.getbetid && ...) }
if minbettime , maxbettime in filterlistofbets set, outcome list should satisfy : mintime < time < maxtime.
you can create object want compare against , use guava fluentiterable or java stream
fluentiterable.from(listofobject) .filter(new predicate<filterobject>(filterobject item) { return item.equals(mytestitem); }) .tolist();
i have written on phone havnt checked idea
Comments
Post a Comment