예제 #1
0
func (c *CheapestFlightCache) Update(flight *model.Flight) UpdateResult {
	id := *flight.Id()
	newFare := flight.CheapestAvailableFare()

	oldFlight, existed := c.cache[id]
	if !existed {
		if newFare == nil {
			return Unchanged
		} else {
			c.cache[id] = flight
			return Added
		}
	}

	if newFare == nil {
		delete(c.cache, id)
		return Removed
	} else if newFare.Cents < oldFlight.CheapestAvailableFare().Cents {
		c.cache[id] = flight
		return Added
	} else {
		return Unchanged
	}
}
예제 #2
0
func (m *MaxAvailableFareFilter) Matches(flight *model.Flight) bool {
	return flight.CheapestAvailableFare().Cents <= m.Cents
}
예제 #3
0
func (m *MaxAvailableFareFilter) Matches(flight *model.Flight) bool {
	cheapestAvailableFare := flight.CheapestAvailableFare()
	return cheapestAvailableFare != nil && flight.CheapestAvailableFare().Cents <= m.Cents
}