本文整理汇总了Java中com.helger.commons.collection.ArrayHelper.EMPTY_STRING_ARRAY属性的典型用法代码示例。如果您正苦于以下问题:Java ArrayHelper.EMPTY_STRING_ARRAY属性的具体用法?Java ArrayHelper.EMPTY_STRING_ARRAY怎么用?Java ArrayHelper.EMPTY_STRING_ARRAY使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类com.helger.commons.collection.ArrayHelper
的用法示例。
在下文中一共展示了ArrayHelper.EMPTY_STRING_ARRAY属性的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getExplodedArray
/**
* Take a concatenated String and return the passed String array of all
* elements in the passed string, using specified separator char.
*
* @param cSep
* The separator to use.
* @param sElements
* The concatenated String to convert. May be <code>null</code> or
* empty.
* @param nMaxItems
* The maximum number of items to explode. If the passed value is ≤
* 0 all items are used. If max items is 1, than the result string is
* returned as is. If max items is larger than the number of elements
* found, it has no effect.
* @return The passed collection and never <code>null</code>.
*/
@Nonnull
public static String [] getExplodedArray (final char cSep,
@Nullable final String sElements,
@CheckForSigned final int nMaxItems)
{
if (nMaxItems == 1)
return new String [] { sElements };
if (hasNoText (sElements))
return ArrayHelper.EMPTY_STRING_ARRAY;
final int nMaxResultElements = 1 + getCharCount (sElements, cSep);
if (nMaxResultElements == 1)
{
// Separator not found
return new String [] { sElements };
}
final String [] ret = new String [nMaxItems < 1 ? nMaxResultElements : Math.min (nMaxResultElements, nMaxItems)];
// Do not use RegExCache.stringReplacePattern because of package
// dependencies
// Do not use String.split because it trims empty tokens from the end
int nStartIndex = 0;
int nItemsAdded = 0;
while (true)
{
final int nMatchIndex = sElements.indexOf (cSep, nStartIndex);
if (nMatchIndex < 0)
break;
ret[nItemsAdded++] = sElements.substring (nStartIndex, nMatchIndex);
// 1 == length of separator char
nStartIndex = nMatchIndex + 1;
if (nMaxItems > 0 && nItemsAdded == nMaxItems - 1)
{
// We have exactly one item the left: the rest of the string
break;
}
}
ret[nItemsAdded++] = sElements.substring (nStartIndex);
if (nItemsAdded != ret.length)
throw new IllegalStateException ("Added " + nItemsAdded + " but expected " + ret.length);
return ret;
}
示例2: getSplitToArray
/**
* Split the passed text with the given regular expression. If you do not need
* a regular expression, {@link StringHelper#getExploded(String, String)} is a
* faster option.
*
* @param sText
* The text to be split. May be <code>null</code>.
* @param sRegEx
* The regular expression to use for splitting. May neither be
* <code>null</code> nor empty.
* @return An empty array if the text is <code>null</code>, a non-
* <code>null</code> array otherwise. If both text and regular
* expression are <code>null</code> an empty array is returned as well
* since the text parameter is checked first.
*/
@Nonnull
public static String [] getSplitToArray (@Nullable final CharSequence sText, @Nonnull @RegEx final String sRegEx)
{
if (sText == null)
return ArrayHelper.EMPTY_STRING_ARRAY;
return RegExCache.getPattern (sRegEx).split (sText);
}