Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class OffsetLimit
- {
- private Integer offset;
- private Integer limit;
- public OffsetLimit( Integer offset, Integer limit )
- {
- this.offset = offset;
- this.limit = limit;
- }
- public Integer getOffset()
- {
- return this.offset;
- }
- public void setOffset( Integer offset )
- {
- this.offset = offset;
- }
- public Integer getLimit()
- {
- return this.limit;
- }
- public void setLimit( Integer limit )
- {
- this.limit = limit;
- }
- @Override
- public String toString()
- {
- return "OffsetLimit{" + "offset=" + this.offset + ", limit=" + this.limit + '}';
- }
- }
- public class OffsetLimitManager
- {
- /**
- *
- * @param totalCount
- * @param batchSize
- * @return List<OffsetLimit>
- */
- public static List<OffsetLimit> getBatchRanges( int totalCount, int batchSize )
- {
- List<OffsetLimit> batchRanges = new ArrayList<>();
- int tabSize = 0;
- while ( totalCount >= batchSize )
- {
- batchRanges.add( new OffsetLimit( batchSize * tabSize++, batchSize ) );
- totalCount -= batchSize;
- }
- if ( totalCount != 0 )
- {
- batchRanges.add( new OffsetLimit( batchSize * tabSize, totalCount ) );
- }
- return batchRanges;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement