Java Code Examples for com.helger.commons.collection.CollectionHelper#newList()

The following examples show how to use com.helger.commons.collection.CollectionHelper#newList() . 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: MapperIteratorTest.java    From ph-commons with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetIteratorWithConversion ()
{
  final Iterator <Integer> it = new MapperIterator <> (CollectionHelper.newList ("100", "-25"),
                                                       StringParser::parseIntObj);
  assertNotNull (it);
  assertTrue (it.hasNext ());
  assertEquals (Integer.valueOf (100), it.next ());
  assertTrue (it.hasNext ());
  assertEquals (Integer.valueOf (-25), it.next ());
  assertFalse (it.hasNext ());

  try
  {
    it.next ();
    fail ();
  }
  catch (final NoSuchElementException ex)
  {}

  it.remove ();
}
 
Example 2
Source File: FilterIteratorTest.java    From ph-commons with Apache License 2.0 6 votes vote down vote up
@Test
public void testIteration1 ()
{
  final List <String> aList = CollectionHelper.newList ("s1", "s2", null, "s3");
  new FilterIterator <> (new IterableIterator <> (aList), Objects::nonNull);
  final FilterIterator <String> it = new FilterIterator <> (aList, Objects::nonNull);
  assertNotNull (it);
  assertSame (it, it.iterator ());

  assertTrue (it.hasNext ());
  assertEquals ("s1", it.next ());
  assertTrue (it.hasNext ());
  assertEquals ("s2", it.next ());
  assertTrue (it.hasNext ());
  assertEquals ("s3", it.next ());
  assertFalse (it.hasNext ());

  try
  {
    // can't call next if hasNext failed
    it.next ();
    fail ();
  }
  catch (final NoSuchElementException ex)
  {}
}
 
Example 3
Source File: FilterIteratorTest.java    From ph-commons with Apache License 2.0 6 votes vote down vote up
@Test
public void testIteration3 ()
{
  // filtered element in the middle
  final List <String> aList = CollectionHelper.newList ("s1", null, "s2", null, "s3");
  final FilterIterator <String> it = new FilterIterator <> (aList, Objects::nonNull);
  assertNotNull (it);

  assertEquals ("s1", it.next ());
  assertEquals ("s2", it.next ());
  assertEquals ("s3", it.next ());

  try
  {
    // can't call next if hasNext failed
    it.next ();
    fail ();
  }
  catch (final NoSuchElementException ex)
  {}
}
 
Example 4
Source File: FilterIteratorTest.java    From ph-commons with Apache License 2.0 6 votes vote down vote up
@Test
public void testIteration4 ()
{
  // filtered elements at the end
  final List <String> aList = CollectionHelper.newList ("s1", "s2", "s3", null, null);
  final FilterIterator <String> it = new FilterIterator <> (aList, Objects::nonNull);
  assertNotNull (it);

  assertEquals ("s1", it.next ());
  assertEquals ("s2", it.next ());
  assertEquals ("s3", it.next ());

  try
  {
    // can't call next if hasNext failed
    it.next ();
    fail ();
  }
  catch (final NoSuchElementException ex)
  {}
}
 
Example 5
Source File: FilterIteratorTest.java    From ph-commons with Apache License 2.0 6 votes vote down vote up
@Test
public void testIteration5 ()
{
  // filtered elements at the beginning
  final List <String> aList = CollectionHelper.newList (null, null, "s1", "s2", "s3");
  final FilterIterator <String> it = new FilterIterator <> (aList, Objects::nonNull);
  assertNotNull (it);

  assertEquals ("s1", it.next ());
  assertEquals ("s2", it.next ());
  assertEquals ("s3", it.next ());

  CommonsTestHelper.testToStringImplementation (it);

  try
  {
    // can't call next if hasNext failed
    it.next ();
    fail ();
  }
  catch (final NoSuchElementException ex)
  {}
}
 
