@Test void packagerCanBeInterruptedWithAFunction() throws InterruptedException { final Container container = new ValidatingContainer("", 1000, 1500, 3200, 0); final List<Container> singleContainer = Collections.singletonList(container); final BruteForcePackager bruteForcePackager = new BruteForcePackager(singleContainer); final LargestAreaFitFirstPackager largestAreaFitFirstPackager = new LargestAreaFitFirstPackager(container.rotations()); final AtomicBoolean laffFinishedBool = new AtomicBoolean(false); final AtomicBoolean bruteForceFinishedBool = new AtomicBoolean(false); final long start = System.currentTimeMillis(); BooleanSupplier deadlineReached = () -> System.currentTimeMillis() > start + 1000; BooleanSupplier interruptLaff = () -> deadlineReached.getAsBoolean() || bruteForceFinishedBool.get(); BooleanSupplier interruptBruteForce = () -> deadlineReached.getAsBoolean() || laffFinishedBool.get(); new Thread(() -> { final Container pack = bruteForcePackager.pack(listOf28Products(), interruptBruteForce); bruteForceFinishedBool.set(pack != null); }).start(); new Thread(() -> { final Container pack = largestAreaFitFirstPackager.pack(listOf28Products(), interruptLaff); laffFinishedBool.set(pack != null); }).start(); Thread.sleep(100); assertTrue(laffFinishedBool.get()); assertFalse(bruteForceFinishedBool.get()); }
public Container pack(List<BoxItem> boxes) { return pack(boxes, Long.MAX_VALUE); }
Packager { public Container pack(List<BoxItem> boxes) { return pack(boxes, Long.MAX_VALUE); } }
Packager { public Container pack(List<BoxItem> boxes) { return pack(boxes, Long.MAX_VALUE); } Packager(List<Container> containers);  Packager(List<Container> containers, boolean rotate3D, boolean binarySearch, int checkpointsPerDeadlineCheck); }
Packager { public Container pack(List<BoxItem> boxes) { return pack(boxes, Long.MAX_VALUE); } Packager(List<Container> containers);  Packager(List<Container> containers, boolean rotate3D, boolean binarySearch, int checkpointsPerDeadlineCheck); Container pack(List<BoxItem> boxes); Container pack(List<BoxItem> boxes, long deadline); Container pack(List<BoxItem> boxes, BooleanSupplier interrupt); Container pack(List<BoxItem> boxes, long deadline, BooleanSupplier interrupt); Container pack(List<BoxItem> boxes, List<Container> containers, long deadline); Container pack(List<BoxItem> boxes, List<Container> containers, long deadline, BooleanSupplier interrupt); Container pack(List<BoxItem> boxes, List<Container> containers, BooleanSupplier interrupt); List<Container> packList(List<BoxItem> boxes, int limit, long deadline); List<Container> packList(List<BoxItem> boxes, int limit, long deadline, BooleanSupplier interrupt); List<Container> packList(List<BoxItem> boxes, int limit, BooleanSupplier interrupt); }
Packager { public Container pack(List<BoxItem> boxes) { return pack(boxes, Long.MAX_VALUE); } Packager(List<Container> containers);  Packager(List<Container> containers, boolean rotate3D, boolean binarySearch, int checkpointsPerDeadlineCheck); Container pack(List<BoxItem> boxes); Container pack(List<BoxItem> boxes, long deadline); Container pack(List<BoxItem> boxes, BooleanSupplier interrupt); Container pack(List<BoxItem> boxes, long deadline, BooleanSupplier interrupt); Container pack(List<BoxItem> boxes, List<Container> containers, long deadline); Container pack(List<BoxItem> boxes, List<Container> containers, long deadline, BooleanSupplier interrupt); Container pack(List<BoxItem> boxes, List<Container> containers, BooleanSupplier interrupt); List<Container> packList(List<BoxItem> boxes, int limit, long deadline); List<Container> packList(List<BoxItem> boxes, int limit, long deadline, BooleanSupplier interrupt); List<Container> packList(List<BoxItem> boxes, int limit, BooleanSupplier interrupt);  }