@Test public void testGetRanges() { List<Integer> list = Arrays.asList(1,2,3); List<Range<Integer>> rangeList = BatchUtil.getRanges(list, 1); assertEquals(3, rangeList.size()); assertEquals(Integer.valueOf(1), rangeList.get(0).getMin()); assertEquals(Integer.valueOf(1), rangeList.get(0).getMax()); assertEquals(Integer.valueOf(2), rangeList.get(1).getMin()); assertEquals(Integer.valueOf(2), rangeList.get(1).getMax()); assertEquals(Integer.valueOf(3), rangeList.get(2).getMin()); assertEquals(Integer.valueOf(3), rangeList.get(2).getMax()); list = Arrays.asList(1,2,3,4,5,6,7,8,9,10); rangeList = BatchUtil.getRanges(list, 3); assertEquals(4, rangeList.size()); assertEquals(Integer.valueOf(1), rangeList.get(0).getMin()); assertEquals(Integer.valueOf(3), rangeList.get(0).getMax()); assertEquals(Integer.valueOf(4), rangeList.get(1).getMin()); assertEquals(Integer.valueOf(6), rangeList.get(1).getMax()); assertEquals(Integer.valueOf(7), rangeList.get(2).getMin()); assertEquals(Integer.valueOf(9), rangeList.get(2).getMax()); assertEquals(Integer.valueOf(10), rangeList.get(3).getMin()); assertEquals(Integer.valueOf(10), rangeList.get(3).getMax()); rangeList = BatchUtil.getRanges(list, 17); assertEquals(1, rangeList.size()); assertEquals(Integer.valueOf(1), rangeList.get(0).getMin()); assertEquals(Integer.valueOf(10), rangeList.get(0).getMax()); }
public static <E extends Comparable<E>> List<Range<E>> getRanges(Collection<E> collection, int batchSize) { List<Range<E>> rangeList = new LinkedList<Range<E>>(); E currentMin = null; if ((collection != null) && (collection.size() > 0) && (batchSize > 0)) { int index = 1; for (E element : collection) { if (currentMin == null) { currentMin = element; } int mod = index % batchSize; if ((mod == 0) || (index == collection.size())) { Range<E> range = new Range<E>(currentMin, element); rangeList.add(range); currentMin = null; } index++; } } return rangeList; }
BatchUtil { public static <E extends Comparable<E>> List<Range<E>> getRanges(Collection<E> collection, int batchSize) { List<Range<E>> rangeList = new LinkedList<Range<E>>(); E currentMin = null; if ((collection != null) && (collection.size() > 0) && (batchSize > 0)) { int index = 1; for (E element : collection) { if (currentMin == null) { currentMin = element; } int mod = index % batchSize; if ((mod == 0) || (index == collection.size())) { Range<E> range = new Range<E>(currentMin, element); rangeList.add(range); currentMin = null; } index++; } } return rangeList; } }
BatchUtil { public static <E extends Comparable<E>> List<Range<E>> getRanges(Collection<E> collection, int batchSize) { List<Range<E>> rangeList = new LinkedList<Range<E>>(); E currentMin = null; if ((collection != null) && (collection.size() > 0) && (batchSize > 0)) { int index = 1; for (E element : collection) { if (currentMin == null) { currentMin = element; } int mod = index % batchSize; if ((mod == 0) || (index == collection.size())) { Range<E> range = new Range<E>(currentMin, element); rangeList.add(range); currentMin = null; } index++; } } return rangeList; }  }
BatchUtil { public static <E extends Comparable<E>> List<Range<E>> getRanges(Collection<E> collection, int batchSize) { List<Range<E>> rangeList = new LinkedList<Range<E>>(); E currentMin = null; if ((collection != null) && (collection.size() > 0) && (batchSize > 0)) { int index = 1; for (E element : collection) { if (currentMin == null) { currentMin = element; } int mod = index % batchSize; if ((mod == 0) || (index == collection.size())) { Range<E> range = new Range<E>(currentMin, element); rangeList.add(range); currentMin = null; } index++; } } return rangeList; }  static boolean shouldRetain(int i, int maxRetention, int length); static int getBatchCount(int length, int batchSize); static List<Range<E>> getRanges(Collection<E> collection,
      int batchSize); }
BatchUtil { public static <E extends Comparable<E>> List<Range<E>> getRanges(Collection<E> collection, int batchSize) { List<Range<E>> rangeList = new LinkedList<Range<E>>(); E currentMin = null; if ((collection != null) && (collection.size() > 0) && (batchSize > 0)) { int index = 1; for (E element : collection) { if (currentMin == null) { currentMin = element; } int mod = index % batchSize; if ((mod == 0) || (index == collection.size())) { Range<E> range = new Range<E>(currentMin, element); rangeList.add(range); currentMin = null; } index++; } } return rangeList; }  static boolean shouldRetain(int i, int maxRetention, int length); static int getBatchCount(int length, int batchSize); static List<Range<E>> getRanges(Collection<E> collection,
      int batchSize);  }