Example 6
Source File: MockUBLTRTestDocuments.java    From ph-ubl with Apache License 2.0 6 votes vote down vote up
@Nonnull
@ReturnsMutableCopy
public static List <String> getUBLTRTestDocuments (@Nonnull final EUBLTRDocumentType eType)
{
  List <String> aFiles = null;
  switch (eType)
  {
    case CANCEL_USER_ACCOUNT:
      aFiles = CollectionHelper.makeUnmodifiable (PREFIX +
                                                  "tr_useraccount/5_KULLANICI_SILME.xml",
                                                  PREFIX + "tr_useraccount/9_FATURA_SAKLAMA_KULLANICI_SILME.xml");
      break;
    case PROCESS_USER_ACCOUNT:
      aFiles = CollectionHelper.makeUnmodifiable (PREFIX +
                                                  "tr_useraccount/4_KULLANICI_ACMA.xml",
                                                  PREFIX + "tr_useraccount/8_FATURA_SAKLAMA_KULLANICI_ACMA.xml");
      break;
    default:
      throw new IllegalArgumentException ("No test files available for type " + eType);
  }

  return CollectionHelper.newList (aFiles);
}
 
Example 7
Source File: IComparatorTest.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
@Test
public void testCollating ()
{
  final List <String> l = CollectionHelper.newList ("a", null, "c");
  assertEquals (3, CollectionHelper.getSorted (l, IComparator.getComparatorCollating (Locale.US)).size ());
  assertEquals (3,
                CollectionHelper.getSorted (l, IComparator.getComparatorCollating (Locale.US).reversed ()).size ());
  assertEquals (3, CollectionHelper.getSorted (l, IComparator.getComparatorCollating (L_EN)).size ());
  assertEquals (3, CollectionHelper.getSorted (l, IComparator.getComparatorCollating (L_FR).reversed ()).size ());
  assertEquals (3,
                CollectionHelper.getSorted (l, IComparator.getComparatorCollating (Collator.getInstance (L_FR)))
                                .size ());
  assertEquals (3,
                CollectionHelper.getSorted (l,
                                            IComparator.getComparatorCollating (Collator.getInstance (L_FR))
                                                       .reversed ())
                                .size ());
  CommonsTestHelper.testToStringImplementation (IComparator.getComparatorCollating (Locale.US));

  try
  {
    IComparator.getComparatorCollating ((Collator) null);
    fail ();
  }
  catch (final NullPointerException ex)
  {}
}
 
Example 8
Source File: FilterIteratorTest.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
@Test
public void testIteration2 ()
{
  final List <String> aList = CollectionHelper.newList ("s1", "s2", null, "s3");
  final FilterIterator <String> it = new FilterIterator <> (aList.iterator (), Objects::nonNull);
  assertNotNull (it);
  assertSame (it, it.iterator ());

  assertTrue (it.hasNext ());
  assertTrue (it.hasNext ());
  assertTrue (it.hasNext ());
  assertEquals ("s1", it.next ());
  assertTrue (it.hasNext ());
  assertTrue (it.hasNext ());
  assertEquals ("s2", it.next ());
  assertTrue (it.hasNext ());
  assertTrue (it.hasNext ());
  assertEquals ("s3", it.next ());
  assertFalse (it.hasNext ());
  assertFalse (it.hasNext ());

  try
  {
    // can't call next if hasNext failed
    it.next ();
    fail ();
  }
  catch (final NoSuchElementException ex)
  {}
}
 
Example 9
Source File: IterableIteratorTest.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
@Test
public void testBasic ()
{
  assertSame (IterableIterator.createEmpty (), IterableIterator.createEmpty ());
  IIterableIterator <String> iit = new IterableIterator <> (ArrayHelper.newArray ("Hallo",
                                                                                  "Welt",
                                                                                  "from",
                                                                                  "Copenhagen"));
  assertNotNull (iit);
  assertNotNull (iit.iterator ());
  assertTrue (iit.hasNext ());
  assertEquals ("Hallo", iit.next ());

  iit = new IterableIterator <> (CollectionHelper.newList ("Hallo", "Welt", "from", "Copenhagen"));
  iit.next ();
  iit.remove ();

  assertEquals (3, CollectionHelper.newList (new IterableIterator <> (new String [] { "a", "b", "c" })).size ());
  assertEquals (3,
                CollectionHelper.newList (new IterableIterator <> (CollectionHelper.newList ("a", "b", "c")))
                                .size ());
  assertEquals (3,
                CollectionHelper.newList (new IterableIterator <> (CollectionHelper.newList ("a", "b", "c")
                                                                                   .iterator ()))
                                .size ());
  CommonsTestHelper.testToStringImplementation (iit);

  try
  {
    new IterableIterator <> ((Iterator <String>) null);
    fail ();
  }
  catch (final NullPointerException ex)
  {}
}
 
