Java Reference
In-Depth Information
StringTokenizer st = new StringTokenizer(infix," ()",true);
while (st.hasMoreTokens()) {
String token = st.nextToken();
if(!token.equals(" ")){
if(token.equals("AND")||token.equals("OR")){
if(ops.size()>parens)evaluate(ops,args);
ops.push(token);
}else if(token.equals("(")){
if(args.size()>0)++parens;
}else if(token.equals(")")){
--parens;
}else {
args.push(token);
}
}
}
while(!ops.empty()){
evaluate(ops,args);
}
String result = (String)args.pop();
return (result.equals("true"))?true:false;
}
private void evaluate(Stack ops,Stack args){
boolean a = (((String)args.pop()).equals("true"))?true:false;
boolean b = (((String)args.pop()).equals("true"))?true:false;
boolean c = false;
String o = (String)ops.pop();
if(o.equals("AND"))c = a & b;
if(o.equals("OR")) c = a | b;
args.push(c?"true":"false");
}
}
Testing the JDBC/XML Database
You can check out the JDBC/XML database using code similar to any of the DriverManager -based
examples in earlier chapters. Listing 19-12 shows a typical example using all the features of a scrollable
ResultSet implemented by adding the optional scrollable ResultSet methods of Listing 19-7 to the
basic XMLResultSet of Listing 19-6 .
Listing 19-12: JDBC/XML database test code
import java.io.*;
import java.net.*;
import java.sql.*;
Search WWH ::




Custom Search