Skip to content

Commit

Permalink
edit
Browse files Browse the repository at this point in the history
  • Loading branch information
usfalami committed Aug 28, 2024
1 parent 63748c6 commit aa0e0fb
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
1 change: 1 addition & 0 deletions src/main/java/org/usf/jquery/core/ColumnFilterGroup.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import static java.util.stream.Collectors.joining;
import static org.usf.jquery.core.QueryParameterBuilder.addWithValue;
import static org.usf.jquery.core.Utils.arrayJoin;
import static org.usf.jquery.core.Utils.arrayJoinFirst;

import java.util.stream.Stream;

Expand Down
12 changes: 6 additions & 6 deletions src/main/java/org/usf/jquery/core/DBColumn.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import static org.usf.jquery.core.Order.ASC;
import static org.usf.jquery.core.Order.DESC;
import static org.usf.jquery.core.QueryParameterBuilder.formatValue;
import static org.usf.jquery.core.Utils.arrayJoin;
import static org.usf.jquery.core.Utils.arrayJoinFirst;
import static org.usf.jquery.core.Validation.requireLegalVariable;
import static org.usf.jquery.core.Validation.requireNoArgs;

Expand Down Expand Up @@ -126,12 +126,12 @@ default ColumnSingleFilter notNull() {

@SuppressWarnings("unchecked")
default <T> ColumnSingleFilter in(T... arr) {
return Comparator.in().filter(arrayJoin(arr, this, 0));
return Comparator.in().filter(arrayJoinFirst(arr, this));
}

@SuppressWarnings("unchecked")
default <T> ColumnSingleFilter notIn(T... arr) {
return Comparator.notIn().filter(arrayJoin(arr, this, 0));
return Comparator.notIn().filter(arrayJoinFirst(arr, this));
}

default ColumnSingleFilter filter(ComparisonExpression exp) {
Expand Down Expand Up @@ -249,11 +249,11 @@ default OperationColumn substring(int start, int end) {
}

default OperationColumn concat(Object... str) {
return Operator.concat().operation(arrayJoin(str, this, 0));
return Operator.concat().operation(arrayJoinFirst(str, this));
}

default OperationColumn pow(int n, String value) {
return Operator.pow().operation(this, n, value);
default OperationColumn lpad(int n, String value) {
return Operator.lpad().operation(this, n, value);
}

default OperationColumn rpad(int n, String value) {
Expand Down
11 changes: 8 additions & 3 deletions src/main/java/org/usf/jquery/core/Utils.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package org.usf.jquery.core;

import static java.lang.System.arraycopy;
import static java.util.Arrays.copyOf;
import static java.util.Objects.isNull;
import static java.util.stream.Collectors.joining;

import java.lang.reflect.Array;
import java.util.Collection;
import java.util.Map;
import java.util.stream.Stream;
Expand Down Expand Up @@ -58,12 +60,15 @@ public static <T> String joinAndDelemit(String delemiter, String before, String
}

public static <T> T[] arrayJoin(T[] arr, T o) {
return arrayJoin(arr, o, arr.length);
var res = copyOf(arr, arr.length+1);
res[arr.length+1] = o;
return res;
}

public static <T> T[] arrayJoin(T[] arr, T o, int idx) {
public static <T> T[] arrayJoinFirst(T[] arr, T o) {
var res = copyOf(arr, arr.length+1);
res[idx] = o;
arraycopy(arr, 0, res, 1, arr.length);
res[0] = o;
return res;
}
}

0 comments on commit aa0e0fb

Please sign in to comment.