diff --git a/src/Bins.java b/src/Bins.java index abdf468..b1a9f2c 100644 --- a/src/Bins.java +++ b/src/Bins.java @@ -4,6 +4,7 @@ import java.util.List; import java.util.PriorityQueue; import java.util.Scanner; +import java.util.function.Function; /** @@ -38,7 +39,10 @@ public int getTotal (List data) { } return total; } - + public static void fitDisksAndPrint(List list, Function, List> func){ + List transformed = func.apply(list); + transformed.forEach(System.out::println); + } // add files to the collection of Disks private Collection allocateDisks (List data) { PriorityQueue pq = new PriorityQueue<>(); @@ -80,7 +84,10 @@ private void runAlgorithm (List data, String description) { Collection disks = allocateDisks(copy); printResults(disks, description); } - + public static List foo(List something){ + Collections.sort(something); + return something; + } /** * The main program. */ @@ -89,6 +96,7 @@ public static void main (String args[]) { Scanner input = new Scanner(Bins.class.getClassLoader().getResourceAsStream(DATA_FILE)); List data = b.readData(input); System.out.println("total size = " + b.getTotal(data) / 1000000.0 + "GB"); + fitDisksAndPrint(data, e -> foo(e)); b.runAlgorithm(data, WORST_FIT); b.runAlgorithm(data, WORST_FIT_DECREASING);