public SelectItem[] getRouteOptions() {
   List<Route> routes = rm.getAllRoutes();
   List<Route> freeRoutes = new ArrayList<Route>();
   if (historiesForDate.isEmpty()) {
     SelectItem[] items = new SelectItem[routes.size()];
     int i = 0;
     for (Route r : routes) {
       items[i++] = new SelectItem(r.getId().toString(), r.toString());
     }
     return items;
   } else {
     boolean isFree = true;
     for (Route r : routes) {
       for (History his : historiesForDate) {
         if (r.getId().equals(his.getRoute().getId())) {
           isFree = false;
           break;
         }
       }
       if (isFree) {
         freeRoutes.add(r);
       } else isFree = true;
     }
     SelectItem[] items = new SelectItem[freeRoutes.size()];
     int i = 0;
     for (Route r : freeRoutes) {
       items[i++] = new SelectItem(r.getId().toString(), r.toString());
     }
     return items;
   }
 }
 // HELPERS
 public SelectItem[] getDriverOptions() {
   List<Driver> drivers = dm.getFreeDrivers();
   List<Driver> freeDrivers = new ArrayList<Driver>();
   if (historiesForDate.isEmpty()) {
     SelectItem[] items = new SelectItem[drivers.size()];
     int i = 0;
     for (Driver d : drivers) {
       items[i++] = new SelectItem(d.getId().toString(), d.toString());
     }
     return items;
   } else {
     boolean isFree = true;
     for (Driver d : drivers) {
       for (History his : historiesForDate) {
         if (d.getId().equals(his.getDriver().getId())) {
           isFree = false;
           break;
         }
       }
       if (isFree) {
         freeDrivers.add(d);
       } else isFree = true;
     }
     SelectItem[] items = new SelectItem[freeDrivers.size()];
     int i = 0;
     for (Driver d : freeDrivers) {
       items[i++] = new SelectItem(d.getId().toString(), d.toString());
     }
     return items;
   }
 }
 public SelectItem[] getBusOptions() {
   List<Bus> buses = bm.getWorkingBus();
   List<Bus> freeBuses = new ArrayList<Bus>();
   if (historiesForDate.isEmpty()) {
     SelectItem[] items = new SelectItem[buses.size()];
     int i = 0;
     for (Bus b : buses) {
       items[i++] = new SelectItem(b.getId().toString(), b.toString());
     }
     return items;
   } else {
     boolean isFree = true;
     for (Bus b : buses) {
       for (History his : historiesForDate) {
         if (b.getId().equals(his.getBus().getId())) {
           isFree = false;
           break;
         }
       }
       if (isFree) {
         freeBuses.add(b);
       } else isFree = true;
     }
     SelectItem[] items = new SelectItem[freeBuses.size()];
     int i = 0;
     for (Bus b : freeBuses) {
       items[i++] = new SelectItem(b.getId().toString(), b.toString());
     }
     return items;
   }
 }
 public String addHistory() {
   history.setDriver(dm.getDriver(driverId));
   history.setBus(bm.getBus(busId));
   history.setRoute(rm.getRoute(routeId));
   history.setDate(date);
   hm.addHistory(history);
   history = new History();
   driverId = 0L;
   busId = 0L;
   routeId = 0L;
   historiesForDate = hm.getHistoryByDate(date);
   return "showLines?faces-redirect=true";
 }