当前位置: 首页>>代码示例>>Java>>正文


Java ArrayHelper.EMPTY_STRING_ARRAY属性代码示例

本文整理汇总了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 &le;
 *        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;
}
 
开发者ID:phax,项目名称:ph-commons,代码行数:59,代码来源:StringHelper.java

示例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);
}
 
开发者ID:phax,项目名称:ph-commons,代码行数:22,代码来源:RegExHelper.java


注:本文中的com.helger.commons.collection.ArrayHelper.EMPTY_STRING_ARRAY属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。