Skip to content

Commit

Permalink
Merge pull request #364 from bloxbean/360-koios-koios-utxoservice-thr…
Browse files Browse the repository at this point in the history
…owing-error-during-simple-transaction

#360 fixed getSubListByPage.
  • Loading branch information
satran004 authored Jan 23, 2024
2 parents c381bac + 51e0d77 commit 1e359f8
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 1e359f8

Please sign in to comment.