Java Search for a sub list from a list with many criteria -


i want make search method list of restaurants. user has gui form , complete fields wants. made method meetscriteria check if restaurant exist. works not in cases.

public class restaurantlist {     private arraylist<restaurant> _restaurants = new arraylist<restaurant>();         restaurantlist selrest;          restaurantlist searchrestaurant(string name, string area, string phone, string category)                 {                     selrest = new restaurantlist();                     (int i=0; i< _restaurants.size(); i++)                     {                         if(_restaurants.get(i).meetscriteria(name, area, phone, category))                         {                             selrest.addrestaurant(_restaurants.get(i));                         }                      }                     return this.selrest;                 }  public class controller {       //this list restaurants     static restaurantlist restlist = new restaurantlist();     //this list result of search.      public static restaurantlist sellist; // selectedlist       public void addrestaurant (restaurant rest)     {         restlist.addrestaurant(rest);     }      public  void searchcriteria(string name, string area, string phone, string category)     {          int size = restlist.getrestaurants().size();         for(int =0; i<size; i++)             sellist = restlist.searchrestaurant(name, area, phone, category);      }   }  public class restaurant {         private string _name;     private string _address;     private string _phonenum;         private area _area;          public boolean meetscriteria(string name, string area, string phone, string category)         {             if( this._name.equals(name) && this._area.getarea().equals(area) && this._phonenum.equals(phone) && this._category.equals(category) )             {                 return true;               }             if ( name.equals("") && area.equals(this._area.getarea()) && phone.equals("") && category.equals("") )             {                 return true;               }             if ( name.equals("") && area.equals(this._area.getarea()) && phone.equals(this._phonenum) && category.equals("") )             {                 return true;               }             if (name.equals("") && area.equals(this._area.getarea()) && phone.equals("") && category.equals(this._category) )             {                return true;                }             if ( area.equals(this._area.getarea()) && phone.equals("") && category.equals("") )             {                 int index = this._name.indexof(name);                 if (index != -1)                 {                     return true;                  }else return false;               }             if (area.equals(this._area) && category.equals(this._category) )             {                 return true;             }             else             {             return false;             }         } } 

begin writing unit test "meetscriteria" method can see conditions pass , fail.

for example:

asserttrue(myrestaurant.meetscriteria("nandos", "new york", "0124536", "tasty")); 

ps., change "searchrestaurant" this:

list<restaurant> searchrestaurant(list<restaurant> allrestaurants, string name, string area, string phone, string category) {     list<restaurant> matches = new arraylist<restaurant>();     (restaurant restaurant : allrestaurants) {         if (restaurant.meetscriteria(name, area, phone, category)) {             matches.addrestaurant(allrestaurants.get(i));         }     }     return matches; } 

Comments

Popular posts from this blog

django - How can I change user group without delete record -

java - Need to add SOAP security token -

java - EclipseLink JPA Object is not a known entity type -