Pagination is the process of dividing content into discrete pages. Pagination is common in Web-based applications, and is used for limiting the result set and displaying a limited number of records on the web page.
E.g.:
Consider the Department-Employee scenario. If the search operation is performed on the basis of Department Id, and there are 100,000 employees per department, then it does not make sense to display the details of 100,000 employees in single page. So, pagination allows to display limited results e.g. 20 records per page. "Previous" and "Next" links or the Page numbers are usually provided on the user interface so that users can navigate to other pages.
Write a program for selecting the records that need to be displayed on user interface. Records should be filtered as per the input parameters, and should be sorted by Employee Name. Requirement is to ensure faster initial page load.
Your program should extract the records from this file on the basis of input parameters. For example, if the input is (Department ID-10, Page Size-20, and Page Number -1), then the program should retrieve first set of 20 records for Department ID-10 sorted by employee name. If the input is (Department ID-10, Page Size-20, and Page Number -2), then the program should retrieve second set of 20 records. As the data for a given department will be sorted by employee name, there will be no overlapping between first page and second page.
Asumptions:
->Input file data may or may not be sorted by Department and Employee ID
->Expected Volumes: Department Data File may have approx. 100,000 records per department ID. Page Size is expected to be less than 100 records.
Input Format:
Line 1
|
Absolute file path |
Line 2
|
D,S,N
where
D,S,N
->Department ID (D) is search Parameter
->Page Size (S) is number of records that need to be displayed on UI e.g. 20
->Page Number(N) is the number of Page which should be displayed e.g. 2 (2nd Page to be displayed) |
File Format:
Number of Columns-3
Order of Column -DEPT_ID,EMP_ID ,EMP_NAME
Columns delimited by comma(,)
Example Department Data File:
DEPT_ID,EMP_ID,EMP_NAME,GRADE
1,1,Smith Frank
1,2,Manager Mike
1,3,Driver Danny
2,7,Bliss
2,8,Java
2,9,Kyte Kelly
1,4,Boat Tony
2,5,Louie Chef
2,6,Lawson
2,10,Baker Sarah
2,11,Smothers Sally
2,12,Silly Sall
2,13,Viper
2,14,Beck
2,15,Rambo
Note:
Department Data file above is provided to help you visualize how the input file will look like. Your program should only accept name of the file as input.
Output:
Output of the program will be the filtered records that need to be displayed on UI (User Interface). Records should be sorted by Employee Names and should be filtered as per the input parameters.
Sample Test Cases:
SNo. |
Input |
Output |
1 |
Page.csv
2,3,1 |
2,14,Beck
2,7,Bliss
2,8,Java |
2 |
Page.csv
1,4,1 |
1,3,Driver Danny
1,4,Boat Tony
1,2,Manager Mike
1,1,Smith Frank |
3 |
Page.csv
2,5,3 |
2,11,Smothers Sally
2,13,Viper |
4 |
Page.csv
1,3,2,1 |
Invalid Input |
5 |
Page.csv
2,3,5 |
Data Unavailable |