I have a program which needs to be able to search through an ArrayList of 'book' objects, and decide which ones meet given criteria.
You can search by Name, ID Number, or Year published. Or just by any assortment of the above.
Currently i use nested if statements, where a null value means that field wasn't specified and to display all.
for(int x = 0; x<bookList.size(); x++)
{
if(bookList.get(x).callNum.equals(callNum) || callNum == null)
{
if(bookList.get(x).title.equals(title) || title == null)
{
if((bookList.get(x).year>= startDate
&& bookList.get(x).year <= endDate) || timeFrame == null)
{
bookList.get(x).ToString();
}
}
}
}
The only place i have a problem, is that for the title variable. I need it to do word-level matching. So if a book is called 'Java Programming' and another is called 'Object Oriented Programming in Java', both should be returned when the search is looking for 'Java'. How can i accomplish this?
I appreciate any help, thanks for you time!