Created
January 24, 2010 18:23
-
-
Save atla/285353 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Main.scala | |
* | |
* To change this template, choose Tools | Template Manager | |
* and open the template in the editor. | |
*/ | |
package scalaapplication15 | |
object Main { | |
class Flight (id:Int) | |
class TicketFlights (val segmentNumber: Int, val positionInSegment: Int, flight:Flight) { | |
override def toString = "segmentNumber: " + segmentNumber | |
} | |
def test () = { | |
val ticketFlights = List (new TicketFlights (2, 0, new Flight (0)), new TicketFlights (0, 1, new Flight (0)), new TicketFlights (1, 0, new Flight (0)), new TicketFlights (0, 0, new Flight (0))) | |
val segmentNumbers = ticketFlights.map (_.segmentNumber) | |
val withoutDuplicates = segmentNumbers.removeDuplicates | |
println (withoutDuplicates) | |
val tmp = withoutDuplicates.map (x => ticketFlights.filter ( _.segmentNumber == x)) | |
println (tmp) | |
tmp | |
} | |
def main(args: Array[String]) :Unit = { | |
test () | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment