Skip to content
Open
Show file tree
Hide file tree
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
15 changes: 10 additions & 5 deletions src/Bins.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
* Runs a number of algorithms that try to fit files onto disks.
Expand All @@ -26,13 +26,18 @@ public List<Integer> readData (Scanner input) {
return results;
}

private static void fitDisksAndPrint(Function<List<Integer>, List<Integer>> func, List<Integer> data ) {
List<Integer> newList = func.apply(data);
newList.forEach(System.out::println);
}

/**
* The main program.
*/
public static void main (String args[]) {
Bins b = new Bins();
Scanner input = new Scanner(Bins.class.getClassLoader().getResourceAsStream(DATA_FILE));
List<Integer> data = b.readData(input);
Scanner in = new Scanner(Bins.class.getClassLoader().getResourceAsStream(DATA_FILE));
List<Integer> data = b.readData(in);

PriorityQueue<Disk> pq = new PriorityQueue<Disk>();
pq.add(new Disk(0));
Expand Down Expand Up @@ -63,7 +68,7 @@ public static void main (String args[]) {
}
System.out.println();

Collections.sort(data, Collections.reverseOrder());
fitDisksAndPrint((input) -> input.stream().sorted().collect(Collectors.toList()), data);
pq.add(new Disk(0));

diskId = 1;
Expand Down
2 changes: 2 additions & 0 deletions src/Disk.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import java.util.ArrayList;
import java.util.List;
import java.util.function.Function;

/**
* Represents a collection of files; how many it can hold is limited by its capacity.
Expand Down Expand Up @@ -103,4 +104,5 @@ public int compareTo (Disk other) {
return -1;
}
}

}