A DESCRIPTION OF THE PROBLEM :
In sample implementation which is represented in Documentation are many mistakes and inaccuracies.
Code does not compiled.
1) Implementation of Predicate interface is not completed
2) Automatic variables (bool1, bool2) are not initialized before their usage
3) Variable crs is not used
4) Absent try/catch block for rs.getObject(int columnIndex) methods
5) Syntax error in if operator clause (absent closing brace)
6) Not clear logic of use lo and hi variables when they used in condition ((rs.getObject(idx[i]) >= lo[i]) && (rs.getObject(idx[i]) >= hi[i]))
7) Redundant usage of bool2 variable in sense of returning value of the method.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Right implementation of Predicate Interface with code having a sense for analysis and computations
ACTUAL -
public class Range implements Predicate {
private Object lo[];
private Object hi[];
private int idx[];
public Range(Object[] lo, Object[] hi, int[] idx) {
this.lo = lo;
this.hi = hi;
this.idx = idx;
}
public boolean evaluate(RowSet rs) {
CachedRowSet crs = (CachedRowSet)rs;
boolean bool1,bool2;
// Check the present row determine if it lies
// within the filtering criteria.
for (int i = 0; i < idx.length; i++) {
if ((rs.getObject(idx[i]) >= lo[i]) &&
(rs.getObject(idx[i]) >= hi[i]) {
bool1 = true; // within filter constraints
} else {
bool2 = true; // outside of filter constraints
}
}
if (bool2) {
return false;
} else {
return true;
}
}
URL OF FAULTY DOCUMENTATION :
http://docs.oracle.com/javase/7/docs/api/javax/sql/rowset/Predicate.html
In sample implementation which is represented in Documentation are many mistakes and inaccuracies.
Code does not compiled.
1) Implementation of Predicate interface is not completed
2) Automatic variables (bool1, bool2) are not initialized before their usage
3) Variable crs is not used
4) Absent try/catch block for rs.getObject(int columnIndex) methods
5) Syntax error in if operator clause (absent closing brace)
6) Not clear logic of use lo and hi variables when they used in condition ((rs.getObject(idx[i]) >= lo[i]) && (rs.getObject(idx[i]) >= hi[i]))
7) Redundant usage of bool2 variable in sense of returning value of the method.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Right implementation of Predicate Interface with code having a sense for analysis and computations
ACTUAL -
public class Range implements Predicate {
private Object lo[];
private Object hi[];
private int idx[];
public Range(Object[] lo, Object[] hi, int[] idx) {
this.lo = lo;
this.hi = hi;
this.idx = idx;
}
public boolean evaluate(RowSet rs) {
CachedRowSet crs = (CachedRowSet)rs;
boolean bool1,bool2;
// Check the present row determine if it lies
// within the filtering criteria.
for (int i = 0; i < idx.length; i++) {
if ((rs.getObject(idx[i]) >= lo[i]) &&
(rs.getObject(idx[i]) >= hi[i]) {
bool1 = true; // within filter constraints
} else {
bool2 = true; // outside of filter constraints
}
}
if (bool2) {
return false;
} else {
return true;
}
}
URL OF FAULTY DOCUMENTATION :
http://docs.oracle.com/javase/7/docs/api/javax/sql/rowset/Predicate.html