-
Notifications
You must be signed in to change notification settings - Fork 72
/
Flight.scala
47 lines (39 loc) · 1.6 KB
/
Flight.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package scalax.collection.labeled.aviation
import scalax.collection.OneOrMore
import scalax.collection.generic.{AbstractDiEdge, LDiEdgeToString, MultiEdge, MultiLEdgeToString, PartialEdgeMapper}
import java.time.{DayOfWeek, LocalTime}
import scala.concurrent.duration.FiniteDuration
/** A labeled edge to represent flights between airports.
*
* Defines a custom edge type that can be used for a flight route map.
*
* A `Flight` has several attributes like `departure` and `duration`.
* To enable multiple flights between airports, the key is extended by `flightNo`.
*
* @see EditingTypedSpec.scala.
*
* @param departure The departure airport
* @param destination The destination airport
* @param flightNo The flight Id as a key attribute consisting of the airline short and a flight number of that airline.
* @param departures daytime of departure
* @param duration of flight
*/
case class Flight(
departure: Airport,
destination: Airport,
flightNo: String,
departures: List[(DayOfWeek, LocalTime)],
duration: FiniteDuration
) extends AbstractDiEdge[Airport](departure, destination)
with MultiEdge
with LDiEdgeToString
with MultiLEdgeToString
with PartialEdgeMapper[Flight] {
override def weight: Double = duration.toMinutes.toDouble
def airline: String = flightNo.takeWhile(_.isLetter)
override def extendKeyBy: OneOrMore[String] = OneOrMore(flightNo)
override protected def labelToString: String = s"($flightNo, $departures, $duration)"
override def map[N]: PartialFunction[(N, N), Flight] = { case (from: Airport, to: Airport) =>
copy(from, to)
}
}