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

The following examples show how to use com.helger.commons.collection.impl.ICommonsList#get() . 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: UnicodeFuncTest.java    From ph-commons with Apache License 2.0 6 votes vote down vote up
@Test
public void testWriteThenReadTwiceAscii () throws IOException
{
  final NonBlockingStringWriter aSW = new NonBlockingStringWriter ();
  try (final CSVWriter aWriter = new CSVWriter (aSW))
  {
    aWriter.writeNext (ASCII_ARRAY);
    aWriter.writeNext (ASCII_ARRAY);

    try (final CSVReader aReader = new CSVReader (new NonBlockingStringReader (aSW.getAsString ())))
    {
      final ICommonsList <ICommonsList <String>> aLines = aReader.readAll ();
      assertEquals (2, aLines.size ());

      ICommonsList <String> aItems = aLines.get (0);
      assertEquals (2, aItems.size ());
      assertEquals (ASCII_ARRAY, aItems);

      aItems = aLines.get (1);
      assertEquals (2, aItems.size ());
      assertEquals (ASCII_ARRAY, aItems);
    }
  }
}
 
Example 2
Source File: UnicodeFuncTest.java    From ph-commons with Apache License 2.0 6 votes vote down vote up
@Test
public void testWriteThenReadTwiceUnicode () throws IOException
{
  final NonBlockingStringWriter aSW = new NonBlockingStringWriter ();
  try (final CSVWriter aWriter = new CSVWriter (aSW))
  {
    aWriter.writeNext (UNICODE_ARRAY);
    aWriter.writeNext (UNICODE_ARRAY);

    try (final CSVReader aReader = new CSVReader (new NonBlockingStringReader (aSW.getAsString ())))
    {
      final ICommonsList <ICommonsList <String>> aLines = aReader.readAll ();
      assertEquals (2, aLines.size ());

      ICommonsList <String> aItems = aLines.get (0);
      assertEquals (2, aItems.size ());
      assertEquals (UNICODE_ARRAY, aItems);

      aItems = aLines.get (1);
      assertEquals (2, aItems.size ());
      assertEquals (UNICODE_ARRAY, aItems);
    }
  }
}
 
Example 3
Source File: UnicodeFuncTest.java    From ph-commons with Apache License 2.0 6 votes vote down vote up
@Test
public void testWriteThenReadTwiceMixedUnicode () throws IOException
{
  final NonBlockingStringWriter aSW = new NonBlockingStringWriter ();
  try (final CSVWriter aWriter = new CSVWriter (aSW))
  {
    aWriter.writeNext (MIXED_ARRAY);
    aWriter.writeNext (MIXED_ARRAY);

    try (final CSVReader aReader = new CSVReader (new NonBlockingStringReader (aSW.getAsString ())))
    {
      final ICommonsList <ICommonsList <String>> aLines = aReader.readAll ();
      assertEquals (2, aLines.size ());

      ICommonsList <String> aItems = aLines.get (0);
      assertEquals (4, aItems.size ());
      assertEquals (MIXED_ARRAY, aItems);

      aItems = aLines.get (1);
      assertEquals (4, aItems.size ());
      assertEquals (MIXED_ARRAY, aItems);
    }
  }
}
 
Example 4
Source File: CSVReaderTest.java    From ph-commons with Apache License 2.0 6 votes vote down vote up
/**
 * Tests iterating over a reader.
 *
 * @throws IOException
 *         if the reader fails.
 */
