下面列出了org.apache.commons.lang3.ArrayUtils#EMPTY_STRING_ARRAY 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* <p>Creates a compact stack trace for the root cause of the supplied
* <code>Throwable</code>.</p>
*
* <p>The output of this method is consistent across JDK versions.
* It consists of the root exception followed by each of its wrapping
* exceptions separated by '[wrapped]'. Note that this is the opposite
* order to the JDK1.4 display.</p>
*
* @param throwable the throwable to examine, may be null
* @return an array of stack trace frames, never null
* @since 2.0
*/
public static String[] getRootCauseStackTrace(final Throwable throwable) {
if (throwable == null) {
return ArrayUtils.EMPTY_STRING_ARRAY;
}
final Throwable throwables[] = getThrowables(throwable);
final int count = throwables.length;
final List<String> frames = new ArrayList<String>();
List<String> nextTrace = getStackFrameList(throwables[count - 1]);
for (int i = count; --i >= 0;) {
final List<String> trace = nextTrace;
if (i != 0) {
nextTrace = getStackFrameList(throwables[i - 1]);
removeCommonFrames(trace, nextTrace);
}
if (i == count - 1) {
frames.add(throwables[i].toString());
} else {
frames.add(WRAPPED_MARKER + throwables[i].toString());
}
for (int j = 0; j < trace.size(); j++) {
frames.add(trace.get(j));
}
}
return frames.toArray(new String[frames.size()]);
}
/**
* e.g. "/a/b" => [a, b].
*
* @param notePath path in str
* @param includeLast whether return file/folder name in path
* @return path in array
*/
String[] toPathArray(String notePath, boolean includeLast) {
if (null == notePath || notePath.length() == 0) {
throw new NullPointerException("notePath is null");
}
//replace multiple "/" to one "/"
notePath = notePath.replaceAll("/+", "/");
if ("/".equals(notePath)) {
return ArrayUtils.EMPTY_STRING_ARRAY;
}
//remove leading "/"
if (notePath.startsWith("/")) {
notePath = notePath.substring(1);
}
String[] arr = notePath.split("/");
return includeLast ? arr : Arrays.copyOfRange(arr, 0, arr.length - 1);
}
/**
* <p>Creates a compact stack trace for the root cause of the supplied
* <code>Throwable</code>.</p>
*
* <p>The output of this method is consistent across JDK versions.
* It consists of the root exception followed by each of its wrapping
* exceptions separated by '[wrapped]'. Note that this is the opposite
* order to the JDK1.4 display.</p>
*
* @param throwable the throwable to examine, may be null
* @return an array of stack trace frames, never null
* @since 2.0
*/
public static String[] getRootCauseStackTrace(Throwable throwable) {
if (throwable == null) {
return ArrayUtils.EMPTY_STRING_ARRAY;
}
Throwable throwables[] = getThrowables(throwable);
int count = throwables.length;
List<String> frames = new ArrayList<String>();
List<String> nextTrace = getStackFrameList(throwables[count - 1]);
for (int i = count; --i >= 0;) {
List<String> trace = nextTrace;
if (i != 0) {
nextTrace = getStackFrameList(throwables[i - 1]);
removeCommonFrames(trace, nextTrace);
}
if (i == count - 1) {
frames.add(throwables[i].toString());
} else {
frames.add(WRAPPED_MARKER + throwables[i].toString());
}
for (int j = 0; j < trace.size(); j++) {
frames.add(trace.get(j));
}
}
return frames.toArray(new String[0]);
}
/**
* <p>Creates a compact stack trace for the root cause of the supplied
* <code>Throwable</code>.</p>
*
* <p>The output of this method is consistent across JDK versions.
* It consists of the root exception followed by each of its wrapping
* exceptions separated by '[wrapped]'. Note that this is the opposite
* order to the JDK1.4 display.</p>
*
* @param throwable the throwable to examine, may be null
* @return an array of stack trace frames, never null
* @since 2.0
*/
public static String[] getRootCauseStackTrace(Throwable throwable) {
if (throwable == null) {
return ArrayUtils.EMPTY_STRING_ARRAY;
}
Throwable throwables[] = getThrowables(throwable);
int count = throwables.length;
List<String> frames = new ArrayList<String>();
List<String> nextTrace = getStackFrameList(throwables[count - 1]);
for (int i = count; --i >= 0;) {
List<String> trace = nextTrace;
if (i != 0) {
nextTrace = getStackFrameList(throwables[i - 1]);
removeCommonFrames(trace, nextTrace);
}
if (i == count - 1) {
frames.add(throwables[i].toString());
} else {
frames.add(WRAPPED_MARKER + throwables[i].toString());
}
for (int j = 0; j < trace.size(); j++) {
frames.add(trace.get(j));
}
}
return frames.toArray(new String[frames.size()]);
}
/**
* <p>Creates a compact stack trace for the root cause of the supplied
* <code>Throwable</code>.</p>
*
* <p>The output of this method is consistent across JDK versions.
* It consists of the root exception followed by each of its wrapping
* exceptions separated by '[wrapped]'. Note that this is the opposite
* order to the JDK1.4 display.</p>
*
* @param throwable the throwable to examine, may be null
* @return an array of stack trace frames, never null
* @since 2.0
*/
public static String[] getRootCauseStackTrace(Throwable throwable) {
if (throwable == null) {
return ArrayUtils.EMPTY_STRING_ARRAY;
}
Throwable throwables[] = getThrowables(throwable);
int count = throwables.length;
List<String> frames = new ArrayList<String>();
List<String> nextTrace = getStackFrameList(throwables[count - 1]);
for (int i = count; --i >= 0;) {
List<String> trace = nextTrace;
if (i != 0) {
nextTrace = getStackFrameList(throwables[i - 1]);
removeCommonFrames(trace, nextTrace);
}
if (i == count - 1) {
frames.add(throwables[i].toString());
} else {
frames.add(WRAPPED_MARKER + throwables[i].toString());
}
for (int j = 0; j < trace.size(); j++) {
frames.add(trace.get(j));
}
}
return frames.toArray(new String[frames.size()]);
}
/**
* <p>Creates a compact stack trace for the root cause of the supplied
* <code>Throwable</code>.</p>
*
* <p>The output of this method is consistent across JDK versions.
* It consists of the root exception followed by each of its wrapping
* exceptions separated by '[wrapped]'. Note that this is the opposite
* order to the JDK1.4 display.</p>
*
* @param throwable the throwable to examine, may be null
* @return an array of stack trace frames, never null
* @since 2.0
*/
public static String[] getRootCauseStackTrace(Throwable throwable) {
if (throwable == null) {
return ArrayUtils.EMPTY_STRING_ARRAY;
}
Throwable throwables[] = getThrowables(throwable);
int count = throwables.length;
List<String> frames = new ArrayList<String>();
List<String> nextTrace = getStackFrameList(throwables[count - 1]);
for (int i = count; --i >= 0;) {
List<String> trace = nextTrace;
if (i != 0) {
nextTrace = getStackFrameList(throwables[i - 1]);
removeCommonFrames(trace, nextTrace);
}
if (i == count - 1) {
frames.add(throwables[i].toString());
} else {
frames.add(WRAPPED_MARKER + throwables[i].toString());
}
for (int j = 0; j < trace.size(); j++) {
frames.add(trace.get(j));
}
}
return frames.toArray(new String[0]);
}
@Override
public void reset(ActionMapping mapping, HttpServletRequest request) {
super.reset(mapping, request);
// Reset all image buttons
for(ImageButton button : targetRemoveList) {
button.clearButton();
}
targetAddButton.clearButton();
updateButton.clearButton();
deleteButton.clearButton();
// Reset form fields for new rule
columnAndTypeNew = null;
chainOperatorNew = 0;
parenthesisOpenedNew = 0;
primaryOperatorNew = 0;
primaryValueNew = null;
parenthesisClosedNew = 0;
dateFormatNew = null;
secondaryOperatorNew = 0;
secondaryValueNew = null;
needSaveTargetGroup = false;
// We need just to check if user is logged in - in other case we'll get NPE here.
// The actual redirect to login page will be made by Action class.
if (AgnUtils.isUserLoggedIn(request)) {
targetShortname = SafeString.getLocaleString("default.Name", AgnUtils.getLocale(request));
targetDescription = SafeString.getLocaleString("default.description", AgnUtils.getLocale(request));
}
setNumberOfRows(-1);
selectedFields = ArrayUtils.EMPTY_STRING_ARRAY;
mailingId = 0;
mailingName = null;
}
@Override
public void reset(ActionMapping map, HttpServletRequest request) {
setAction(ComMailingBaseAction.ACTION_LIST);
dynamicTemplate = false;
archived = false;
super.reset(map, request);
clearBulkIds();
int actionID = NumberUtils.toInt(request.getParameter("action"));
if (actionID == ComMailingBaseAction.ACTION_SAVE
|| actionID == ComMailingBaseAction.ACTION_SAVE_MAILING_GRID) {
parameterMap.clear();
addParameter = false;
}
intervalType = ComMailingParameterDao.IntervalType.None;
intervalDays = new boolean[7];
setNumberOfRows(-1);
selectedFields = ArrayUtils.EMPTY_STRING_ARRAY;
uploadFile = null;
setTargetGroups(Collections.emptyList());
setTargetExpression(StringUtils.EMPTY);
assignTargetGroups = false;
}
private String[] wrap(String code) {
if (code == null) {
return ArrayUtils.EMPTY_STRING_ARRAY;
}
return new String[]{code};
}
@Override
public String[] read() throws IOException, NoSuchElementException {
if (!hasNext()) {
throw new NoSuchElementException();
}
String[] values = reader.getValues();
readRecord();
lineNumber++;
// drop all values after last non-empty cell
// otherwise a lot of empty (but styled) cells will be returned
int lastNonEmptyCellIdx = ArrayUtils.INDEX_NOT_FOUND;
for (int i = values.length - 1; i >= 0; i--) {
if (StringUtils.isNotBlank(values[i])) {
lastNonEmptyCellIdx = i;
break;
}
}
if(lastNonEmptyCellIdx == ArrayUtils.INDEX_NOT_FOUND) {
return ArrayUtils.EMPTY_STRING_ARRAY;
}
if(values.length != lastNonEmptyCellIdx + 1) {
values = Arrays.copyOf(values, lastNonEmptyCellIdx + 1);
}
for (int i=0; i<values.length; i++) {
values[i] = values[i].trim();
}
return values;
}
/**
* Converts the json string to java string array.
*
* @param jsonString json array string
* @return java array. Returns empty string, if there is any error parsing the json string or not of type array.
*/
private static String[] toArray(String jsonString) {
if (jsonString == null) {
return ArrayUtils.EMPTY_STRING_ARRAY;
}
try {
return mapper.readValue(jsonString, String[].class);
} catch (IOException e) {
return ArrayUtils.EMPTY_STRING_ARRAY;
}
}
/**
* 使用StringTokenizer分隔给定的字符串到字符串数组.
*
* <p>
* (此方法借鉴 "org.springframework.util.StringUtils#tokenizeToStringArray").
* </p>
*
* <h3>说明:</h3>
*
* <blockquote>
* <p>
* 给定的delimiters字符串支持任意数量的分隔字符characters. <br>
* 每一个characters可以用来分隔tokens.一个delimiter分隔符常常是一个single字符;<br>
* 如果你要使用多字符 multi-character delimiters分隔, 你可以考虑使用<code>delimitedListToStringArray</code>
* </p>
* </blockquote>
*
* <h3>关于 {@link StringTokenizer}:</h3>
*
* <blockquote>
*
* {@link StringTokenizer} implements {@code Enumeration<Object>}<br>
* 其在 Enumeration接口的基础上,定义了 hasMoreTokens nextToken两个方法<br>
* 实现的Enumeration接口中的 hasMoreElements nextElement,调用了 hasMoreTokens nextToken<br>
*
* </blockquote>
*
* @param str
* 需要被分隔的字符串
* @param delimiters
* delimiter characters, assembled as String<br>
* 参数中的所有字符都是分隔标记的分隔符,比如这里可以设置成 ";, " ,spring就是使用这样的字符串来分隔数组/集合的
* @param trimTokens
* 是否使用 {@link String#trim()}操作token
* @param ignoreEmptyTokens
* 是否忽视空白的token,如果为true,那么token必须长度 {@code >} 0;如果为false会包含长度=0 空白的字符<br>
* (仅仅用于那些 trim之后是empty的tokens,StringTokenizer不会考虑subsequent delimiters as token in the first place).
* @return 如果 <code>str</code> 是null,返回 {@link ArrayUtils#EMPTY_STRING_ARRAY}<br>
* @see java.util.StringTokenizer
* @see String#trim()
* @see "org.springframework.util.StringUtils#delimitedListToStringArray"
* @see "org.springframework.util.StringUtils#tokenizeToStringArray"
* @since 1.0.7
*/
public static String[] tokenizeToStringArray(String str,String delimiters,boolean trimTokens,boolean ignoreEmptyTokens){
if (null == str){
return ArrayUtils.EMPTY_STRING_ARRAY;
}
List<String> tokens = newArrayList();
StringTokenizer stringTokenizer = new StringTokenizer(str, delimiters);
while (stringTokenizer.hasMoreTokens()){
String token = stringTokenizer.nextToken();
token = trimTokens ? token.trim() : token;//去空
if (!ignoreEmptyTokens || token.length() > 0){
tokens.add(token);
}
}
return toArray(tokens, String.class);
}
public static String[] toParts( String version )
{
if ( StringUtils.isBlank( version ) )
{
return ArrayUtils.EMPTY_STRING_ARRAY;
}
int modeOther = 0;
int modeDigit = 1;
int modeText = 2;
List<String> parts = new ArrayList<>();
int len = version.length();
int i = 0;
int start = 0;
int mode = modeOther;
while ( i < len )
{
char c = version.charAt( i );
if ( Character.isDigit( c ) )
{
if ( mode != modeDigit )
{
if ( mode != modeOther )
{
parts.add( version.substring( start, i ) );
}
mode = modeDigit;
start = i;
}
}
else if ( Character.isLetter( c ) )
{
if ( mode != modeText )
{
if ( mode != modeOther )
{
parts.add( version.substring( start, i ) );
}
mode = modeText;
start = i;
}
}
else
{
// Other.
if ( mode != modeOther )
{
parts.add( version.substring( start, i ) );
mode = modeOther;
}
}
i++;
}
// Add remainder
if ( mode != modeOther )
{
parts.add( version.substring( start, i ) );
}
return parts.toArray( new String[parts.size()] );
}
/**
* <p>Captures the stack trace associated with the specified
* <code>Throwable</code> object, decomposing it into a list of
* stack frames.</p>
*
* <p>The result of this method vary by JDK version as this method
* uses {@link Throwable#printStackTrace(java.io.PrintWriter)}.
* On JDK1.3 and earlier, the cause exception will not be shown
* unless the specified throwable alters printStackTrace.</p>
*
* @param throwable the <code>Throwable</code> to examine, may be null
* @return an array of strings describing each stack frame, never null
*/
public static String[] getStackFrames(final Throwable throwable) {
if (throwable == null) {
return ArrayUtils.EMPTY_STRING_ARRAY;
}
return getStackFrames(getStackTrace(throwable));
}
/**
* Converts the given Collection into an array of Strings. The returned array does not contain <code>null</code>
* entries. Note that {@link Arrays#sort(Object[])} will throw an {@link NullPointerException} if an array element
* is <code>null</code>.
*
* @param collection
* The collection to convert
* @return A new array of Strings.
*/
static String[] toNoNullStringArray(Collection<String> collection) {
if (collection == null) {
return ArrayUtils.EMPTY_STRING_ARRAY;
}
return toNoNullStringArray(collection.toArray());
}
/**
* <p>Captures the stack trace associated with the specified
* <code>Throwable</code> object, decomposing it into a list of
* stack frames.</p>
*
* <p>The result of this method vary by JDK version as this method
* uses {@link Throwable#printStackTrace(java.io.PrintWriter)}.
* On JDK1.3 and earlier, the cause exception will not be shown
* unless the specified throwable alters printStackTrace.</p>
*
* @param throwable the <code>Throwable</code> to examine, may be null
* @return an array of strings describing each stack frame, never null
*/
public static String[] getStackFrames(Throwable throwable) {
if (throwable == null) {
return ArrayUtils.EMPTY_STRING_ARRAY;
}
return getStackFrames(getStackTrace(throwable));
}
/**
* <p>Captures the stack trace associated with the specified
* <code>Throwable</code> object, decomposing it into a list of
* stack frames.</p>
*
* <p>The result of this method vary by JDK version as this method
* uses {@link Throwable#printStackTrace(java.io.PrintWriter)}.
* On JDK1.3 and earlier, the cause exception will not be shown
* unless the specified throwable alters printStackTrace.</p>
*
* @param throwable the <code>Throwable</code> to examine, may be null
* @return an array of strings describing each stack frame, never null
*/
public static String[] getStackFrames(Throwable throwable) {
if (throwable == null) {
return ArrayUtils.EMPTY_STRING_ARRAY;
}
return getStackFrames(getStackTrace(throwable));
}
/**
* Converts the given Collection into an array of Strings. The returned array does not contain <code>null</code>
* entries. Note that {@link Arrays#sort(Object[])} will throw an {@link NullPointerException} if an array element
* is <code>null</code>.
*
* @param collection
* The collection to convert
* @return A new array of Strings.
*/
static String[] toNoNullStringArray(Collection<String> collection) {
if (collection == null) {
return ArrayUtils.EMPTY_STRING_ARRAY;
}
return toNoNullStringArray(collection.toArray());
}
/**
* <p>Captures the stack trace associated with the specified
* <code>Throwable</code> object, decomposing it into a list of
* stack frames.</p>
*
* <p>The result of this method vary by JDK version as this method
* uses {@link Throwable#printStackTrace(java.io.PrintWriter)}.
* On JDK1.3 and earlier, the cause exception will not be shown
* unless the specified throwable alters printStackTrace.</p>
*
* @param throwable the <code>Throwable</code> to examine, may be null
* @return an array of strings describing each stack frame, never null
*/
public static String[] getStackFrames(Throwable throwable) {
if (throwable == null) {
return ArrayUtils.EMPTY_STRING_ARRAY;
}
return getStackFrames(getStackTrace(throwable));
}
/**
* 将字符串 <code>value</code> 使用分隔符 <code>regexSpliter</code> 分隔成 字符串数组.
*
* <p>
* 建议使用 {@link #tokenizeToStringArray(String, String)} 或者 {@link StringUtils#split(String)}
* </p>
*
* @param value
* value
* @param regexSpliter
* 此处不是简单的分隔符,是正则表达式,<b>.$|()[{^?*+\\</b> 有特殊的含义,因此我们使用.的时候必须进行转义,<span style="color:red">"\"转义时要写成"\\\\"</span> <br>
* 最终调用了 {@link java.util.regex.Pattern#split(CharSequence)}
* @return 如果 <code>value</code> 是null或者empty,返回 {@link ArrayUtils#EMPTY_STRING_ARRAY}<br>
* @see String#split(String)
* @see String#split(String, int)
* @see StringUtils#split(String)
* @see java.util.regex.Pattern#split(CharSequence)
*/
public static String[] split(String value,String regexSpliter){
return isNullOrEmpty(value) ? ArrayUtils.EMPTY_STRING_ARRAY : value.split(regexSpliter);
}