diff --git a/README.md b/README.md index 0103fbf..1bc8ab7 100644 --- a/README.md +++ b/README.md @@ -5,3 +5,6 @@ Making a change!!! Even more changes :) + +I am changing the readme + diff --git a/src/Bins.java b/src/Bins.java index b313a3d..70ea535 100644 --- a/src/Bins.java +++ b/src/Bins.java @@ -1,10 +1,16 @@ import java.io.File; import java.io.FileNotFoundException; import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; 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; + +import com.sun.xml.internal.bind.v2.runtime.unmarshaller.XsiNilLoader.Array; /** * Runs a number of algorithms that try to fit files onto disks. @@ -31,62 +37,88 @@ public List readData (Scanner input) { */ 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)); + b.go(); + } + /** + * + */ + public void go(){ + Scanner input = new Scanner(Bins.class.getClassLoader().getResourceAsStream(DATA_FILE)); + List data = this.readData(input); + PriorityQueue pq = new PriorityQueue(); + worstFitDecreasing(pq, data); + worstFit(pq, data); + Integer [] nums = {1, 2, 3, 4, 5, 6, 7, 8}; + List toTransform = Arrays.asList(nums); + fitDisksAndPrint(toTransform, (in) -> in.stream() + .filter((elem) -> elem%2 == 0).collect(Collectors.toList())); + + } + + public void fitDisksAndPrint(List toTransform, Function, List> func){ + List transformed = func.apply(toTransform); + transformed.forEach(System.out::println); + + } - 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 void worstFitDecreasing(PriorityQueue pq, List data){ + Collections.sort(data, Collections.reverseOrder()); + pq.add(new Disk(0)); - 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(); + int 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); + } + } - Collections.sort(data, Collections.reverseOrder()); - pq.add(new Disk(0)); + 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(); + } + + public void worstFit (PriorityQueue pq, List data ) { + //algo + + pq.add(new Disk(0)); - 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); - } - } + 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; + } - 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(); - } + 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(); + } + }