mirror of
https://e.coding.net/circlecloud/BossShop-re.git
synced 2025-11-24 21:26:18 +00:00
103 lines
3.7 KiB
Java
103 lines
3.7 KiB
Java
package cc.util.bossshop;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.Collection;
|
|
import java.util.List;
|
|
|
|
public class Function{
|
|
|
|
/**
|
|
* 获取忽略大小写的指定前缀的字符串
|
|
* <p>如果指定的前缀为空时将返回全部的目标</p>
|
|
* @param pStrs 搜索目标,不能为null
|
|
* @param pPrefix 指定的前缀,不能为null
|
|
* @param pIgnoreSame 是否忽略相同的字符串
|
|
*/
|
|
public static Collection<String> getSamePrefixIgnoreCase(Collection<String> pStrs,String pPrefix,boolean pIgnoreSame){
|
|
return Function.getSamePrefix(pStrs,pPrefix,true,pIgnoreSame);
|
|
}
|
|
|
|
/**
|
|
* 获取指定前缀的字符串<br />
|
|
* 相同的字符串不作为拥有该前缀
|
|
* <p>如果指定的前缀为空时将返回全部的目标</p>
|
|
* @param pStrs 搜索目标,不能为null
|
|
* @param pPrefix 指定的前缀,不能为null
|
|
* @param pIgnoreCase 是否忽略大小写
|
|
* @param pIgnoreSame 是否忽略相同的字符串
|
|
*/
|
|
public static Collection<String> getSamePrefix(Collection<String> pStrs,String pPrefix,boolean pIgnoreCase,boolean pIgnoreSame){
|
|
ArrayList<String> same=new ArrayList<>();
|
|
if(pStrs==null||pStrs.isEmpty()) return same;
|
|
if(pPrefix==null||pPrefix.isEmpty()) return pStrs;
|
|
if(pIgnoreCase){
|
|
pPrefix=pPrefix.toLowerCase();
|
|
for(String sStr : pStrs){
|
|
if(sStr==null) continue;
|
|
String lowsStr=sStr.toLowerCase();
|
|
if(lowsStr.startsWith(pPrefix)&&(!pIgnoreSame||lowsStr.length()!=pPrefix.length()))
|
|
same.add(sStr);
|
|
}
|
|
}else{
|
|
for(String sStr : pStrs){
|
|
if(sStr==null) continue;
|
|
if(sStr.startsWith(pPrefix)&&(!pIgnoreSame||sStr.length()!=pPrefix.length()))
|
|
same.add(sStr);
|
|
}
|
|
}
|
|
return same;
|
|
}
|
|
|
|
/**
|
|
* 指定位置是否存在忽略大小的指定字符串
|
|
* @param pStrs 目标位置,不能为null
|
|
* @param pTarget 要查找的字符串,可以为null
|
|
* @return 是否存在
|
|
*/
|
|
public static boolean containsIgnoreCase(Collection<String> pStrs,String pTarget){
|
|
if(pStrs==null) return false;
|
|
if(pTarget==null) return pStrs.contains(pTarget);
|
|
return Function.getIgnoreCase(pStrs,pTarget)!=null;
|
|
}
|
|
|
|
/**
|
|
* 获取忽略大小的指定字符串
|
|
* @param pStrs 目标位置,不能为null
|
|
* @param pTarget 要查找的字符串,不能为null
|
|
* @return 查找到的字符串或者null
|
|
*/
|
|
public static String getIgnoreCase(Collection<String> pStrs,String pTarget){
|
|
if(pStrs==null||pStrs.isEmpty()) return null;
|
|
if(pTarget==null) return null;
|
|
for(String sStr : pStrs)
|
|
if(sStr!=null&&sStr.equalsIgnoreCase(pTarget))
|
|
return sStr;
|
|
return null;
|
|
}
|
|
|
|
/**
|
|
* 打印当前位置的堆栈
|
|
*/
|
|
public static void printStackTrace(){
|
|
StackTraceElement[] elements=Thread.currentThread().getStackTrace();
|
|
for(StackTraceElement sElement : elements){
|
|
System.out.println(sElement.toString());
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 将数组转化成List
|
|
* @param pArrays 要转换的数组,如果数组为null,将返回空List
|
|
* @return 转换后的List,非null
|
|
*/
|
|
public static <T> List<T> asList(T[] pArrays){
|
|
ArrayList<T> newList=new ArrayList<>();
|
|
if(pArrays==null||pArrays.length==0) return newList;
|
|
for(T t : pArrays)
|
|
newList.add(t);
|
|
return newList;
|
|
}
|
|
|
|
|
|
}
|