Skip to content

Commit

Permalink
edit
Browse files Browse the repository at this point in the history
  • Loading branch information
usfalami committed Sep 12, 2024
1 parent e32c428 commit d0e2266
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/main/java/org/usf/jquery/core/FunctionOperator.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ default void sql(SqlStringBuilder sb, QueryContext ctx, Object[] args) {
}

default void sql(SqlStringBuilder sb, QueryContext ctx, Object[] args, int from) {
sb.function(id(), ()-> ctx.appendLiteralArray(sb, args, from)); //avoid array copy
sb.function(id(), ()-> ctx.appendLiteralArray(sb, args, from)); //avoid sub array
}
}
2 changes: 1 addition & 1 deletion src/main/java/org/usf/jquery/core/KeyValueMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ public List<DynamicModel> map(ResultSet rs) throws SQLException {
log.trace("{} rows mapped in {} ms", res.size(), currentTimeMillis()-t);
return res;
}
}
}
23 changes: 13 additions & 10 deletions src/main/java/org/usf/jquery/core/SqlStringBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,19 +65,22 @@ public <T> SqlStringBuilder runForeach(T[] arr, String delimiter, Consumer<T> fn
}

public <T> SqlStringBuilder runForeach(T[] arr, int idx, String delimiter, Consumer<T> fn, String prefix, String suffix) {
if(idx < 0 || (isEmpty(arr) && idx > 0) || idx >= requireNonNull(arr, "arr connot be null").length) {
throw new IndexOutOfBoundsException(idx);
}
sb.append(prefix);
if(!isEmpty(arr)) { //idx < arr.length
var i=idx;
fn.accept(arr[i]);
for(++i; i<arr.length; i++) {
sb.append(delimiter);
requireNonNull(arr, "arr connot be null");
if((arr.length == 0 && idx == 0) || idx < arr.length) {
sb.append(prefix);
if(!isEmpty(arr)) { //idx < arr.length
var i=idx;
fn.accept(arr[i]);
for(++i; i<arr.length; i++) {
sb.append(delimiter);
fn.accept(arr[i]);
}
}
sb.append(suffix);
}
else {
throw new IndexOutOfBoundsException(idx);
}
sb.append(suffix);
return this;
}

Expand Down

0 comments on commit d0e2266

Please sign in to comment.