Previous Lecture Lecture 10 Next Lecture

Lecture 10, Mon 10/31

corgis databases, ant properties, sorting with lambdas

Corgis databases

Ant properties

Bundling one jar in another

Running from a jar file

-bash-4.3$ java -cp build/corgiAirlines.jar edu.ucsb.cs56.corgis.airlines.demos.ExampleStringSort
[BOS, EWR, JFK, LAX, OAK, PHX, SAN, SBA, SFO, SJC, SNA]
-bash-4.3$

Sorting with lambdas

In ExampleSort01.java we use a lambda to sort by Airport Code

    public static void main(String[] args) {
        // Get access to the library
        AirlinesLibrary airlinesLibrary = new AirlinesLibrary();
        // Access data inside the library
        ArrayList<Airline> list_of_airline = airlinesLibrary.getReports(true);

 	      Collections.sort(list_of_airline,
			    (a1,a2) ->
			      a1.getAirport().toString().compareTo(a2.getAirport().toString()));
	
        AirlinePrinter.printNicely(list_of_airline);
    }

The main class of ExampleSort02.java is identical except for the lambda expression; here we sort by airline code (Carrier, e.g. AA for American Airlines, DL for Delta, etc.)

 		Collections.sort(list_of_airline,
			 (a1,a2) ->
			 a1.getCarrier().toString().compareTo
			         (a2.getCarrier().toString()));