Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // represents a filter function that take a collection of cabs, filters and returns the result
- type Filter = List[Cab] => List[Cab]
- /* a simple filter to filter cabs based on source and destination, */
- def matchRoutes(source: Source, destination: Destination): Filter = {
- cabs: List[Cab] => cabs.filter(c => c.finalDestination == destination && isWithinRange(c.currentLocation, source))
- }
- def isWithinRange(cabLoc: Location, myLoc: Location) = true
- /* a simple filter to filter cabs based on service type - pool, premier, etc, */
- def matchClass(typName: String): Filter = {
- cabs: List[Cab] => cabs.filter(_.typ.equalsIgnoreCase(typName))
- }
- /* a simple filter to filter cabs based on some kind of promotion */
- def matchPromotionCabs: Filter = {
- cabs: List[Cab] => cabs.filter(_.isOnPromotion)
- }
- /* a long laborious process of matching the best cabs based on multitude of factors
- * such as driver ratings, user ratings, co-passenger ratings, traffic conditions, etc
- * */
- def matchSeats(numOfSeats: Int): Filter = {
- cabs: List[Cab] => cabs.filter(_.seatsAvlbl == numOfSeats)
- }
- def matchDistanceToPickUp(here: Location, dis: Double): Filter = {
- cabs: List[Cab] => cabs.filter(_.distanceFromHere(here) == dis)
- }
- def matchTimeToDrop(here: Location, time: Int): Filter = {
- cabs: List[Cab] => cabs.filter(_.timeToDrop(here) <= time)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement