Hi all,
here is the criteriaFind I did, I have an error when I do
rv[j++] = new DataInfo(j, description,values);
/******************/
// criteria format
//FlightNO='PA001'[,Destination='JFK',..]
public synchronized DataInfo[] criteriaFind(
String criteriaString) throws DatabaseException {
invariant();
try {
System.out.println("try finding"); //###
//##########
//tokenize and parse the criteria
StringTokenizer criteriaTokens = new StringTokenizer(criteriaString,",");
int tokenCount = criteriaTokens.countTokens();
System.out.println("tokencount="+tokenCount);
//the field need to be matched in each flight
//if need match, set to 1
int filedToMatch[] ={0,0,0,0};
String valuesToMacth[]={"", "", "", ""};
while (criteriaTokens.hasMoreTokens()){
//get the criteria pair and trim
String criteriaPair = criteriaTokens.nextToken().trim();
//System.out.println("nextToken="+criteriaPair);
int equalSignPos = criteriaPair.indexOf("=");
String criteria = criteriaPair.substring(0,equalSignPos);
//System.out.println("criteria=" + criteria);
int valueStartIndex = equalSignPos+2;
int valueStopIndex = criteriaPair.length()-1;
String criteriaValue = criteriaPair.substring(valueStartIndex,valueStopIndex);
//System.out.println("criteriavalue="+ criteriaValue);
if (criteria .equals("FlightNo")) {
filedToMatch[0] = 1;
valuesToMacth[0] = criteriaValue;
} else if (criteria.equals("Origin")) {
filedToMatch[1] = 1;
valuesToMacth[1] = criteriaValue;
} else if (criteria.equals("Destination")) {
filedToMatch[2] = 1;
valuesToMacth[2] = criteriaValue;
} else if (criteria.equals("Carrier")) {
filedToMatch[3] = 1;
valuesToMacth[3] = criteriaValue;
}
}
for (int i=0; i<4; i++){
System.out.println("filedToMatch" + i + "=" + filedToMatch[i]);
}
//##########
seek(1);
DataInfo[] rv = null;
String [] values = null;
boolean found = false;
int r;
int j=0;
for (r = 1; r <= recordCount; r++) {
values = readRecord();
System.out.println("search for record no." + r);
if (values != null) {
found = true;
for (int i=0; i<4; i++) {
//System.out.println("enter for loop");
if (filedToMatch[i] == 1){
//System.out.println("compare now");
found= found && (values[i].equals(valuesToMacth[i]));
//System.out.println("found= " + found);
}else{
//System.out.println(" skip compare");
}
}
}
//if(found) break;
if (found) {
System.out.println("I find it, yahhhhhh, yehhhhh "); //###
rv[j++] = new DataInfo(j, description, values);
System.out.println("OK");
}
}
/*
if (found) {
rv = new DataInfo(r, description, values);
System.out.println("I find it, yahhhhhh, yehhhhh "); //###
}
*/ return rv;
} catch (IOException e) {
throw new DatabaseException(UNEXPECTED + e);
}
}
/***************/
What is the fix for this?
Could someone tell me if the way to parse the criteria OK?
Thanks.