@Test public void createIntPartitionUnnormal() { int from = 0; int to = 102; int partitionCount = 4; int partitionSize = (to - from) / partitionCount; List<NumberRange.IntRange> ranges = NumberRange.partition(from, to, partitionCount); assertEquals(4, ranges.size()); List<int[]> expectedList = Lists.newArrayList( new int[] { 0, 26, 1, 26 }, new int[] { 26, 52, 1, 26 }, new int[] { 52, 77, 1, 25 }, new int[] { 77, 102, 1, 25 }); for (int i = 0; i < partitionCount; i++) { NumberRange.IntRange intRange = ranges.get(i); int[] expected = expectedList.get(i); if (log.isDebugEnabled()) log.debug("NumberRange({})=[{}]", i, intRange); assertEquals(expected[0], intRange.getFromInclude()); assertEquals(expected[1], intRange.getToExclude()); assertEquals(expected[2], intRange.getStep()); assertEquals(expected[3], intRange.size()); } }
public static List<IntRange> partition(IntRange range, int partitionCount) { if (isTraceEnabled) log.trace("partition... range=[{}], partitionCount=[{}]", range, partitionCount); int rangeSize = range.size(); int stepSign = range.getStep(); int step = range.getStep(); int partitionSize = rangeSize / partitionCount; int remainder = rangeSize % partitionCount; List<IntRange> partitions = Lists.newLinkedList(); int fromInclude = range.fromInclude; for (int i = 0; i < partitionCount; i++) { int toExclude = fromInclude + (partitionSize + ((remainder > 0) ? 1 : 0)) * stepSign; if (remainder > 0) remainder--; toExclude = (step > 0) ? Math.min(toExclude, range.getToExclude()) : Math.max(toExclude, range.getToExclude()); IntRange partition = range(fromInclude, toExclude, step); partitions.add(partition); fromInclude = toExclude; if (isTraceEnabled) log.trace("Partition 추가 = [{}]", partition); } return partitions; }
NumberRange implements Iterable<T> { public static List<IntRange> partition(IntRange range, int partitionCount) { if (isTraceEnabled) log.trace("partition... range=[{}], partitionCount=[{}]", range, partitionCount); int rangeSize = range.size(); int stepSign = range.getStep(); int step = range.getStep(); int partitionSize = rangeSize / partitionCount; int remainder = rangeSize % partitionCount; List<IntRange> partitions = Lists.newLinkedList(); int fromInclude = range.fromInclude; for (int i = 0; i < partitionCount; i++) { int toExclude = fromInclude + (partitionSize + ((remainder > 0) ? 1 : 0)) * stepSign; if (remainder > 0) remainder--; toExclude = (step > 0) ? Math.min(toExclude, range.getToExclude()) : Math.max(toExclude, range.getToExclude()); IntRange partition = range(fromInclude, toExclude, step); partitions.add(partition); fromInclude = toExclude; if (isTraceEnabled) log.trace("Partition 추가 = [{}]", partition); } return partitions; } }
NumberRange implements Iterable<T> { public static List<IntRange> partition(IntRange range, int partitionCount) { if (isTraceEnabled) log.trace("partition... range=[{}], partitionCount=[{}]", range, partitionCount); int rangeSize = range.size(); int stepSign = range.getStep(); int step = range.getStep(); int partitionSize = rangeSize / partitionCount; int remainder = rangeSize % partitionCount; List<IntRange> partitions = Lists.newLinkedList(); int fromInclude = range.fromInclude; for (int i = 0; i < partitionCount; i++) { int toExclude = fromInclude + (partitionSize + ((remainder > 0) ? 1 : 0)) * stepSign; if (remainder > 0) remainder--; toExclude = (step > 0) ? Math.min(toExclude, range.getToExclude()) : Math.max(toExclude, range.getToExclude()); IntRange partition = range(fromInclude, toExclude, step); partitions.add(partition); fromInclude = toExclude; if (isTraceEnabled) log.trace("Partition 추가 = [{}]", partition); } return partitions; } private  NumberRange(); }
NumberRange implements Iterable<T> { public static List<IntRange> partition(IntRange range, int partitionCount) { if (isTraceEnabled) log.trace("partition... range=[{}], partitionCount=[{}]", range, partitionCount); int rangeSize = range.size(); int stepSign = range.getStep(); int step = range.getStep(); int partitionSize = rangeSize / partitionCount; int remainder = rangeSize % partitionCount; List<IntRange> partitions = Lists.newLinkedList(); int fromInclude = range.fromInclude; for (int i = 0; i < partitionCount; i++) { int toExclude = fromInclude + (partitionSize + ((remainder > 0) ? 1 : 0)) * stepSign; if (remainder > 0) remainder--; toExclude = (step > 0) ? Math.min(toExclude, range.getToExclude()) : Math.max(toExclude, range.getToExclude()); IntRange partition = range(fromInclude, toExclude, step); partitions.add(partition); fromInclude = toExclude; if (isTraceEnabled) log.trace("Partition 추가 = [{}]", partition); } return partitions; } private  NumberRange(); static IntRange range(int fromInclude, int toExclude, int step); static IntRange range(int fromInclude, int toExclude); static IntRange range(int count); static LongRange range(long fromInclude, long toExclude, long step); static LongRange range(long fromInclude, long toExclude); static LongRange range(long count); static List<IntRange> partition(IntRange range, int partitionCount); static List<IntRange> partition(int fromInclude, int toExclude, int step, int partitionCount); static List<IntRange> partition(int fromInclude, int toExclude, int partitionCount); static List<IntRange> partition(int count, int partitionCount); static List<LongRange> partition(LongRange range, int partitionCount); static List<LongRange> partition(long fromInclude, long toExclude, int step, int partitionCount); static List<LongRange> partition(long fromInclude, long toExclude, int partitionCount); static List<LongRange> partition(long count, int partitionCount); }
NumberRange implements Iterable<T> { public static List<IntRange> partition(IntRange range, int partitionCount) { if (isTraceEnabled) log.trace("partition... range=[{}], partitionCount=[{}]", range, partitionCount); int rangeSize = range.size(); int stepSign = range.getStep(); int step = range.getStep(); int partitionSize = rangeSize / partitionCount; int remainder = rangeSize % partitionCount; List<IntRange> partitions = Lists.newLinkedList(); int fromInclude = range.fromInclude; for (int i = 0; i < partitionCount; i++) { int toExclude = fromInclude + (partitionSize + ((remainder > 0) ? 1 : 0)) * stepSign; if (remainder > 0) remainder--; toExclude = (step > 0) ? Math.min(toExclude, range.getToExclude()) : Math.max(toExclude, range.getToExclude()); IntRange partition = range(fromInclude, toExclude, step); partitions.add(partition); fromInclude = toExclude; if (isTraceEnabled) log.trace("Partition 추가 = [{}]", partition); } return partitions; } private  NumberRange(); static IntRange range(int fromInclude, int toExclude, int step); static IntRange range(int fromInclude, int toExclude); static IntRange range(int count); static LongRange range(long fromInclude, long toExclude, long step); static LongRange range(long fromInclude, long toExclude); static LongRange range(long count); static List<IntRange> partition(IntRange range, int partitionCount); static List<IntRange> partition(int fromInclude, int toExclude, int step, int partitionCount); static List<IntRange> partition(int fromInclude, int toExclude, int partitionCount); static List<IntRange> partition(int count, int partitionCount); static List<LongRange> partition(LongRange range, int partitionCount); static List<LongRange> partition(long fromInclude, long toExclude, int step, int partitionCount); static List<LongRange> partition(long fromInclude, long toExclude, int partitionCount); static List<LongRange> partition(long count, int partitionCount);  }