• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

findbyCriteria compareRecord please look

 
Ling Chung
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
i have method to findbycriteria, i call this method to compare record to criteria :

Ok so boolean match to begin is true, but normally in methods boolean starts false.
Can i do it in this way?
And how to ignore case in record[i].startsWith(criteria[i])) ?
Thank you
 
Jacques Bosch
Ranch Hand
Posts: 319
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Ok so boolean match to begin is true, but normally in methods boolean starts false.
Can i do it in this way?

Initializing a boolean to true is fine.

And how to ignore case in record[i].startsWith(criteria[i])) ?

You could do something like:
if (a.toLowerCase().startsWith(b.toLowerCase())) ... etc
J
PS (I didn't check your code for logic or errors)
 
Ling Chung
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok so setting boolean to true is ok, but is it also ok in this case when comparing records. Could you please have a short look?
 
Jacques Bosch
Ranch Hand
Posts: 319
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ling.
You have:

For exact match you probably want !record[i].equals(criteria[i])), rather than !record[i].equalsIgnoreCase(criteria[i])).

Ok so setting boolean to true is ok, but is it also ok in this case when comparing records. Could you please have a short look?

Yes that appears fine, but in this case it would seem to me to be a bit more natural to start off with false, and to set match to true when a match is found. I.e. Check for a match, not for a non-match.
J
 
Jacques Bosch
Ranch Hand
Posts: 319
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry , I actually understand now what you are doing, starting off with the true, and then only changing to false if one of the fields don't match. Good way to do it.
But you could also put a break; after the match = false; lines to break out of the for loop. Since match is already false, there is no need to do further checks.
J
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic