本文整理汇总了Java中com.helger.commons.string.StringHelper.getExplodedArray方法的典型用法代码示例。如果您正苦于以下问题:Java StringHelper.getExplodedArray方法的具体用法?Java StringHelper.getExplodedArray怎么用?Java StringHelper.getExplodedArray使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.helger.commons.string.StringHelper
的用法示例。
在下文中一共展示了StringHelper.getExplodedArray方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getLocale
import com.helger.commons.string.StringHelper; //导入方法依赖的package包/类
/**
* Get the {@link Locale} object matching the given language.
*
* @param sLanguage
* The language to use. May be <code>null</code> or empty.
* @return <code>null</code> if the passed language string is
* <code>null</code> or empty
*/
@Nullable
public Locale getLocale (@Nullable final String sLanguage)
{
if (sLanguage != null && sLanguage.length () > 2)
{
// parse
final String [] aParts = StringHelper.getExplodedArray (LocaleHelper.LOCALE_SEPARATOR, sLanguage, 3);
if (aParts.length == 3)
return getLocale (aParts[0], aParts[1], aParts[2]);
if (aParts.length == 2)
return getLocale (aParts[0], aParts[1], "");
// else fall through
}
return getLocale (sLanguage, "", "");
}
示例2: testWriteAll
import com.helger.commons.string.StringHelper; //导入方法依赖的package包/类
/**
* Test writing to a list.
*
* @throws IOException
* if the reader fails.
*/
@Test
public void testWriteAll () throws IOException
{
final ICommonsList <ICommonsList <String>> allElements = new CommonsArrayList <> ();
allElements.add (StringHelper.getExploded ('#', "Name#Phone#Email"));
allElements.add (StringHelper.getExploded ('#', "Glen#1234#[email protected]"));
allElements.add (StringHelper.getExploded ('#', "John#5678#[email protected]"));
final NonBlockingStringWriter aSW = new NonBlockingStringWriter ();
try (final CSVWriter aWriter = new CSVWriter (aSW))
{
aWriter.writeAll (allElements);
}
final String sResult = aSW.getAsString ().trim ();
final String [] aLines = StringHelper.getExplodedArray ('\n', sResult);
assertEquals (3, aLines.length);
}
示例3: testWriteAllObjects
import com.helger.commons.string.StringHelper; //导入方法依赖的package包/类
/**
* Test writing from a list.
*
* @throws IOException
* if the reader fails.
*/
@Test
public void testWriteAllObjects () throws IOException
{
final ICommonsList <ICommonsList <String>> allElements = new CommonsArrayList <> ();
allElements.add (StringHelper.getExploded ('#', "Name#Phone#Email"));
allElements.add (StringHelper.getExploded ('#', "Glen#1234#[email protected]"));
allElements.add (StringHelper.getExploded ('#', "John#5678#[email protected]"));
final NonBlockingStringWriter aSW = new NonBlockingStringWriter ();
try (final CSVWriter aWriter = new CSVWriter (aSW))
{
aWriter.writeAll (allElements, false);
}
final String sResult = aSW.getAsString ();
final String [] aLines = StringHelper.getExplodedArray ('\n', sResult.trim ());
assertEquals (3, aLines.length);
final String [] aValues = StringHelper.getExplodedArray (',', aLines[1]);
assertEquals (3, aValues.length);
assertEquals ("1234", aValues[1]);
}
示例4: getFitToWidth
import com.helger.commons.string.StringHelper; //导入方法依赖的package包/类
@Nonnull
@ReturnsMutableCopy
public ICommonsList <TextAndWidthSpec> getFitToWidth (@Nullable final String sText,
@Nonnegative final float fFontSize,
@Nonnegative final float fMaxWidth) throws IOException
{
ValueEnforcer.isGT0 (fFontSize, "FontSize");
ValueEnforcer.isGT0 (fMaxWidth, "MaxWidth");
// First split by the contained line breaks
// In the constructor we ensured that only "\n" is used
final String [] aLines = StringHelper.getExplodedArray ('\n', sText);
final ICommonsList <TextAndWidthSpec> ret = new CommonsArrayList <> ();
for (final String sLine : aLines)
_getLineFitToWidthForward (sLine, fFontSize, fMaxWidth, ret);
return ret;
}
示例5: _extSplit
import com.helger.commons.string.StringHelper; //导入方法依赖的package包/类
@Nonnull
@ReturnsMutableCopy
private static String [] _extSplit (@Nonnull final String s)
{
final String [] aDotParts = StringHelper.getExplodedArray ('.', s, 2);
if (aDotParts.length == 2)
{
// Dots always take precedence
return aDotParts;
}
if (StringParser.isInt (aDotParts[0]))
{
// If it is numeric, use the dot parts anyway (e.g. for "5" or "-1")
return aDotParts;
}
final String [] aDashParts = StringHelper.getExplodedArray ('-', s, 2);
if (aDashParts.length == 1)
{
// Neither dot nor dash present
return aDotParts;
}
// More matches for dash split! (e.g. "0-RC1")
return aDashParts;
}
示例6: containsLocale
import com.helger.commons.string.StringHelper; //导入方法依赖的package包/类
/**
* Check if the passed language is in the cache.
*
* @param sLanguage
* The language to check.
* @return <code>true</code> if it is in the cache, <code>false</code>
* otherwise.
*/
public boolean containsLocale (@Nullable final String sLanguage)
{
if (sLanguage != null && sLanguage.length () > 2)
{
// parse
final String [] aParts = StringHelper.getExplodedArray (LocaleHelper.LOCALE_SEPARATOR, sLanguage, 3);
if (aParts.length == 3)
return containsLocale (aParts[0], aParts[1], aParts[2]);
if (aParts.length == 2)
return containsLocale (aParts[0], aParts[1], "");
// else fall through
}
return containsLocale (sLanguage, "", "");
}
示例7: unifyName
import com.helger.commons.string.StringHelper; //导入方法依赖的package包/类
@Nullable
public static String unifyName (@Nullable final String sName, @Nonnull final Locale aSortLocale)
{
if (sName == null)
return null;
if (!isComplexNameHandlingEnabled ())
{
// Use old compatible name handling: to upper first character
if (sName.length () <= 1)
return sName.toUpperCase (aSortLocale);
return sName.substring (0, 1).toUpperCase (aSortLocale) + sName.substring (1);
}
// empty name?
String s = _unifySinglePart (sName, aSortLocale);
if (s == null)
return null;
// double name handling ("Hans-Peter" or "Hans Peter")
for (final char cSep : new char [] { ' ', '-' })
{
final String [] aParts = StringHelper.getExplodedArray (cSep, s);
if (aParts.length > 1)
{
final StringBuilder aSB = new StringBuilder (s.length ());
for (final String sPart : aParts)
{
final String sRealPart = _unifySinglePart (sPart, aSortLocale);
if (sRealPart == null)
{
// Ignore all empty parts (e.g. "Kai Uwe" with 2 spaces between
continue;
}
if (aSB.length () > 0)
aSB.append (cSep);
aSB.append (sRealPart);
}
s = aSB.toString ();
}
}
return s;
}
示例8: main
import com.helger.commons.string.StringHelper; //导入方法依赖的package包/类
public static void main (final String [] args) throws IOException
{
final String sRevision = "20130111";
final BufferedReader aReader = new BufferedReader (new ClassPathResource ("ISO-639-2_utf-8.txt").getReader (StandardCharsets.UTF_8));
final IMicroDocument aDoc = new MicroDocument ();
final IMicroElement eRoot = aDoc.appendElement ("iso639-2");
String sLine;
// Skip the BOM!
aReader.read ();
while ((sLine = aReader.readLine ()) != null)
{
// An alpha-3 (bibliographic) code
// an alpha-3 (terminologic) code (when given)
// an alpha-2 code (when given)
// an English name
// a French name
final String [] aParts = StringHelper.getExplodedArray ('|', sLine);
if (aParts.length != 5)
throw new IllegalStateException ();
final String sAlpha3B = aParts[0];
final String sAlpha3T = aParts[1];
final String sAlpha2 = aParts[2];
final String sEN = aParts[3];
final String sFR = aParts[4];
if (StringHelper.hasNoText (sAlpha3B))
throw new IllegalArgumentException ("Alpha3B");
if (StringHelper.hasNoText (sEN))
throw new IllegalArgumentException ("EN");
if (StringHelper.hasNoText (sFR))
throw new IllegalArgumentException ("FR");
// "Reserved for local use"
if (sAlpha3B.equals ("qaa-qtz"))
continue;
final IMicroElement eItem = eRoot.appendElement ("item");
eItem.setAttribute ("alpha3", sAlpha3B.toLowerCase (Locale.US));
if (StringHelper.hasText (sAlpha3T))
eItem.setAttribute ("alpha3t", sAlpha3T.toLowerCase (Locale.US));
if (StringHelper.hasText (sAlpha2))
eItem.setAttribute ("alpha2", sAlpha2.toLowerCase (Locale.US));
eItem.setAttribute ("en", sEN);
eItem.setAttribute ("fr", sFR);
}
MicroWriter.writeToFile (aDoc, new File ("src/main/resources/codelists/iso639-2-data-" + sRevision + ".xml"));
}
示例9: _convertToPackage
import com.helger.commons.string.StringHelper; //导入方法依赖的package包/类
@Nonnull
private static String _convertToPackage (@Nonnull final String sNamespaceURI)
{
// Lowercase everything
String s = sNamespaceURI.toLowerCase (Locale.US);
String [] aParts;
final URL aURL = URLHelper.getAsURL (sNamespaceURI);
if (aURL != null)
{
// Host
String sHost = aURL.getHost ();
// Kick static prefix: www.helger.com -> helger.com
sHost = StringHelper.trimStart (sHost, "www.");
// Reverse domain: helger.com -> com.helger
final List <String> x = CollectionHelper.getReverseList (StringHelper.getExploded ('.', sHost));
// Path in regular order:
final String sPath = StringHelper.trimStart (aURL.getPath (), '/');
x.addAll (StringHelper.getExploded ('/', sPath));
// Convert to array
aParts = ArrayHelper.newArray (x, String.class);
}
else
{
// Kick known prefixes
for (final String sPrefix : new String [] { "urn:", "http://" })
if (s.startsWith (sPrefix))
{
s = s.substring (sPrefix.length ());
break;
}
// Replace all illegal characters
s = StringHelper.replaceAll (s, ':', '.');
s = StringHelper.replaceAll (s, '-', '_');
aParts = StringHelper.getExplodedArray ('.', s);
}
// Split into pieces and replace all illegal package parts (e.g. only
// numeric) with valid ones
for (int i = 0; i < aParts.length; ++i)
aParts[i] = RegExHelper.getAsIdentifier (aParts[i]);
return StringHelper.getImploded (".", aParts);
}
示例10: _convertToPackage
import com.helger.commons.string.StringHelper; //导入方法依赖的package包/类
@Nonnull
private static String _convertToPackage (@Nonnull final String sNamespaceURI)
{
// Lowercase everything
String s = sNamespaceURI.toLowerCase (Locale.US);
String [] aParts;
final URL aURL = URLHelper.getAsURL (sNamespaceURI);
if (aURL != null)
{
// Host
String sHost = aURL.getHost ();
// Kick static prefix: www.helger.com -> helger.com
sHost = StringHelper.trimStart (sHost, "www.");
// Reverse domain: helger.com -> com.helger
final ICommonsList <String> x = StringHelper.getExploded ('.', sHost);
x.reverse ();
// Path in regular order:
final String sPath = StringHelper.trimStart (aURL.getPath (), '/');
x.addAll (StringHelper.getExploded ('/', sPath));
// Convert to array
aParts = ArrayHelper.newArray (x, String.class);
}
else
{
// Kick known prefixes
for (final String sPrefix : new String [] { "urn:", "http://" })
if (s.startsWith (sPrefix))
{
s = s.substring (sPrefix.length ());
break;
}
// Replace all illegal characters
s = StringHelper.replaceAll (s, ':', '.');
s = StringHelper.replaceAll (s, '-', '_');
aParts = StringHelper.getExplodedArray ('.', s);
}
// Split into pieces and replace all illegal package parts (e.g. only
// numeric) with valid ones
for (int i = 0; i < aParts.length; ++i)
aParts[i] = RegExHelper.getAsIdentifier (aParts[i]);
return StringHelper.getImploded (".", aParts);
}