List<CellParam> parentCellParamList = Linq4j.asEnumerable(paramList)
.where(p -> p.getParentId().equals(parentId)).toList();
<dependency>
<groupId>org.apache.calcite</groupId>
<artifactId>calcite-linq4j</artifactId>
<version>1.14.0</version>
</dependency>
package com.zte.springbootframe.util;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
import java.lang.reflect.Array;
import java.security.MessageDigest;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* description:工具类
*
* @author: 胡俊10242248
* @date: 2018/10/31 11:14
*/
public class DatasourceTools
{
/**
* description:单例
*/
private static class SingletonHolder
{
private final static DatasourceTools INSTANCE = new DatasourceTools();
}
public static DatasourceTools getInstance()
{
return DatasourceTools.SingletonHolder.INSTANCE;
}
/**
* description:字母
*/
private static Pattern patternIsLetter = Pattern.compile("[^a-z^A-Z]");
/**
* description:数字类型
*/
private static Pattern patternIsInt = Pattern.compile("[^0-9]");
/**
* description:double类型
*/
private static Pattern patternIsDouble = Pattern.compile("^(\\-|\\+)?\\d+(\\.\\d+)?$");
/**
* description:判断excel版本
*/
private static Pattern excelVersion = Pattern.compile("^.+\\.(?i)(xlsx)$");
/**
* description:特殊字符处理
*/
private static Pattern specialCharacter = Pattern.compile("[`~!@#$%^&*()\\-+{}':;,\\[\\]./?¥…()_|【】‘;:=”\"“’。,、?\\s]");
/**
* description:加减乘除符号分隔
*/
public static String expression = "[\\+\\-\\*\\/\\%]";
public static String expressionplus = "[\\+\\-\\*\\/\\%\\(\\)\\,]";
/**
* description:excel中if表达式
*/
public static String ifExpression = "[\\>\\<\\=]";
public static String expressionPlus = "[\\+\\-\\*\\/\\%\\>\\<\\=\\(\\)\\,]";
public static int one = 1;
/**
* description:公式分隔符
*/
public static String formulaFlag = "~";
/**
* description:批注分隔符
*/
public static String commentFlag = "^";
/**
* description:下拉框数据分割符
*/
public static String listFlag = "#";
/**
* description:字符串中是否包含字母
*/
public static Pattern stringIsContainLetter = Pattern.compile("(?i)[a-z]");
/**
* description:字符串中是否包含中文
*/
public static Pattern stringIsContainChinese = Pattern.compile("[\u4e00-\u9fa5]");
/**
* description:字母和数字
*/
public static String letterAndNumRegex = "[^A-Z^0-9]";
/**
* description:数字
*/
public static String numRegex = "[^0-9]";
/**
* description:汉字
*/
public static String chinaRegex = "[^\u4E00-\u9FA5]";
public static int ten = 10;
/**
* description:JavaScript 向上取整函数
*/
public static String ROUNDUP = "function ROUNDUP(num,dep){\n" + " return (Math.floor(dep)<0?num:Math.ceil(num*Math.pow(10,Math.floor(dep)))/(Math.pow(10,Math.floor(dep))));\n"
+ " }\n";
/**
* description:JavaScript 向下取整函数
*/
public static String ROUNDDOWN =
"function ROUNDDOWN(num,dep){\n" + "\t\treturn Math.floor(num*Math.pow(10,dep))/Math.pow(10,dep);\n" + "\t}\n";
/**
* description:JavaScript 四舍五入
*/
public static String ROUND = "function ROUND(num,dep){\n" + "\t\treturn num.toFixed(dep);\n" + "\t}\n";
/**
* description:JavaScript SUM函数
*/
public static String SUMArray =
"function SUMArray(arr){\n" + "\t\tvar i = 0, n = arr.length;\n" + "\t\tvar sum=0;\n" + "\t\tfor(;i<n;i++){\n" + "\t\t\tsum = sum + arr[i];\n" + "\t\t}\n" + "\t\treturn sum;\n" + "\t}\n";
/**
* description:JavaScript ceiling函数
*/
public static String CEILING = "function CEILING(num,dep){\n" + "\t\treturn Math.ceil(num/dep)*dep;\n" + "\t}\n";
/**
* description:JavaScript 平均值函数
*/
public static String AVERAGE =
"function AVERAGE(arr){\n" + "\t\tvar i = 0, n = arr.length;\n" + "\t\tvar sum=0;\n" + "\t\tfor(;i<n;i++){\n" + "\t\t\tsum = sum + arr[i];\n" + "\t\t}\n" + "\t\treturn sum/n;\n" + "\t}\n";
/**
* description:JavaScript SUMPRODUCT函数
*/
public static String SUMPRODUCT =
"function SUMPRODUCT(){\n" + "\t\tvar n = arguments.length;\n" + " var sum=0;\n" + " for(var i=0;i<arguments[0].length;i++){\n" + " var temp=arguments[0][i];\n"
+ " for(var j=1;j<n;j++){\n" + " temp=temp*arguments[j][i];\n" + " }\n"
+ " sum=sum+temp;\n" + " }\n" + " return sum;\n" + "\t}\n";
public enum Constant
{
/**
* description:excel相关常量
*/
utfName("名称"),
iosName("name"),
utfResult("结果"),
utfValue("实际值"),
iosValue("value"),
utfValueDefault("参考值"),
iosValueDefault("default"),
utfRemark("备注"),
utfDescription("说明"),
iosRemark("remark"),
utfFormula("公式"),
iosFormula("formula"),
leftBrackets("("),
rightBrackets(")"),
ROUNDUP("ROUNDUP"),
CEILING("CEILING"),
SUM("SUM"),
ROUNDDOWN("ROUNDDOWN"),
IF("IF"),
MAX("MAX"),
MIN("MIN"),
AVERAGE("AVERAGE"),
SUMPRODUCT("SUMPRODUCT"),
AT("@"),
ROUND("ROUND");
private final String state;
Constant(String state)
{
this.state = state;
}
public String getState()
{
return state;
}
}
/**
* 只保留string中数字部分,如B3----3
*/
public static int getNumberInString(String str)
{
Matcher m = patternIsInt.matcher(str);
return Integer.parseInt(m.replaceAll("").trim());
}
public static Long getLongInString(String str)
{
Matcher m = patternIsInt.matcher(str);
return Long.valueOf(m.replaceAll("").trim());
}
/**
* description:只保留string中数字部分,如B3----B
*
* @author: 胡俊10242248
* @date: 2018/10/23 9:50
*/
public static String getLetterInString(String str)
{
Matcher m = patternIsLetter.matcher(str);
return m.replaceAll("").trim();
}
/**
* 判断字符串是否为数值类型
*/
public static boolean isNumeric(String str)
{
if(str==null){
return false;
}
Matcher isNum = patternIsDouble.matcher(str);
if (!isNum.matches())
{
return false;
}
return true;
}
/**
* description:判断字符串中是否有中文
*
* @author: 胡俊10242248
* @date: 2018/10/30 18:13
*/
public static boolean checkCountChinese(String countName)
{
Matcher m = stringIsContainChinese.matcher(countName);
if (m.find())
{
return true;
}
return false;
}
/**
* description:字符串中是否包含字母
* author: 胡俊10242248
* date: 2018/11/6 13:37
*/
public static boolean checkCountLetter(String countName)
{
Matcher m = stringIsContainLetter.matcher(countName);
if (m.find())
{
return true;
}
return false;
}
/**
* description:一维excel公式分割,A1*A2+A5*A17"--1,2,5,17
*
* @author: 胡俊10242248
* @date: 2018/10/29 16:17
*/
public static ArrayList<Integer> formulaNumSplit(String formulaColNum)
{
ArrayList<Integer> arrayList = new ArrayList<>();
String[] str1 = formulaColNum.split(expression);
for (int i = 0; i < str1.length; i++)
{
Matcher m = patternIsInt.matcher(str1[i]);
arrayList.add(Integer.parseInt(m.replaceAll("").trim()));
}
return arrayList;
}
/**
* description:特殊字符用下划线替换
*
* @author: 胡俊10242248
* @date: 2018/10/29 10:05
*/
public static String specialStringConversion(String s)
{
Matcher m = specialCharacter.matcher(s);
return m.replaceAll("_").trim();
}
/**
* description:判断可变参数字符串是否存在为空
*
* @author: 胡俊10242248
* @date: 2018/10/29 9:39
*/
public static boolean isHaveEmpty(String... strs)
{
for (String str : strs)
{
if (str == null || "".equals(str))
{
return true;
}
}
return false;
}
/**
* description:判断excel版本,如果版本不正确则抛出异常
*
* @author: 胡俊10242248
* @date: 2018/10/23 10:28
*/
public static void isExcel2007(String filePath)
{
Matcher isExcel2007 = excelVersion.matcher(filePath);
if (!isExcel2007.matches())
{
throw new RuntimeException("excel版本要求2007以上!");
}
}
/**
* description:去除数组中数字元素,如str={"a","b","c","1","2"}--{"a","b","c"}
* author: 胡俊10242248
* date: 2018/11/2 15:14
*/
public static String[] removeNumericElement(String[] str)
{
int length = str.length;
int i = 0;
while (i < str.length)
{
//if (DatasourceTools.isNumeric(str[i]))
if (!DatasourceTools.checkCountLetter(str[i]))
{
--length;
//把当前元素放到最后
str[i] = str[str.length - 1];
str = Arrays.copyOf(str, length);
i = 0;
}
else
{
i++;
}
}
return str;
}
public static String[] removeNull(String[] str)
{
int length = str.length;
int i = 0;
while (i < str.length)
{
if (str[i].contains("null"))
{
--length;
//把当前元素放到最后
str[i] = str[str.length - 1];
str = Arrays.copyOf(str, length);
i = 0;
}
else
{
i++;
}
}
return str;
}
/**
* description:去除数组中null字段内容
* author: 胡俊10242248
* date: 2018/12/18 20:01
*/
public static String[] removeArrayEmptyText(String[] strArray) {
List<String> strList= Arrays.asList(strArray);
List<String> strListNew=new ArrayList<>();
for (int i = 0; i <strList.size(); i++) {
if (strList.get(i)!=null&&!strList.get(i).equals("")){
strListNew.add(strList.get(i));
}
}
return strListNew.toArray(new String[strListNew.size()]);
}
/**
* description:去除数组中最后一个元素
* author: 胡俊10242248
* date: 2018/11/7 17:05
*/
public static String[] removeLastElement(String[] str)
{
ArrayList<String> al = new ArrayList<>(Arrays.asList(str));
al.remove(al.size() - 1);
return al.toArray(new String[al.size()]);
}
/**
* description:数组合并
* author: 胡俊10242248
* date: 2018/11/7 17:23
*/
@SafeVarargs
public static <T> T[] arrayMerge(T[] first, T[]... rest)
{
int totalLength = first.length;
for (T[] array : rest)
{
totalLength += array.length;
}
T[] result = Arrays.copyOf(first, totalLength);
int offset = first.length;
for (T[] array : rest)
{
System.arraycopy(array, 0, result, offset, array.length);
offset += array.length;
}
return result;
}
/**
* description:list转string,分隔符flag
* author: 胡俊10242248
* date: 2019/3/13 10:16
*/
public static String listToStr(List<String> modelSourceNos,String flag) {
StringBuilder sb=new StringBuilder();
for(int j=0;j<modelSourceNos.size();j++){
if(j!=modelSourceNos.size()-1){
sb.append(modelSourceNos.get(j)).append(flag);
}else {
sb.append(modelSourceNos.get(j));
}
}
return sb.toString();
}
/**
* description:判断字符串中是否包含某些字符
* author: 胡俊10242248
* date: 2018/10/31 14:52
*/
public static boolean isContainsBatch(String s, String... strs)
{
for (String str : strs)
{
if (s.contains(str))
{
return true;
}
}
return false;
}
/**
* description:字符key在string中出现的位置
* author: 胡俊10242248
* date: 2018/11/26 18:33
*/
public static ArrayList<Integer> searchAllIndex(String str,String key) {
ArrayList<Integer> indexs=new ArrayList<>();
int a = str.indexOf(key);//*第一个出现的索引位置
indexs.add(a);
while (a != -1) {
a = str.indexOf(key, a + 1);//*从这个索引往后开始第一个出现的位置
indexs.add(a);
}
return indexs;
}
/**
* description:将string指定位置字符转换为content
* author: 胡俊10242248
* date: 2018/11/26 18:35
*/
public static String replaceIndex(String str,int index,String content){
return str.substring(0, index) + content + str.substring(index + 1);
}
/**
* description:获取分隔符之后的字符串
* author: 胡俊10242248
* date: 2018/10/31 17:09
*/
public static String getStringAfterFlag(String str, String flag)
{
if(!str.contains(flag)){
return str;
}
return str.substring(str.indexOf(flag) + 1);
}
/**
* description:获取分隔符之前的字符串
* author: 胡俊10242248
* date: 2018/10/31 17:14
*/
public static String getStringBeforeFlag(String str, String flag)
{
if(!str.contains(flag)){
return str;
}
return str.substring(0, str.indexOf(flag));
}
/**
* description:excel列数转字母,0--A,26--AA
* author: 胡俊10242248
* date: 2018/11/1 9:29
*/
public static String excelColumnNumToLetter(int columnNum)
{
StringBuffer stringBuffer = new StringBuffer();
getExcelColumnNum(columnNum, stringBuffer);
return stringBuffer.toString();
}
private static void getExcelColumnNum(int columnNum, StringBuffer sbBuffer)
{
if (columnNum / 26 > 0)
{
//列从0开始计算
getExcelColumnNum(columnNum / 26 - 1, sbBuffer);
}
sbBuffer.append((char) (columnNum % 26 + 'A'));
}
/**
* description:去掉数组中重复元素
* author: 胡俊10242248
* date: 2018/11/6 10:07
*/
public static String[] removeRepeatElement(String[] strs)
{
//参数编码去重
Set<String> hashSet = new HashSet<>();
hashSet.addAll(Arrays.asList(strs));
return hashSet.toArray(new String[hashSet.size()]);
}
/**
* excel开始行所在的列--字母转数字,如A---1,AA--27
*/
public static int letterToNumber(String colStr)
{
int length = colStr.length();
int num;
int result = 0;
for (int i = 0; i < length; i++)
{
char ch = colStr.charAt(length - i - 1);
num = (ch - 'A' + 1);
num *= Math.pow(26, i);
result += num;
}
return result;
}
/**
* 获取系统当前时间
*/
public static String getDateTime()
{
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
return sdf.format(new Date());
}
/**
* 判断多个字符串全部是否为空
*
* @param strings
* @return
*/
public static boolean isAllEmpty(String... strings)
{
if (strings == null)
{
return true;
}
for (String str : strings)
{
if (StringUtils.isNotEmpty(str))
{
return false;
}
}
return true;
}
/**
* 首字母变小写
*/
public static String firstCharToLowerCase(String str)
{
char firstChar = str.charAt(0);
if (firstChar >= 'A' && firstChar <= 'Z')
{
char[] arr = str.toCharArray();
arr[0] += ('a' - 'A');
return new String(arr);
}
return str;
}
/**
* 首字母变大写
*/
public static String firstCharToUpperCase(String str)
{
char firstChar = str.charAt(0);
if (firstChar >= 'a' && firstChar <= 'z')
{
char[] arr = str.toCharArray();
arr[0] -= ('a' - 'A');
return new String(arr);
}
return str;
}
/**
* md5加密
*/
public static String MD5(String s)
{
char[] hexDigits = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
try
{
byte[] btInput = s.getBytes("UTF-8");
// 获得MD5摘要算法的 MessageDigest 对象
MessageDigest mdInst = MessageDigest.getInstance("MD5");
// 使用指定的字节更新摘要
mdInst.update(btInput);
// 获得密文
byte[] md = mdInst.digest();
// 把密文转换成十六进制的字符串形式
int j = md.length;
char str[] = new char[j * 2];
int k = 0;
for (int i = 0; i < j; i++)
{
byte byte0 = md[i];
str[k++] = hexDigits[byte0 >>> 4 & 0xf];
str[k++] = hexDigits[byte0 & 0xf];
}
return new String(str);
}
catch (Exception e)
{
e.printStackTrace();
return null;
}
}
/**
* description:json字符串转Java对象
* author: 胡俊10242248
* date: 2018/11/14 14:19
*/
public static <T> T jsonToBean(String jsonData, Class<T> clazz)
{
return JSONObject.parseObject(jsonData, clazz);
}
/**
* description:数组转jsonString
* author: 胡俊10242248
* date: 2018/11/17 10:49
*/
public static <T> String arrayToJsonString(T[] s){
JSONArray result = new JSONArray(Arrays.asList(s));
return result.toJSONString();
}
/**
* description:删除数组中指定下标元素
* author: 胡俊10242248
* date: 2018/11/27 14:10
*/
public static <T> T[] removeElementByIndex(T[] str,int index){
return ArrayUtils.remove(str, index);
}
/**
* description:删除数组中指定元素
* author: 胡俊10242248
* date: 2018/11/27 14:52
*/
@SuppressWarnings("unchecked")
public static <T> T[] removeSpeficElement(T[] arr,T element){
int count = 0;
for(int i = 0 ; i<arr.length ; i++){
if(arr[i]==element){
count++;
}
}
T[] newArr=(T[]) Array.newInstance(arr.getClass().getComponentType(), arr.length-count);
int index =0 ;
for(int i = 0; i<arr.length ; i++){
if(arr[i]!=element){
newArr[index] = arr[i];
index++;
}
}
return newArr;
}
/**
*判断字符串是不是以数字开头
*/
public static boolean isStartWithNumber(String str) {
Matcher isNum = patternIsInt.matcher(str.charAt(0)+"");
if (isNum.matches()) {
return false;
}
return true;
}
/**
* description:excel公式转换为JS
* author: 胡俊10242248
* date: 2019/2/27 16:44
*/
public static String excelFormulaToJS(String excelFormula) {
excelFormula="return "+excelFormula.replace("MAX","Math.max")
.replace("MIN","Math.min")
.replace("ROUNDUP","Math.ceil")
.replace("ROUNDDOWN","Math.floor")
.replace("ROUND","Math.round")
.replace("=","==")
.replace(">==",">=")
.replace("<==","<=")
.replace("<>","!=");
return excelFormula;
}
/**
* description:获取两个字符串之间的字符
* author: 胡俊10242248
* date: 2019/1/2 13:46
*/
public static String getStrBetweenPreAndSuf(String str,String pre,String suf) {
if(str.contains(pre)&&str.contains(suf)){
return str.substring((str.indexOf(pre)+pre.length()), str.indexOf(suf));
}
return str;
}
/**
* description:去掉空格,换行,制表符
* author: 胡俊10242248
* date: 2019/1/2 15:05
*/
public static String replaceBlank(String str) {
String dest = "";
if (str!=null) {
Pattern p = Pattern.compile("\\s*|\t|\r|\n");
Matcher m = p.matcher(str);
dest = m.replaceAll("");
}
return dest;
}
/** 长日期格式: 年-月-日 时:分:秒 */
public static final String FULL_DATE_FORMAT = "yyyy-MM-dd HH:mm:ss";
/**
* 日期格式化为字符串
*
* @author 6404000031 蔡德杰
* @param date
* @param format
* @return
*/
public static final String format(Date date, String format) {
if (null == date) {
return StringUtils.EMPTY;
}
SimpleDateFormat sdf = new SimpleDateFormat(format);
return sdf.format(date);
}
/**
* description:去掉空格
* author: 胡俊10242248
* date: 2019/1/2 15:05
*/
public static String removeSpace(String arr)
{
char [] ch=arr.toCharArray();
int count=0;
for(int i=0;i<ch.length;i++)
{
if (!Character.isSpaceChar(ch[i])){
count++;
}
}
arr=arr.substring(0,count);
return arr;
}
/**
* description:数字转换为Excel列号
* @param column
* return:
* author: 胡俊10242248
* date: 2019/2/15 17:19
*/
public static String intToExcelColumn(final int column)
{
int col = column + 1;
int system = 26;
char[] digArr = new char[100];
int ind = 0;
while (col > 0)
{
int mod = col % system;
if (mod == 0){
mod = system;
}
digArr[ind++] = (char)(mod-1+'A');
col = (col - 1) / 26;
}
StringBuilder bf = new StringBuilder(ind);
for (int i = ind - 1; i >= 0; i--)
{
bf.append(digArr[i]);
}
return bf.toString();
}
/**
* description:字符串中包含字和数字
* author: 胡俊10242248
* date: 2019/2/18 10:22
*/
public static boolean isLetterAndDigit(String str) {
boolean isDigit = false;
boolean isLetter = false;
for (int i = 0; i < str.length(); i++) {
if (Character.isDigit(str.charAt(i))) {
isDigit = true;
}
if (Character.isLetter(str.charAt(i))) {
isLetter = true;
}
if (isDigit & isLetter) {
return true;
}
}
return false;
}
/**
* 使用正则表达式提取中括号中的内容
* @param msg
* @return
*/
public static List<String> extractMessageByRegular(String msg){
Set<String> list=new HashSet<>();
Pattern p = Pattern.compile("(\\[[^\\]]*\\])");
Matcher m = p.matcher(msg);
while(m.find()){
list.add(m.group().substring(1, m.group().length()-1));
}
return new ArrayList<>(list);
}
/**
* description:筛选出list中包含特殊字符的list
* return:
* author: 胡俊10242248
* date: 2019/3/22 15:48
*/
public static <T> List<T> getAllContainSpeficElement(List<T> list,String element){
List<T> tList=new ArrayList<>();
for(T t:list){
if(t.toString().contains(element)){
tList.add(t);
}
}
return tList;
}
}
工具类
最新推荐文章于 2022-01-12 16:45:08 发布