Refactor ResultInfo to use Java record
Replaced the ResultInfo class with a Java record for conciseness and immutability. Adjusted related validation logic and method calls to align with the new record structure. Minor updates to Javadoc documentation were also included.
This commit is contained in:
@@ -43,11 +43,11 @@ class ResponseValidator {
|
||||
private void validateResultCount(AbstractResponse resp, boolean singleResultExpected)
|
||||
throws CloudflareApiException {
|
||||
if (resp instanceof RecordMultipleResponse respMulti) {
|
||||
if (singleResultExpected && respMulti.getResultInfo().getTotalCount() > 1) {
|
||||
if (singleResultExpected && respMulti.getResultInfo().totalCount() > 1) {
|
||||
throw new CloudflareApiException(
|
||||
"Unexpected result count: " + respMulti.getResultInfo().getTotalCount());
|
||||
"Unexpected result count: " + respMulti.getResultInfo().totalCount());
|
||||
}
|
||||
if (emptyResultThrowsException && respMulti.getResultInfo().getTotalCount() == 0) {
|
||||
if (emptyResultThrowsException && respMulti.getResultInfo().totalCount() == 0) {
|
||||
throw new CloudflareNotFoundException("No result found");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
package codes.thischwa.cf.model;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* Represents metadata for paginated results.
|
||||
*
|
||||
@@ -16,11 +14,16 @@ import lombok.Data;
|
||||
* <li><b>totalCount:</b> The total number of results across all pages.
|
||||
* </ul>
|
||||
*/
|
||||
@Data
|
||||
public class ResultInfo {
|
||||
private int page;
|
||||
private int perPage;
|
||||
private int totalPages;
|
||||
private int count;
|
||||
private int totalCount;
|
||||
|
||||
public record ResultInfo(int page, int perPage, int totalPages, int count, int totalCount) {
|
||||
|
||||
/**
|
||||
* Constructs a ResultInfo instance with the specified total count and default values for other
|
||||
* fields. Just to use in tests!
|
||||
*
|
||||
* @param totalCount the total number of results across all pages
|
||||
*/
|
||||
public ResultInfo(int totalCount) {
|
||||
this(0, 0, 0, 0, totalCount);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user