Java Code Examples for com.helger.commons.collection.impl.ICommonsList#addAll()

The following examples show how to use com.helger.commons.collection.impl.ICommonsList#addAll() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: XMLCharsetDeterminatorTest.java    From ph-commons with Apache License 2.0 6 votes vote down vote up
@Test
public void testAllCharsetsDoubleQuotes ()
{
  for (final Charset c : XMLCharsetDeterminator.getAllSupportedCharsets ())
  {
    final ICommonsList <String> aNames = new CommonsArrayList <> (c.name ());
    aNames.addAll (c.aliases ());
    for (final String sAlias : aNames)
    {
      final String sXML = "<?xml version=\"1.0\" encoding=\"" + sAlias + "\"?><!-- " + c.name () + " --><root />";
      if (false)
        LOGGER.info (sXML);
      final byte [] aBytes = sXML.getBytes (c);
      final Charset aDetermined = XMLCharsetDeterminator.determineXMLCharset (aBytes);
      assertEquals (c, aDetermined);
    }
  }
}
 
Example 2
Source File: XMLCharsetDeterminatorTest.java    From ph-commons with Apache License 2.0 6 votes vote down vote up
@Test
public void testAllCharsetsSingleQuotes ()
{
  for (final Charset c : XMLCharsetDeterminator.getAllSupportedCharsets ())
  {
    final ICommonsList <String> aNames = new CommonsArrayList <> (c.name ());
    aNames.addAll (c.aliases ());
    for (final String sAlias : aNames)
    {
      final String sXML = "<?xml version=\"1.0\" encoding='" + sAlias + "'?><!-- " + c.name () + " --><root />";
      if (false)
        LOGGER.info (sXML);
      final byte [] aBytes = sXML.getBytes (c);
      final Charset aDetermined = XMLCharsetDeterminator.determineXMLCharset (aBytes);
      assertEquals (c, aDetermined);
    }
  }
}
 
Example 3
Source File: XMLCharsetDeterminatorTest.java    From ph-commons with Apache License 2.0 6 votes vote down vote up
@Test
public void testAllBOMCharsets ()
{
  for (final EUnicodeBOM eBOM : EUnicodeBOM.values ())
    if (eBOM.hasCharset ())
    {
      final Charset c = eBOM.getCharset ();
      final ICommonsList <String> aNames = new CommonsArrayList <> (c.name ());
      aNames.addAll (c.aliases ());
      for (final String sAlias : aNames)
      {
        final String sXML = "<?xml version=\"1.0\" encoding=\"" + sAlias + "\"?><!-- " + c.name () + " --><root />";
        if (false)
          LOGGER.info (sXML);
        final byte [] aBytes = sXML.getBytes (c);
        assertFalse ("Charset " + sAlias + " already contains BOM " + eBOM, eBOM.isPresent (aBytes));

        // Prefix with BOM
        final Charset aDetermined = XMLCharsetDeterminator.determineXMLCharset (ArrayHelper.getConcatenated (eBOM.getAllBytes (),
                                                                                                             aBytes));
        assertEquals (c, aDetermined);
      }
    }
}
 
Example 4
Source File: CSVReader.java    From ph-commons with Apache License 2.0 6 votes vote down vote up
/**
 * Reads the next line from the buffer and converts to a string array.
 *
 * @return a string array with each comma-separated element as a separate
 *         entry.
 * @throws IOException
 *         if bad things happen during the read
 */
@Nullable
public ICommonsList <String> readNext () throws IOException
{
  ICommonsList <String> ret = null;
  do
  {
    final String sNextLine = _getNextLine ();
    if (!m_bHasNext)
    {
      // should throw if still pending?
      return ret;
    }
    final ICommonsList <String> r = m_aParser.parseLineMulti (sNextLine);
    if (ret == null)
      ret = r;
    else
      ret.addAll (r);
  } while (m_aParser.isPending ());
  return ret;
}
 
Example 5
Source File: Options.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
@Nonnull
@ReturnsMutableCopy
public ICommonsList <Option> getAllResolvedOptions ()
{
  final ICommonsList <Option> ret = new CommonsArrayList <> ();
  for (final IOptionBase aOptionBase : m_aOptions)
    if (aOptionBase instanceof Option)
      ret.add ((Option) aOptionBase);
    else
      ret.addAll (((OptionGroup) aOptionBase).getAllOptions ());
  return ret;
}
 
Example 6
Source File: MainFindOccurrances.java    From ph-ubl with Apache License 2.0 5 votes vote down vote up
/**
 * Get all fields of the specified class and all super classes.
 *
 * @param aClass
 *        Base class
 * @param aList
 *        List to be filled
 */
private static void _getAllFields (@Nonnull final Class <?> aClass, @Nonnull final ICommonsList <Field> aList)
{
  aList.addAll (aClass.getDeclaredFields ());

  final Class <?> aSuperClass = aClass.getSuperclass ();
  if (aSuperClass != null && !_isSystemClass (aSuperClass))
    _getAllFields (aSuperClass, aList);
}
 
Example 7
Source File: MainCreateJAXBBinding20.java    From ph-ubl with Apache License 2.0 4 votes vote down vote up
@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);
}