Created
August 23, 2019 11:55
-
-
Save KryptKode/e8ffe5f5548497ca969e83f4c6d27844 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object PositionUtil { | |
fun computePositionalDataSourceEquivalent(position:Int, totalCount: Int): Int { | |
val pageSize = DataSource.PAGE_SIZE //DataSource.PAGE_SIZE is the requested page size | |
val initialLoadSize = DataSource.PAGE_SIZE * 3 //Default loadSize is 3 times the requested load size | |
var pageStart = position / pageSize * pageSize | |
// maximum start pos is that which will encompass end of list | |
val maximumLoadPage = (totalCount - initialLoadSize + pageSize - 1) / pageSize * pageSize | |
pageStart = Math.min(maximumLoadPage, pageStart) | |
// minimum start position is 0 | |
pageStart = Math.max(0, pageStart) | |
return pageStart | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment