diff --git a/.classpath b/.classpath
new file mode 100644
index 0000000..d478271
--- /dev/null
+++ b/.classpath
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
diff --git a/RECITATION.txt b/RECITATION.txt
new file mode 100644
index 0000000..89bf202
--- /dev/null
+++ b/RECITATION.txt
@@ -0,0 +1,40 @@
+Bins: Code Critiquen
+Brian Lin bl131
+Austin Hua ah335
+
+Readability
+
+What pieces of code help versus obscure your understanding of the algorithm?
+-The Disk methods are all relatively short, simple, and aptly titled. These help us understand the algorithm.
+-The Bins main method is very long and uncommented. This makes the algorithm hard to understand.
+What comments might be helpful within the code?
+Are there places where the code could be more concise and also more clear?
+-The Bins main method could be improved with comments
+-The Bins main method should also be shortened or split into their own methods based on function
+
+Testability
+How would you test this code for bugs?
+-Run the program with test cases, including specific edge cases
+Give a specific example of a "test case" as the code is currently written.
+-Text file containing: 1000001, 99999
+What additional functions may be helpful?
+-An 'add to bin/disk' function that loops over the scanned input
+Give a specific example of a "test case" for your new function.
+-Text file containing: 500001, 500002, 500003
+
+
+Extensibility
+
+What Code Smells can you find?
+-Redundancy, the print statements in the Bins main method are written twice and can instead be placed in their own method
+-Change preventers, the duplicate print statements would force you to modify two lines for a single desired change
+-The for loops are also the same and a function with a for loop could be used instead.
+What suggestions does this code make about how someone would extend it in the future to compare the performance of a wider variety of fitting algorithms?
+-Currently, in order to add more fitting algorithms, you would have to manually type in code within the main method. Instead, you could have the main method take in separate Java files corresponding to different fitting algorithms.
+What dependencies are there between different parts of the code?
+-You are forced to run both the in-order and decreasing methods one after the other
+-The Disk.java class is required for Bins.java to run
+How easy to find are those dependencies?
+-Difficult, you have to visually parse the code for instantiation of other classes
+Can you clarify or remove those dependencies?
+-These two different orders should be placed in separate methods to run independently
\ No newline at end of file
diff --git a/src/Bins.java b/src/Bins.java
index b313a3d..718431f 100644
--- a/src/Bins.java
+++ b/src/Bins.java
@@ -1,92 +1,102 @@
import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.PriorityQueue;
import java.util.Scanner;
+import java.util.function.Function;
+
+// small change
/**
* Runs a number of algorithms that try to fit files onto disks.
*/
public class Bins {
- public static final String DATA_FILE = "example.txt";
-
- /**
- * Reads list of integer data from the given input.
- *
- * @param input tied to an input source that contains space separated numbers
- * @return list of the numbers in the order they were read
- */
- public List readData (Scanner input) {
- List results = new ArrayList();
- while (input.hasNext()) {
- results.add(input.nextInt());
- }
- return results;
- }
-
- /**
- * The main program.
- */
- public static void main (String args[]) {
- Bins b = new Bins();
- Scanner input = new Scanner(Bins.class.getClassLoader().getResourceAsStream(DATA_FILE));
- List data = b.readData(input);
-
- PriorityQueue pq = new PriorityQueue();
- pq.add(new Disk(0));
-
- int diskId = 1;
- int total = 0;
- for (Integer size : data) {
- Disk d = pq.peek();
- if (d.freeSpace() > size) {
- pq.poll();
- d.add(size);
- pq.add(d);
- } else {
- Disk d2 = new Disk(diskId);
- diskId++;
- d2.add(size);
- pq.add(d2);
- }
- total += size;
- }
+ public static final String DATA_FILE = "example.txt";
- System.out.println("total size = " + total / 1000000.0 + "GB");
- System.out.println();
- System.out.println("worst-fit method");
- System.out.println("number of pq used: " + pq.size());
- while (!pq.isEmpty()) {
- System.out.println(pq.poll());
- }
- System.out.println();
+ /**
+ * Reads list of integer data from the given input.
+ *
+ * @param input tied to an input source that contains space separated numbers
+ * @return list of the numbers in the order they were read
+ */
+ public List readData (Scanner input) {
+ List results = new ArrayList();
+ while (input.hasNext()) {
+ results.add(input.nextInt());
+ }
+ return results;
+ }
+
+ public void fitDisksAndPrint(Function< List, List > function, List myList) {
+ List transformedFunction = function.apply(myList);
+ }
+
+ public List myReverse (List myList ) {
+ Collections.reverse(myList);
+ return myList;
+ }
+
+ // Add to collection of disks
+ public PriorityQueue addDisk(List myData) {
+ PriorityQueue pq = new PriorityQueue();
+ pq.add(new Disk(0));
- Collections.sort(data, Collections.reverseOrder());
- pq.add(new Disk(0));
+ int diskId = 1;
+ for (Integer size : myData) {
+ Disk d = pq.peek();
+ if (d.freeSpace() >= size) {
+ pq.poll();
+ d.add(size);
+ pq.add(d);
+ } else {
+ Disk d2 = new Disk(diskId);
+ diskId++;
+ d2.add(size);
+ pq.add(d2);
+ }
+ }
+ return pq;
+ }
+
+ // Returns total data size of files
+ public int getTotalData(List dataIn) {
+ int total = 0;
+ for (Integer elem: dataIn) {
+ total += elem;
+ }
+ return total;
+ }
+
+ // Print statistics
+ public void printStats(PriorityQueue myPQ) {
+ System.out.println();
+ System.out.println("worst-fit method");
+ System.out.println("number of pq used: " + myPQ.size());
+ while (!myPQ.isEmpty()) {
+ System.out.println(myPQ.poll());
+ }
+ System.out.println();
+ }
- diskId = 1;
- for (Integer size : data) {
- Disk d = pq.peek();
- if (d.freeSpace() >= size) {
- pq.poll();
- d.add(size);
- pq.add(d);
- } else {
- Disk d2 = new Disk(diskId);
- diskId++;
- d2.add(size);
- pq.add(d2);
- }
- }
+ /**
+ * The main program.
+ */
+ public static void main (String args[]) {
+ Bins b = new Bins();
+ Scanner input = new Scanner(Bins.class.getClassLoader().getResourceAsStream(DATA_FILE));
+ List data = b.readData(input);
+ System.out.println("total size = " + b.getTotalData(data) / 1000000.0 + "GB\n");
+ // In-order
+ b.printStats(b.addDisk(data));
+ // Decreasing order
+ Collections.sort(data, Collections.reverseOrder());
+ b.printStats(b.addDisk(data));
+ List places = new ArrayList(
+ Arrays.asList(1, 2, 3));
+ b.fitDisksAndPrint((t -> t.stream().sorted().collect(Collections::toList) ), places);
- System.out.println();
- System.out.println("worst-fit decreasing method");
- System.out.println("number of pq used: " + pq.size());
- while (!pq.isEmpty()) {
- System.out.println(pq.poll());
- }
- System.out.println();
- }
+ }
}