Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/Bins.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.util.List;
import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.function.Function;


/**
Expand Down Expand Up @@ -38,7 +39,10 @@ public int getTotal (List<Integer> data) {
}
return total;
}

public static void fitDisksAndPrint(List<Integer> list, Function<List<Integer>, List<Integer>> func){
List<Integer> transformed = func.apply(list);
transformed.forEach(System.out::println);
}
// add files to the collection of Disks
private Collection<Disk> allocateDisks (List<Integer> data) {
PriorityQueue<Disk> pq = new PriorityQueue<>();
Expand Down Expand Up @@ -80,7 +84,10 @@ private void runAlgorithm (List<Integer> data, String description) {
Collection<Disk> disks = allocateDisks(copy);
printResults(disks, description);
}

public static List<Integer> foo(List<Integer> something){
Collections.sort(something);
return something;
}
/**
* The main program.
*/
Expand All @@ -89,6 +96,7 @@ public static void main (String args[]) {
Scanner input = new Scanner(Bins.class.getClassLoader().getResourceAsStream(DATA_FILE));
List<Integer> 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);
Expand Down