jSQL is a java library provide developers to filter the java collections with syntax similar to SQL. It enhances you application performance by ignoring the database connection if you already having a database records in the java collection.
Use the following code to create an instance of CollectionFilter class.
~~~~~~~~~~~~~~~~~~
CollectionFilter<emp> objFilter = new CollectionFilter<emp>(list, "name=\"aa106\"");
list = (List<emp>) objFilter.getFilteredCollection();</emp></emp></emp>
//list: first parameter passed to CollectionFilter class constructor is collection to be filtered.
//query: "name=\"aa106\"" is second parameter which is the filter that is going to be applied on collection.
~~~~~~~~~~~~~~~~~~~
getFilteredCollection() is function in CollectionFilter class which returns the filtered collection.
Filter follows similar to sql syntax without select,order by and supports where clause without where. So syntax goes like this :
~~~~~~~~~~~~~
(propertyName operator operand) logical operator (propertyName operator operand)
age>=20 and age<=35 and deptName="Finance"
//This will return the collection contain object which are from Finance department and age is between 20 and 35.
~~~~~~~~~~~~~
Use " " double code to represent string comparison, so you have to use escape sequence( "name=\"Ajay\"") while passing to CollectionFilter class.