### Question:
FreeSegmentsUtil { public static List<Vector> removeSegment(List<Vector> freeSegments, Vector occupiedSegment) { List<Vector> res = new ArrayList<>(); for (Vector seg: freeSegments) { if (seg.y <= occupiedSegment.x || seg.x >= occupiedSegment.y) { res.add(seg); } else { if (seg.x <= occupiedSegment.x) { res.add(new Vector(seg.x, occupiedSegment.x)); } if (occupiedSegment.y <= seg.y) { res.add(new Vector(occupiedSegment.y, seg.y)); } } } return res; }  static List<Vector> removeSegment(List<Vector> freeSegments, Vector occupiedSegment);  }### Answer:
@Test public void notIntersecting() { List<Vector> seg = new ArrayList<>(); seg.add(new Vector(0, 10)); List<Vector> res = FreeSegmentsUtil.removeSegment(seg, new Vector(-10, 0)); assertTrue(res.size() == 1); assertEquals(new Vector(0, 10), res.get(0)); res = FreeSegmentsUtil.removeSegment(seg, new Vector(10, 100)); assertTrue(res.size() == 1); assertEquals(new Vector(0, 10), res.get(0)); }
@Test public void occupiedPoint() { List<Vector> seg = new ArrayList<>(); seg.add(new Vector(0, 10)); List<Vector> res = FreeSegmentsUtil.removeSegment(seg, new Vector(5, 5)); assertTrue(res.size() == 2); assertEquals(new Vector(0, 5), res.get(0)); assertEquals(new Vector(5, 10), res.get(1)); }
@Test public void occupiedIntersectsMany() { List<Vector> seg = new ArrayList<>(); seg.add(new Vector(0, 2)); seg.add(new Vector(4, 6)); seg.add(new Vector(8, 10)); List<Vector> res = FreeSegmentsUtil.removeSegment(seg, new Vector(1, 9)); assertTrue(res.size() == 2); assertEquals(new Vector(0, 1), res.get(0)); assertEquals(new Vector(9, 10), res.get(1)); }