Skip to content

Commit

Permalink
#360 fixed getSubListByPage. Error occured when page > 1 was requeste…
Browse files Browse the repository at this point in the history
…d, but not enough elements are available. So page 2 must be empty for example.
  • Loading branch information
Kammerlo committed Jan 22, 2024
1 parent c381bac commit 51e0d77
Showing 1 changed file with 16 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -129,24 +129,35 @@ private Result<List<Utxo>> convertToUTxOs(String address, List<AddressUtxo> utxo
return Result.success("OK").withValue(utxoList).code(200);
}

/**
* Returns sublist of a page. If a page is empty and emptyList will be returned.
* @param list
* @param pageNumber
* @param pageSize
* @return
*/
public static List<AddressUtxo> getSubListByPage(List<AddressUtxo> list, int pageNumber, int pageSize) {
int start = 0;
int end;

if (pageNumber >= 0) {
if (pageNumber > 0) {
start = pageSize * (pageNumber - 1);

} else if(pageNumber <= 0) {
return Collections.emptyList();
}
if (pageSize > 0) {
end = start + pageSize;
} else {
end = start;
}
if (list.size() < end + 1) {
end = list.size() - 1;
end = list.size();
}
end = Math.max(end, 0);
return list.subList(start, end);

if(end < start) {
return Collections.emptyList();
} else {
return list.subList(start, end);
}
}
}

0 comments on commit 51e0d77

Please sign in to comment.