@Test
public void testIteratorFunctionality () throws IOException
{
  final ICommonsList <ICommonsList <String>> expectedResult = new CommonsArrayList <> ();
  expectedResult.add (CollectionHelper.newList ("a", "b", "aReader"));
  expectedResult.add (CollectionHelper.newList ("a", "b,b,b", "aReader"));
  expectedResult.add (CollectionHelper.newList ("", "", ""));
  expectedResult.add (CollectionHelper.newList ("a", "PO Box 123,\nKippax,ACT. 2615.\nAustralia", "d."));
  expectedResult.add (CollectionHelper.newList ("Glen \"The Man\" Smith", "Athlete", "Developer"));
  expectedResult.add (CollectionHelper.newList ("\"\"", "test"));
  expectedResult.add (CollectionHelper.newList ("a\nb", "b", "\nd", "e"));
  int idx = 0;
  try (final CSVReader aReader = _createCSVReader ())
  {
    for (final ICommonsList <String> line : aReader)
    {
      final ICommonsList <String> expectedLine = expectedResult.get (idx++);
      assertEquals (expectedLine, line);
    }
  }
}
 
Example 5
Source File: URLHelper.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
@Nonnull
@ReturnsMutableCopy
public static URLParameterList getParsedQueryParameters (@Nullable final String sQueryString,
                                                         @Nullable final IDecoder <String, String> aParameterDecoder)
{
  final URLParameterList aMap = new URLParameterList ();
  if (StringHelper.hasText (sQueryString))
  {
    for (final String sKeyValuePair : StringHelper.getExploded (AMPERSAND, sQueryString))
      if (sKeyValuePair.length () > 0)
      {
        final ICommonsList <String> aParts = StringHelper.getExploded (EQUALS, sKeyValuePair, 2);
        final String sKey = aParts.get (0);
        // Maybe empty when passing something like "url?=value"
        if (StringHelper.hasText (sKey))
        {
          final String sValue = aParts.size () == 2 ? aParts.get (1) : "";
          if (sValue == null)
            throw new IllegalArgumentException ("parameter value may not be null");
          if (aParameterDecoder != null)
          {
            // Now decode the name and the value
            aMap.add (aParameterDecoder.getDecoded (sKey), aParameterDecoder.getDecoded (sValue));
          }
          else
            aMap.add (sKey, sValue);
        }
      }
  }
  return aMap;
}
 
Example 6
Source File: PDTDisplayHelper.java    From ph-commons with Apache License 2.0 4 votes vote down vote up
@Nonnull
@Nonempty
public static String getPeriodText (final int nYears,
                                    final int nMonths,
                                    final int nDays,
                                    final long nHours,
                                    final long nMinutes,
                                    final long nSeconds,
                                    @Nonnull final IPeriodTextProvider aTextProvider)
{
  final String sYear = aTextProvider.getYears (nYears);
  final String sMonth = aTextProvider.getMonths (nMonths);
  final String sDay = aTextProvider.getDays (nDays);
  final String sHour = aTextProvider.getHours (nHours);
  final String sMinute = aTextProvider.getMinutes (nMinutes);
  final String sSecond = aTextProvider.getSeconds (nSeconds);

  // Skip all "leading 0" parts
  final ICommonsList <String> aParts = new CommonsArrayList <> (6);
  if (nYears != 0)
    aParts.add (sYear);
  if (nMonths != 0 || aParts.isNotEmpty ())
    aParts.add (sMonth);
  if (nDays != 0 || aParts.isNotEmpty ())
    aParts.add (sDay);
  if (nHours != 0 || aParts.isNotEmpty ())
    aParts.add (sHour);
  if (nMinutes != 0 || aParts.isNotEmpty ())
    aParts.add (sMinute);
  aParts.add (sSecond);

  final int nParts = aParts.size ();
  if (nParts == 1)
    return aParts.get (0);
  if (nParts == 2)
    return aParts.get (0) + aTextProvider.getAnd () + aParts.get (1);

  final StringBuilder aSB = new StringBuilder ();
  for (int i = 0; i < nParts - 1; ++i)
  {
    if (aSB.length () > 0)
      aSB.append (aTextProvider.getComma ());
    aSB.append (aParts.get (i));
  }
  return aSB.append (aTextProvider.getAnd ()).append (aParts.getLast ()).toString ();
}