Skip to content

Commit 1e359f8

Browse files
authored
Merge pull request #364 from bloxbean/360-koios-koios-utxoservice-throwing-error-during-simple-transaction
#360 fixed getSubListByPage.
2 parents c381bac + 51e0d77 commit 1e359f8

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

backend-modules/koios/src/main/java/com/bloxbean/cardano/client/backend/koios/KoiosUtxoService.java

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,24 +129,35 @@ private Result<List<Utxo>> convertToUTxOs(String address, List<AddressUtxo> utxo
129129
return Result.success("OK").withValue(utxoList).code(200);
130130
}
131131

132+
/**
133+
* Returns sublist of a page. If a page is empty and emptyList will be returned.
134+
* @param list
135+
* @param pageNumber
136+
* @param pageSize
137+
* @return
138+
*/
132139
public static List<AddressUtxo> getSubListByPage(List<AddressUtxo> list, int pageNumber, int pageSize) {
133140
int start = 0;
134141
int end;
135142

136-
if (pageNumber >= 0) {
143+
if (pageNumber > 0) {
137144
start = pageSize * (pageNumber - 1);
138-
145+
} else if(pageNumber <= 0) {
146+
return Collections.emptyList();
139147
}
140148
if (pageSize > 0) {
141149
end = start + pageSize;
142150
} else {
143151
end = start;
144152
}
145153
if (list.size() < end + 1) {
146-
end = list.size() - 1;
154+
end = list.size();
147155
}
148-
end = Math.max(end, 0);
149-
return list.subList(start, end);
150156

157+
if(end < start) {
158+
return Collections.emptyList();
159+
} else {
160+
return list.subList(start, end);
161+
}
151162
}
152163
}

0 commit comments

Comments
 (0)