Java Reference
In-Depth Information
ing example, a filter class is created that will later be used to filter the results that are
returned from a database query. The filter in the example is used to limit the number of
rows that are visible based on an author's last name. The following class contains the
implementation of the filter:
package org.java8recipes.chapter13.recipe13_12;
import java.sql.SQLException;
import javax.sql.RowSet;
import javax.sql.rowset.Predicate;
public class AuthorFilter implements Predicate {
private String[] authors;
private String colName = null;
private int colNumber = -1;
public AuthorFilter(String[] authors, String colName) {
this.authors = authors;
this.colNumber = -1;
this.colName = colName;
}
public AuthorFilter(String[] authors, int colNumber) {
this.authors = authors;
this.colNumber = colNumber;
this.colName = null;
}
@Override
public boolean evaluate(Object value, String colName) {
if (colName.equalsIgnoreCase(this.colName)) {
for (String author : this.authors) {
if (author.equalsIgnoreCase((String)value)) {
return true;
}
}
}
Search WWH ::




Custom Search