|
5 | 5 | import static java.util.Map.entry;
|
6 | 6 | import static java.util.Objects.nonNull;
|
7 | 7 | import static java.util.Objects.requireNonNull;
|
| 8 | +import static java.util.Optional.empty; |
8 | 9 | import static java.util.Optional.ofNullable;
|
9 | 10 | import static java.util.stream.Collectors.toUnmodifiableMap;
|
10 | 11 | import static org.usf.jquery.core.SqlStringBuilder.quote;
|
11 | 12 | import static org.usf.jquery.core.Utils.isEmpty;
|
12 | 13 | import static org.usf.jquery.core.Validation.requireLegalVariable;
|
| 14 | +import static org.usf.jquery.core.Validation.requireNArgs; |
13 | 15 | import static org.usf.jquery.web.ColumnMetadata.columnMetadata;
|
14 | 16 | import static org.usf.jquery.web.ContextManager.currentContext;
|
15 | 17 | import static org.usf.jquery.web.NoSuchResourceException.undeclaredResouceException;
|
16 | 18 | import static org.usf.jquery.web.Parameters.COLUMN;
|
17 | 19 | import static org.usf.jquery.web.Parameters.COLUMN_DISTINCT;
|
18 |
| -import static org.usf.jquery.web.Parameters.OFFSET; |
19 | 20 | import static org.usf.jquery.web.Parameters.JOIN;
|
20 | 21 | import static org.usf.jquery.web.Parameters.LIMIT;
|
| 22 | +import static org.usf.jquery.web.Parameters.OFFSET; |
21 | 23 | import static org.usf.jquery.web.Parameters.ORDER;
|
22 | 24 | import static org.usf.jquery.web.Parameters.VIEW;
|
23 | 25 | import static org.usf.jquery.web.RequestParser.parseEntries;
|
@@ -188,17 +190,13 @@ default void parseFilters(QueryBuilder query, Map<String, String[]> parameters)
|
188 | 190 |
|
189 | 191 | private static Optional<Integer> requirePositiveInt(String key, Map<String, String[]> parameters) {
|
190 | 192 | if(parameters.containsKey(key)) {
|
191 |
| - var values = parameters.remove(key); |
192 |
| - if(values.length == 1) { |
193 |
| - var v = parseInt(values[0]); |
194 |
| - if(v >= 0) { |
195 |
| - return Optional.of(v); |
196 |
| - } |
197 |
| - throw new IllegalArgumentException(key + " cannot be negative"); |
| 193 | + var v = parseInt(requireNArgs(1, parameters.remove(key), ()-> key)[0]); |
| 194 | + if(v >= 0) { |
| 195 | + return Optional.of(v); |
198 | 196 | }
|
199 |
| - throw new IllegalArgumentException("too many value"); |
| 197 | + throw new IllegalArgumentException(key + " cannot be negative"); |
200 | 198 | }
|
201 |
| - return Optional.empty(); |
| 199 | + return empty(); |
202 | 200 | }
|
203 | 201 |
|
204 | 202 | static Stream<String> flatParameters(String... arr) { //number local separator
|
|
0 commit comments