
com.querydsl.collections.CollQueryFunctions Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of querydsl-collections Show documentation
Show all versions of querydsl-collections Show documentation
Collections support for Querydsl
The newest version!
/*
* Copyright 2015, The Querydsl Team (http://www.querydsl.com/team)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.querydsl.collections;
import java.lang.reflect.Field;
import java.math.BigDecimal;
import java.util.*;
import java.util.regex.Pattern;
import org.jetbrains.annotations.Nullable;
import com.querydsl.core.types.Expression;
import com.querydsl.core.types.Operator;
import com.querydsl.core.types.Ops;
import com.querydsl.core.util.MathUtils;
import com.querydsl.core.util.ReflectionUtils;
/**
* {@code CollQueryFunctions} defines function implementation for use in ColQueryTemplates
*
* @author tiwe
*
*/
public final class CollQueryFunctions {
private interface BinaryFunction {
Number apply(Number num1, Number num2);
}
private static final BinaryFunction SUM = new BinaryFunction() {
@Override
public Number apply(Number num1, Number num2) {
return MathUtils.sum(num1, num2);
}
};
private static final BinaryFunction MAX = new BinaryFunction() {
@Override
public Number apply(Number num1, Number num2) {
if (num1.getClass().equals(num2.getClass()) && num1 instanceof Comparable) {
@SuppressWarnings("unchecked") // The types are interchangeable, guarded by previous check
Comparable left = (Comparable) num1;
return left.compareTo(num2) < 0 ? num2 : num1;
} else {
BigDecimal n1 = new BigDecimal(num1.toString());
BigDecimal n2 = new BigDecimal(num2.toString());
return n1.compareTo(n2) < 0 ? num2 : num1;
}
}
};
private static final BinaryFunction MIN = new BinaryFunction() {
@Override
public Number apply(Number num1, Number num2) {
if (num1.getClass().equals(num2.getClass()) && num1 instanceof Comparable) {
@SuppressWarnings("unchecked") // The types are interchangeable, guarded by previous check
Comparable left = (Comparable) num1;
return left.compareTo(num2) < 0 ? num1 : num2;
} else {
BigDecimal n1 = new BigDecimal(num1.toString());
BigDecimal n2 = new BigDecimal(num2.toString());
return n1.compareTo(n2) < 0 ? num1 : num2;
}
}
};
private static final List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy