public List < E > get ( int index ) { /*log.fine("public List<E> get(int index): called");*/ // Check that the index is not to large. int originalSize = original . size ( ) ; int size = ( originalSize / pageSize ) + ( ( ( originalSize % pageSize ) == 0 ) ? 0 : 1 ) ; /*log.fine("originalSize = " + originalSize);*/ /*log.fine("size = " + size);*/ // Check if the size of the underlying list is zero, in which case return an empty list, so long as page zero // was requested. if ( ( index == 0 ) && ( originalSize == 0 ) ) { return new ArrayList < E > ( ) ; } // Check if the requested index exceeds the number of pages, or is an illegal negative value. if ( ( index >= size ) || ( index < 0 ) ) { /*log.fine("(index >= size) || (index < 0), throwing out of bounds exception.");*/ throw new IndexOutOfBoundsException ( "Index " + index + " is less than zero or more than the number of pages: " + size ) ; } // Extract the appropriate sub-list. // Note that if this is the last page it may not be a full page. Just up to the last page will be returned. /*log.fine("Requesting sublist from, " + (pageSize * index) + ", to ," + (((pageSize * (index + 1)) >= originalSize) ? originalSize : (pageSize * (index + 1))) + ".");*/ List < E > result = original . subList ( pageSize * index , ( ( pageSize * ( index + 1 ) ) >= originalSize ) ? originalSize : ( pageSize * ( index + 1 ) ) ) ; return result ; }
Extracts the sub - list at the specified page index . The returned list will have size equal to the page size unless it is the last page in which case it may not be a full page .