示例#1
0
 @Override
 public List<Object> getDishesByType(List<Object> dishList, String dishType) {
   ArrayList<Object> arrayList = new ArrayList<>();
   int dishTypeInt = DishInformation.getTypeValue(dishType);
   for (Object object : dishList) {
     if (object instanceof DishInformation) {
       DishInformation dishInformation = (DishInformation) object;
       if (dishTypeInt == dishInformation.getType()) {
         arrayList.add(dishInformation);
       }
     }
   }
   return arrayList;
 }
示例#2
0
 @Override
 public String getStatsByDishType(List<Object> dishList, String dishType) {
   int dishTypeInt = DishInformation.getTypeValue(dishType);
   int total = dishList.size();
   int count = 0;
   for (Object object : dishList) {
     if (getObjectFromFeature(object, dishType)) count++;
   }
   float percentage = count * 100 / total;
   return percentage + "%";
 }
示例#3
0
 private boolean getObjectFromFeature(Object object, String feature) {
   if (object instanceof DishInformation) {
     DishInformation dishInformation = (DishInformation) object;
     switch (feature) {
       case STR_GLUTEN_FREE:
         if (dishInformation.isGlutenFree()) return true;
         break;
       case STR_HALAL_MEAT:
         if (dishInformation.isHalalMeat()) return true;
         break;
       case STR_SEAFOOD_FREE:
         if (dishInformation.isSeafoodFree()) return true;
         break;
       case STR_VEGETARIAN:
         if (dishInformation.isVegetarian()) return true;
         break;
       default:
         return false;
     }
   }
   return false;
 }