JSONObject filterJsonObj = getPagedResult(allPortList, pageIndex,
pageCount, searchContext);
List<NetworkDeviceInterfacePojo> portList = (List<NetworkDeviceInterfacePojo>) filterJsonObj
.get("list");
private JSONObject getPagedResult(
List<NetworkDeviceInterfacePojo> allPortList, int pageIndex,
int pageCount, String searchContext) {
List<NetworkDeviceInterfacePojo> pagedResult = new ArrayList<NetworkDeviceInterfacePojo>();
List<NetworkDeviceInterfacePojo> searchResult = new ArrayList<NetworkDeviceInterfacePojo>();
if (!StringUtils.isEmpty(searchContext)) {
searchContext = searchContext.toUpperCase();
for (NetworkDeviceInterfacePojo p : allPortList) {
if (!StringUtils.isEmpty(p.getName())
&& p.getName().toUpperCase().contains(searchContext)) {
searchResult.add(p);
}
}
} else {
searchResult.addAll(allPortList);
}
int firstNumber = (pageIndex - 1) * pageCount;
int lastNumber = pageIndex * pageCount;
for (int i = 0; i < searchResult.size(); i++) {
if (i >= firstNumber && i < lastNumber) {
pagedResult.add(searchResult.get(i));
}
}
JSONObject obj = new JSONObject();
obj.put("list", pagedResult);
obj.put("total", searchResult.size());
return obj;
}