Advertisement
Guest User

esrdtyfg

a guest
Apr 10th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 1.19 KB | None | 0 0
  1. public class OffsetLimit
  2. {
  3.     private Integer offset;
  4.     private Integer limit;
  5.    
  6.     public OffsetLimit( Integer offset, Integer limit )
  7.     {
  8.         this.offset = offset;
  9.         this.limit = limit;
  10.     }
  11.    
  12.     public Integer getOffset()
  13.     {
  14.         return this.offset;
  15.     }
  16.    
  17.     public void setOffset( Integer offset )
  18.     {
  19.         this.offset = offset;
  20.     }
  21.    
  22.     public Integer getLimit()
  23.     {
  24.         return this.limit;
  25.     }
  26.    
  27.     public void setLimit( Integer limit )
  28.     {
  29.         this.limit = limit;
  30.     }
  31.    
  32.     @Override
  33.     public String toString()
  34.     {
  35.         return "OffsetLimit{" + "offset=" + this.offset + ", limit=" + this.limit + '}';
  36.     }
  37. }
  38.  
  39. public class OffsetLimitManager
  40. {
  41.     /**
  42.      *
  43.      * @param totalCount
  44.      * @param batchSize
  45.      * @return List<OffsetLimit>
  46.      */
  47.     public static List<OffsetLimit> getBatchRanges( int totalCount, int batchSize )
  48.     {
  49.         List<OffsetLimit> batchRanges = new ArrayList<>();
  50.        
  51.         int tabSize = 0;
  52.         while ( totalCount >= batchSize )
  53.         {
  54.             batchRanges.add( new OffsetLimit( batchSize * tabSize++, batchSize ) );
  55.             totalCount -= batchSize;
  56.         }
  57.        
  58.         if ( totalCount != 0 )
  59.         {
  60.             batchRanges.add( new OffsetLimit( batchSize * tabSize, totalCount ) );
  61.         }
  62.        
  63.         return batchRanges;
  64.     }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement