package ba.aljovic.amer.batch.chunk;

import ba.aljovic.amer.utils.Utils;
import org.springframework.batch.core.partition.support.Partitioner;
import org.springframework.batch.item.ExecutionContext;

import java.util.HashMap;
import java.util.Map;

public class RangePartitioner implements Partitioner
{
    private Integer fromId;
    private Integer range;

    public RangePartitioner(Integer fromId, Integer range)
    {
        this.fromId = fromId;
        this.range = range;
    }

    @Override
    public Map<String, ExecutionContext> partition(int gridSize)
    {
        Map<String, ExecutionContext> result = new HashMap<>();
        for (int i = 1; i <= gridSize; i++)
        {
            Integer toId = fromId + range - 1;

            ExecutionContext value = new ExecutionContext();
            value.putInt(Utils.FROM_ID, fromId);
            value.putInt(Utils.TO_ID, toId);
            value.putString("name", "Thread" + i);
            result.put("partition" + i, value);

            fromId += range;
        }
        return result;
    }
}

@@ -583,32 +583,62 @@
 idSize)%0D%0A    %7B%0D%0A
+        assert gridSize %3E 0;%0D%0A
         Map%3CStri

Assert that number of threads for partitioner is minimum 1.