Example 10
Source File: AbstractMultiMapTestCase.java    From ph-commons with Apache License 2.0 4 votes vote down vote up
@Nonnull
protected final ICommonsList <String> getValueList1 ()
{
  return CollectionHelper.newList (getValue1 ());
}
 
Example 11
Source File: MockHasChildren.java    From ph-commons with Apache License 2.0 4 votes vote down vote up
public MockHasChildren (@Nonnull final String sID, @Nullable final MockHasChildren... aList)
{
  m_sID = sID;
  m_aList = CollectionHelper.newList (aList);
}
 
Example 12
Source File: MockUBL20TestDocuments.java    From ph-ubl with Apache License 2.0 4 votes vote down vote up
@Nonnull
@ReturnsMutableCopy
public static ICommonsList <String> getUBL20TestDocuments (@Nonnull final EUBL20DocumentType eType)
{
  List <String> aFiles = null;
  switch (eType)
  {
    case CATALOGUE:
      aFiles = UBLTestFiles.CATALOGUE_FILES;
      break;
    case CREDIT_NOTE:
      aFiles = UBLTestFiles.CREDIT_NOTE_FILES;
      break;
    case DEBIT_NOTE:
      aFiles = UBLTestFiles.DEBIT_NOTE_FILES;
      break;
    case DESPATCH_ADVICE:
      aFiles = UBLTestFiles.DESPATCH_ADVICE_FILES;
      break;
    case FORWARDING_INSTRUCTIONS:
      aFiles = UBLTestFiles.FORWARDING_INSTRUCTIONS_FILES;
      break;
    case FREIGHT_INVOICE:
      aFiles = UBLTestFiles.FREIGHT_INVOICE_FILES;
      break;
    case INVOICE:
      aFiles = UBLTestFiles.INVOICE_FILES;
      break;
    case ORDER:
      aFiles = UBLTestFiles.ORDER_FILES;
      break;
    case ORDER_CANCELLATION:
      aFiles = UBLTestFiles.ORDER_CANCELLATION_FILES;
      break;
    case ORDER_RESPONSE:
      aFiles = UBLTestFiles.ORDER_RESPONSE_FILES;
      break;
    case ORDER_RESPONSE_SIMPLE:
      aFiles = UBLTestFiles.ORDER_RESPONSE_SIMPLE_FILES;
      break;
    case QUOTATION:
      aFiles = UBLTestFiles.QUOTATION_FILES;
      break;
    case RECEIPT_ADVICE:
      aFiles = UBLTestFiles.RECEIPT_ADVICE_FILES;
      break;
    case REQUEST_FOR_QUOTATION:
      aFiles = CollectionHelper.newList (UBLTestFiles.REQUEST_FOR_QUOTATION_FILES);
      aFiles.remove ("test-ubl/requestforquotation/UBL-RequestForQuotation-2.1-Example.xml");
      break;
    case REMITTANCE_ADVICE:
      aFiles = UBLTestFiles.REMITTANCE_ADVICE_FILES;
      break;
    case STATEMENT:
      aFiles = UBLTestFiles.STATEMENT_FILES;
      break;
    case WAYBILL:
      aFiles = UBLTestFiles.WAYBILL_FILES;
      break;
    default:
      throw new IllegalArgumentException ("No test files available for type " + eType);
  }

  return CollectionHelper.newList (aFiles);
}
 
Example 13
Source File: ICommonsMap.java    From ph-commons with Apache License 2.0 3 votes vote down vote up
/**
 * Create a copy of all values matching the passed filter.
 *
 * @param aFilter
 *        The filter to be applied. May be <code>null</code>.
 * @return A new list with all matching values. If no filter is provided the
 *         returned value is identical as of {@link #copyOfValues()}
 * @see #values()
 * @see #copyOfValues()
 * @see #copyOfValuesMapped(Function)
 * @see #copyOfValuesMapped(Predicate, Function)
 */
@Nonnull
@ReturnsMutableCopy
default ICommonsList <VALUETYPE> copyOfValues (@Nullable final Predicate <? super VALUETYPE> aFilter)
{
  if (aFilter == null)
    return copyOfValues ();
  return CollectionHelper.newList (values (), aFilter);
}