ApplicationExporter { public static <T> Set<List<T>> partition(List<T> _list, int _num) throws IllegalArgumentException { final Set<List<T>> parts = new HashSet<List<T>>(); if (_num < 1) throw new IllegalArgumentException( "Number of partitions must be greater than 0 but is [" + _num + "]"); else if (_list == null) ; else if (_list.size() < _num) parts.add(_list); else { final int size = (int) Math.floor((double) _list.size() / (double) _num); int i, min, max; for (i = 0; i < _num - 1; i++) { min = i * size; max = Math.min((i + 1) * size, _list.size()); if (max >= min) { parts.add(_list.subList(min, max)); } } min = i * size; max = Math.min((_num + 1) * size, _list.size()); if (max >= min) { parts.add(_list.subList(min, max)); } } return parts; }  synchronized void produceExportAsync(
      final Tenant _tenant,
      final Space _space,
      final String separator,
      final String[] includeSpaceProperties,
      final String[] includeGoalConfiguration,
      final String[] includeGoalSystemInfo,
      final String[] _selected_bugs,
      final boolean _incl_all_bugs,
      final boolean _incl_exemptions,
      final ExportFormat _format,
      final Message _msg); @Transactional synchronized Path produceExport(
      Tenant _tenant,
      Space _space,
      String separator,
      String[] includeSpaceProperties,
      String[] includeGoalConfiguration,
      String[] includeGoalSystemInfo,
      String[] _selected_bugs,
      boolean _incl_all_bugs,
      boolean _incl_exemptions,
      ExportFormat _format); static Set<List<T>> partition(List<T> _list, int _num);  }
@Test public void testPartition() { Set<List<Integer>> parts = ApplicationExporter.partition(this.createList(10), 1); int num = 0; assertEquals(1, parts.size()); assertEquals(10, parts.iterator().next().size()); parts = ApplicationExporter.partition(null, 10); num = 0; assertEquals(0, parts.size()); for (List<Integer> part : parts) { assertTrue(false); } assertEquals(0, num); parts = ApplicationExporter.partition(this.createList(0), 10); num = 0; assertEquals(1, parts.size()); for (List<Integer> part : parts) { assertTrue(part.size() == 0); num += part.size(); } assertEquals(0, num); parts = ApplicationExporter.partition(this.createList(1), 10); num = 0; assertEquals(1, parts.size()); for (List<Integer> part : parts) { assertTrue(part.size() == 1); num += part.size(); } assertEquals(1, num); parts = ApplicationExporter.partition(this.createList(2), 10); num = 0; assertEquals(1, parts.size()); for (List<Integer> part : parts) { assertTrue(part.size() == 2); num += part.size(); } assertEquals(2, num); parts = ApplicationExporter.partition(this.createList(10), 10); num = 0; assertEquals(10, parts.size()); for (List<Integer> part : parts) { assertTrue(part.size() == 1); num += part.size(); } assertEquals(10, num); parts = ApplicationExporter.partition(this.createList(10), 5); num = 0; assertEquals(5, parts.size()); for (List<Integer> part : parts) { assertTrue(part.size() == 2); num += part.size(); } assertEquals(10, num); parts = ApplicationExporter.partition(this.createList(11), 5); num = 0; assertEquals(5, parts.size()); for (List<Integer> part : parts) { assertTrue(part.size() == 2 || part.size() == 3); num += part.size(); } assertEquals(11, num); parts = ApplicationExporter.partition(this.createList(12), 5); num = 0; assertEquals(5, parts.size()); for (List<Integer> part : parts) { assertTrue(part.size() == 2 || part.size() == 4); num += part.size(); } assertEquals(12, num); parts = ApplicationExporter.partition(this.createList(1130), 40); num = 0; assertEquals(40, parts.size()); for (List<Integer> part : parts) { assertTrue(part.size() == 28 || part.size() == 38); num += part.size(); } assertEquals(1130, num); }