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

The following examples show how to use com.helger.commons.collection.impl.ICommonsList#add() . 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: AbstractConcurrentCollector.java    From ph-commons with Apache License 2.0 6 votes vote down vote up
@Nonnull
@ReturnsMutableCopy
public final ICommonsList <DATATYPE> drainQueue ()
{
  // Drain all objects to this queue
  final ICommonsList <Object> aDrainedToList = new CommonsArrayList <> ();
  m_aRWLock.writeLockedInt ( () -> m_aQueue.drainTo (aDrainedToList));

  // Change data type
  final ICommonsList <DATATYPE> ret = new CommonsArrayList <> ();
  for (final Object aObj : aDrainedToList)
    if (!EqualsHelper.identityEqual (aObj, STOP_QUEUE_OBJECT))
      ret.add (GenericReflection.uncheckedCast (aObj));
    else
    {
      // Re-add the stop object, because loops in derived classes rely on this
      // object
      m_aRWLock.writeLockedBoolean ( () -> m_aQueue.add (aObj));
    }
  return ret;
}
 
Example 2
Source File: SVRLHelper.java    From ph-schematron with Apache License 2.0 6 votes vote down vote up
/**
 * Get a list of all successful reports in a given schematron output, with an
 * error level equally or more severe than the passed error level.
 *
 * @param aSchematronOutput
 *        The schematron output to be used. May be <code>null</code>.
 * @param aErrorLevel
 *        Minimum error level to be queried
 * @return A non-<code>null</code> list with all successful reports.
 */
@Nonnull
@ReturnsMutableCopy
public static ICommonsList <SVRLSuccessfulReport> getAllSuccessfulReportsMoreOrEqualSevereThan (@Nullable final SchematronOutputType aSchematronOutput,
                                                                                                @Nonnull final IErrorLevel aErrorLevel)
{
  final ICommonsList <SVRLSuccessfulReport> ret = new CommonsArrayList <> ();
  if (aSchematronOutput != null)
    for (final Object aObj : aSchematronOutput.getActivePatternAndFiredRuleAndFailedAssert ())
      if (aObj instanceof SuccessfulReport)
      {
        final SVRLSuccessfulReport aSR = new SVRLSuccessfulReport ((SuccessfulReport) aObj);
        if (aSR.getFlag ().isGE (aErrorLevel))
          ret.add (aSR);
      }
  return ret;
}
 
Example 3
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 4
Source File: MainBenchmarkIsValidSchematron.java    From ph-schematron with Apache License 2.0 6 votes vote down vote up
public static void main (final String [] args)
{
  logSystemInfo ();

  final ICommonsList <IReadableResource> aValidSchematrons = new CommonsArrayList <> ();
  for (final IReadableResource aRes : SchematronTestHelper.getAllValidSchematronFiles ())
    if (!aRes.getPath ().endsWith ("/BIICORE-UBL-T01.sch") &&
        !aRes.getPath ().endsWith ("/BIICORE-UBL-T10.sch") &&
        !aRes.getPath ().endsWith ("/BIICORE-UBL-T14.sch") &&
        !aRes.getPath ().endsWith ("/BIICORE-UBL-T15.sch") &&
        !aRes.getPath ().endsWith ("/CellarBook.sch") &&
        !aRes.getPath ().endsWith ("/pattern-example-with-includes.sch") &&
        !aRes.getPath ().endsWith ("/pattern-example.sch") &&
        !aRes.getPath ().endsWith ("/schematron-svrl.sch"))
      aValidSchematrons.add (aRes);

  LOGGER.info ("Starting");

  final double dTime1 = benchmarkTask (new ValidSchematronPure (aValidSchematrons));
  LOGGER.info ("Time pure: " + BigDecimal.valueOf (dTime1).toString () + " us");

  final double dTime2 = benchmarkTask (new ValidSchematronSCH (aValidSchematrons));
  LOGGER.info ("Time XSLT: " + BigDecimal.valueOf (dTime2).toString () + " us");

  LOGGER.info ("Time1 is " + BigDecimal.valueOf (dTime1 / dTime2 * 100).toString () + "% of time2");
}
 
Example 5
Source File: TextHelperTest.java    From ph-commons with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetCopyWithLocales ()
{
  final MultilingualText aMLT = new MultilingualText ();
  assertTrue (aMLT.setText (Locale.ENGLISH, "Hi").isChanged ());
  assertTrue (aMLT.setText (Locale.GERMAN, "Moin").isChanged ());
  assertEquals (2, aMLT.texts ().size ());

  final ICommonsList <Locale> aLocaleList = new CommonsArrayList <> ();
  aLocaleList.add (Locale.ENGLISH);
  final MultilingualText aMLT2 = TextHelper.getCopyWithLocales (aMLT, aLocaleList);
  assertTrue (aMLT2.texts ().containsKey (Locale.ENGLISH));
  assertFalse (aMLT2.texts ().containsKey (Locale.GERMAN));

  assertTrue (aMLT.texts ().containsKey (Locale.ENGLISH));
  assertTrue (aMLT.texts ().containsKey (Locale.GERMAN));
}
 
Example 6
Source File: JAXBContextCacheKey.java    From ph-commons with Apache License 2.0 6 votes vote down vote up
/**
 * @return The list of classes passed in the constructor. May be
 *         <code>null</code>.
 */
@Nullable
@ReturnsMutableCopy
private ICommonsList <Class <?>> _getAllClasses ()
{
  ICommonsList <Class <?>> ret = null;
  if (m_aClasses != null)
  {
    ret = new CommonsArrayList <> ();
    for (final WeakReference <Class <?>> aItem : m_aClasses)
    {
      final Class <?> aClass = aItem.get ();
      if (aClass != null)
        ret.add (aClass);
    }
  }
  return ret;
}
 
Example 7
Source File: GraphIterator.java    From ph-commons with Apache License 2.0 6 votes vote down vote up
private void _traverseDFS (@Nonnull final IMutableGraphNode aStartNode,
                           @Nonnull final ICommonsList <IMutableGraphNode> aList)
{
  m_aHandledObjects.add (aStartNode.getID ());
  aList.add (aStartNode);
  for (final IMutableGraphRelation aRelation : aStartNode.getAllRelations ())
  {
    final boolean bNewRelation = m_aHandledObjects.add (aRelation.getID ());
    for (final IMutableGraphNode aNode : aRelation.getAllConnectedNodes ())
      if (!EqualsHelper.identityEqual (aNode, aStartNode))
      {
        if (!m_aHandledObjects.contains (aNode.getID ()))
          _traverseDFS (aNode, aList);
        else
        {
          // If an unexplored edge leads to a node visited before, then the
          // graph contains a cycle.
          if (bNewRelation)
            m_bHasCycles = true;
        }
      }
  }
}
 
Example 8
Source File: SchematronHelper.java    From ph-schematron with Apache License 2.0 5 votes vote down vote up
/**
 * Get a list of all supported namespaces.
 *
 * @param bLenient
 *        <code>true</code> to support old namespace URIs, <code>false</code>
 *        if not.
 * @return The non-<code>null</code> and non-empty list of all supported
 *         schematron namespace URIs.
 * @since 5.4.1
 */
@Nonnull
@Nonempty
@ReturnsMutableCopy
public static ICommonsList <String> getAllValidSchematronNS (final boolean bLenient)
{
  final ICommonsList <String> ret = new CommonsArrayList <> (2);
  ret.add (CSchematron.NAMESPACE_SCHEMATRON);
  if (bLenient)
    ret.add (CSchematron.DEPRECATED_NAMESPACE_SCHEMATRON);
  return ret;
}
 
Example 9
Source File: CSSNode.java    From ph-css with Apache License 2.0 5 votes vote down vote up
@Nonnull
public Iterator <CSSNode> iterator ()
{
  final ICommonsList <CSSNode> aChildren = new CommonsArrayList <> (jjtGetNumChildren ());
  if (m_aChildren != null)
    for (final CSSNode aChildNode : m_aChildren)
      if (aChildNode != null)
        aChildren.add (aChildNode);
  return aChildren.iterator ();
}
 
Example 10
Source File: SVRLHelper.java    From ph-schematron with Apache License 2.0 5 votes vote down vote up
/**
 * Get a list of all failed assertions in a given schematron output.
 *
 * @param aSchematronOutput
 *        The schematron output to be used. May be <code>null</code>.
 * @return A non-<code>null</code> list with all failed assertions.
 */
@Nonnull
@ReturnsMutableCopy
public static ICommonsList <SVRLFailedAssert> getAllFailedAssertions (@Nullable final SchematronOutputType aSchematronOutput)
{
  final ICommonsList <SVRLFailedAssert> ret = new CommonsArrayList <> ();
  if (aSchematronOutput != null)
    for (final Object aObj : aSchematronOutput.getActivePatternAndFiredRuleAndFailedAssert ())
      if (aObj instanceof FailedAssert)
        ret.add (new SVRLFailedAssert ((FailedAssert) aObj));
  return ret;
}
 
Example 11
Source File: JsonWriterTest.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
@Test
public void testComplex ()
{
  final ICommonsList <JsonObject> aObjs = new CommonsArrayList <> ();
  for (final ICommonsMap <String, String> aRow : new CommonsArrayList <> (CollectionHelper.newMap ("key", "value")))
  {
    final JsonObject aObj = new JsonObject ();
    for (final Map.Entry <String, String> aEntry : aRow.entrySet ())
      aObj.add (aEntry.getKey (), aEntry.getValue ());
    aObjs.add (aObj);
  }
  assertEquals ("{\"aa\":[{\"key\":\"value\"}]}", JsonConverter.convertToJson (new JsonObject ().add ("aa", aObjs)).getAsJsonString ());
}
 
Example 12
Source File: CloneHelper.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
/**
 * Get a list where each contained item is also cloned. Like a deep copy.
 *
 * @param aList
 *        Source list. May be <code>null</code>.
 * @return The cloned list. Never <code>null</code> but maybe empty if the
 *         source list is empty.
 * @param <DATATYPE>
 *        The list element type to be cloned
 */
@Nonnull
@ReturnsMutableCopy
public static <DATATYPE> ICommonsList <DATATYPE> getGenericClonedList (@Nullable final Iterable <DATATYPE> aList)
{
  final ICommonsList <DATATYPE> ret = new CommonsArrayList <> ();
  if (aList != null)
    for (final DATATYPE aItem : aList)
      ret.add (getClonedValue (aItem));
  return ret;
}
 
Example 13
Source File: BenchmarkTrie.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
private static void execute () throws IOException
{
  final ICommonsList <String> aStrings = _readWordList (new ClassPathResource ("wordlist/english-words.95"),
                                                        StandardCharsets.ISO_8859_1);
  if (true)
  {
    // 309 chars
    aStrings.add ("Very long string!! Very long string!! Very long string!! Very long string!! Very long string!! Very long string!! Very long string!! Very long string!! Very long string!! Very long string!! Very long string!! Very long string!! Very long string!! Very long string!! Very long string!! Very long string!! Very ");
    // 1024 chars
    aStrings.add (StringHelper.getRepeated ("a", 1024));
  }
  final String [] aStringArray = aStrings.toArray (new String [aStrings.size ()]);
  LOGGER.info ("Comparing " +
               aStrings.size () +
               " strings from word list; The longest string is " +
               _getMaxStringLength (aStrings) +
               " chars!");

  final AbstractStringMapBase aL1a = new StringMapHashMap (aStringArray);
  final AbstractStringMapBase aL1b = new StringMapTreeMap (aStringArray);
  final AbstractStringMapBase aL2a = new StringMapTST (aStringArray);
  LOGGER.info ("Initial check done!");

  double dTime;

  dTime = benchmarkTask (aL2a);
  LOGGER.info ("StringMapTST: " + LocaleFormatter.getFormatted (dTime, Locale.ENGLISH) + " ns");
  LOGGER.info (aL2a.size () + " entries");

  dTime = benchmarkTask (aL1a);
  LOGGER.info ("StringMapHashMap: " + LocaleFormatter.getFormatted (dTime, Locale.ENGLISH) + " ns");
  LOGGER.info (aL1a.size () + " entries");

  dTime = benchmarkTask (aL1b);
  LOGGER.info ("StringMapTreeMap: " + LocaleFormatter.getFormatted (dTime, Locale.ENGLISH) + " ns");
  LOGGER.info (aL1b.size () + " entries");
}
 
Example 14
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 15
Source File: AbstractSingleton.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
/**
 * Get all singleton objects registered in the respective sub-class of this
 * class.
 *
 * @param <T>
 *        The singleton type to be retrieved
 * @param aScope
 *        The scope to use. May be <code>null</code> to avoid creating a new
 *        scope.
 * @param aDesiredClass
 *        The desired sub-class of this class. May not be <code>null</code>.
 * @return A non-<code>null</code> list with all instances of the passed class
 *         in the passed scope.
 */
@Nonnull
@ReturnsMutableCopy
public static final <T extends AbstractSingleton> ICommonsList <T> getAllSingletons (@Nullable final IScope aScope,
                                                                                     @Nonnull final Class <T> aDesiredClass)
{
  ValueEnforcer.notNull (aDesiredClass, "DesiredClass");

  final ICommonsList <T> ret = new CommonsArrayList <> ();
  if (aScope != null)
    for (final Object aScopeValue : aScope.attrs ().values ())
      if (aScopeValue != null && aDesiredClass.isAssignableFrom (aScopeValue.getClass ()))
        ret.add (aDesiredClass.cast (aScopeValue));
  return ret;
}
 
Example 16
Source File: SVRLHelper.java    From ph-schematron with Apache License 2.0 5 votes vote down vote up
/**
 * Get a list of all successful reports in a given schematron output.
 *
 * @param aSchematronOutput
 *        The schematron output to be used. May be <code>null</code>.
 * @return A non-<code>null</code> list with all successful reports.
 */
@Nonnull
@ReturnsMutableCopy
public static ICommonsList <SVRLSuccessfulReport> getAllSuccessfulReports (@Nullable final SchematronOutputType aSchematronOutput)
{
  final ICommonsList <SVRLSuccessfulReport> ret = new CommonsArrayList <> ();
  if (aSchematronOutput != null)
    for (final Object aObj : aSchematronOutput.getActivePatternAndFiredRuleAndFailedAssert ())
      if (aObj instanceof SuccessfulReport)
        ret.add (new SVRLSuccessfulReport ((SuccessfulReport) aObj));
  return ret;
}
 
Example 17
Source File: CombinationGenerator.java    From ph-commons with Apache License 2.0 4 votes vote down vote up
/**
 * Generate next combination (algorithm from Rosen p. 286)
 *
 * @return the next combination as list of the size specified for slots filled
 *         with elements from the original list
 */
@Nonnull
@ReturnsMutableCopy
public ICommonsList <DATATYPE> next ()
{
  if (!hasNext ())
    throw new NoSuchElementException ();

  // Not for the very first item, as the first item is the original order
  final boolean bFirstItem = m_bUseLong ? m_nCombinationsLeft == m_nTotalCombinations
                                        : m_aCombinationsLeft.equals (m_aTotalCombinations);
  if (!bFirstItem)
  {
    final int nElementCount = m_aElements.length;
    final int nSlotCount = m_aIndexResult.length;

    int i = nSlotCount - 1;
    while (m_aIndexResult[i] == (nElementCount - nSlotCount + i))
    {
      i--;
    }
    m_aIndexResult[i]++;
    final int nIndexResultI = m_aIndexResult[i];
    for (int j = i + 1; j < nSlotCount; j++)
    {
      m_aIndexResult[j] = nIndexResultI + j - i;
    }
  }

  // One combination less
  if (m_bUseLong)
    m_nCombinationsLeft--;
  else
    m_aCombinationsLeft = m_aCombinationsLeft.subtract (BigInteger.ONE);

  // Build result list
  final ICommonsList <DATATYPE> aResult = new CommonsArrayList <> (m_aIndexResult.length);
  for (final int nIndex : m_aIndexResult)
    aResult.add (m_aElements[nIndex]);
  return aResult;
}
 
Example 18
Source File: BenchmarkLevenshteinDistance.java    From ph-commons with Apache License 2.0 4 votes vote down vote up
private static void findWhetherSynchronizedOrLockAreFaster () throws IOException
{
  final ICommonsList <String> aStrings = _readWordList (new ClassPathResource ("wordlist/english-words.95"),
                                                        StandardCharsets.ISO_8859_1);
  if (true)
  {
    aStrings.remove (0);
    aStrings.remove (0);
    // 309 chars
    aStrings.add ("Very long string!! Very long string!! Very long string!! Very long string!! Very long string!! Very long string!! Very long string!! Very long string!! Very long string!! Very long string!! Very long string!! Very long string!! Very long string!! Very long string!! Very long string!! Very long string!! Very ");
    // 1024 chars
    aStrings.add (StringHelper.getRepeated ("a", 1024));
  }
  final String [] aStringArray = aStrings.toArray (new String [0]);
  LOGGER.info ("Comparing " +
               aStrings.size () +
               " strings from word list; The longest string is " +
               _getMaxStringLength (aStrings) +
               " chars!");

  final LevDist0StringHelper aL0 = new LevDist0StringHelper (aStringArray);
  final AbstractLevDist aL1a = new LevDist1a (aStringArray);
  final AbstractLevDist aL1b = new LevDist1b (aStringArray);
  final AbstractLevDist aL2a = new LevDist2a (aStringArray);
  final AbstractLevDist aL2b = new LevDist2b (aStringArray);

  // Check algo once for all texts!
  for (int i = 0; i < aStringArray.length - 1; ++i)
  {
    final String s1 = aStringArray[i];
    for (int j = i + 1; j < aStringArray.length; ++j)
    {
      final String s2 = aStringArray[j];
      final int n0 = LevenshteinDistance.getDistance (s1, s2, LV_COST_INSERT, LV_COST_DELETE, LV_COST_SUBSTITUTE);
      final int n1a = aL1a.levDist (s1, s2);
      final int n1b = aL1b.levDist (s1, s2);
      final int n2a = aL2a.levDist (s1, s2);
      final int n2b = aL2b.levDist (s1, s2);
      if (!(n0 == n1a && n1a == n1b && n1b == n2a && n2a == n2b))
        throw new IllegalArgumentException ("Implementation differences!");
    }
  }
  LOGGER.info ("Initial check done!");

  double dTime = benchmarkTask (aL0);
  LOGGER.info ("*LevDist0: " + LocaleFormatter.getFormatted (dTime, Locale.ENGLISH) + " ns");

  dTime = benchmarkTask (aL1a);
  LOGGER.info ("LevDist1a: " + LocaleFormatter.getFormatted (dTime, Locale.ENGLISH) + " ns");

  dTime = benchmarkTask (aL1b);
  LOGGER.info ("LevDist1b: " + LocaleFormatter.getFormatted (dTime, Locale.ENGLISH) + " ns");

  dTime = benchmarkTask (aL2a);
  LOGGER.info ("LevDist2a: " + LocaleFormatter.getFormatted (dTime, Locale.ENGLISH) + " ns");

  dTime = benchmarkTask (aL2b);
  LOGGER.info ("LevDist2b: " + LocaleFormatter.getFormatted (dTime, Locale.ENGLISH) + " ns");
}
 
Example 19
Source File: ConcurrentCollectorMultiple.java    From ph-commons with Apache License 2.0 4 votes vote down vote up
/**
 * This method starts the collector by taking objects from the internal
 * {@link BlockingQueue}. So this method blocks and must be invoked from a
 * separate thread. This method runs until {@link #stopQueuingNewObjects()} is
 * new called and the queue is empty.
 *
 * @throws IllegalStateException
 *         if no performer is set - see
 *         {@link #setPerformer(IConcurrentPerformer)}
 */
public final void collect ()
{
  if (m_aPerformer == null)
    throw new IllegalStateException ("No performer set!");

  try
  {
    // The temporary list that contains all objects to be delivered
    final ICommonsList <DATATYPE> aObjectsToPerform = new CommonsArrayList <> ();
    boolean bQueueIsStopped = false;

    while (true)
    {
      // Block until the first object is in the queue
      Object aCurrentObject = m_aQueue.take ();
      if (EqualsHelper.identityEqual (aCurrentObject, STOP_QUEUE_OBJECT))
        break;

      // add current object
      aObjectsToPerform.add (GenericReflection.uncheckedCast (aCurrentObject));

      // take all messages that are in the queue and handle them at once.
      // Handle at last m_nMaxPerformSize objects
      while (aObjectsToPerform.size () < m_nMaxPerformCount && !m_aQueue.isEmpty ())
      {
        // Explicitly handle the "stop queue message" (using "=="!!!)
        aCurrentObject = m_aQueue.take ();
        if (EqualsHelper.identityEqual (aCurrentObject, STOP_QUEUE_OBJECT))
        {
          bQueueIsStopped = true;
          break;
        }

        // add current object
        aObjectsToPerform.add (GenericReflection.uncheckedCast (aCurrentObject));
      }

      _perform (aObjectsToPerform);

      // In case we received a stop message while getting the bulk messages
      // above -> break the loop manually
      // Note: do not include in while-loop above because the conditions may
      // not execute in the correct order since "take" is blocking!
      if (bQueueIsStopped)
        break;
    }

    // perform any remaining actions
    _perform (aObjectsToPerform);
  }
  catch (final Exception ex)
  {
    LOGGER.error ("Error taking elements from queue - queue has been interrupted!!!", ex);
  }
}
 
Example 20
Source File: ServiceLoaderHelper.java    From ph-commons with Apache License 2.0 4 votes vote down vote up
/**
 * Uses the {@link ServiceLoader} to load all SPI implementations of the
 * passed class
 *
 * @param <T>
 *        The implementation type to be loaded
 * @param aSPIClass
 *        The SPI interface class. May not be <code>null</code>.
 * @param aClassLoader
 *        The class loader to use for the SPI loader. May not be
 *        <code>null</code>.
 * @param aLogger
 *        An optional logger to use. May be <code>null</code>.
 * @return A collection of all currently available plugins. Never
 *         <code>null</code>.
 */
@Nonnull
@ReturnsMutableCopy
public static <T> ICommonsList <T> getAllSPIImplementations (@Nonnull final Class <T> aSPIClass,
                                                             @Nonnull final ClassLoader aClassLoader,
                                                             @Nullable final Logger aLogger)
{
  ValueEnforcer.notNull (aSPIClass, "SPIClass");
  ValueEnforcer.notNull (aClassLoader, "ClassLoader");

  final Logger aRealLogger = aLogger != null ? aLogger : LOGGER;

  if (aRealLogger.isTraceEnabled ())
    aRealLogger.trace ("Trying to retrieve all SPI implementations of " + aSPIClass);

  if (!s_aCacheInterface.hasAnnotation (aSPIClass))
    if (LOGGER.isWarnEnabled ())
      LOGGER.warn (aSPIClass + " should have the @IsSPIInterface annotation");

  final ServiceLoader <T> aServiceLoader = ServiceLoader.<T> load (aSPIClass, aClassLoader);
  final ICommonsList <T> ret = new CommonsArrayList <> ();

  // We use the iterator to be able to catch exceptions thrown
  // when loading SPI implementations (e.g. the SPI implementation class does
  // not exist)
  final Iterator <T> aIterator = aServiceLoader.iterator ();
  while (aIterator.hasNext ())
  {
    try
    {
      final T aInstance = aIterator.next ();
      if (!s_aCacheImplementation.hasAnnotation (aInstance))
        if (LOGGER.isWarnEnabled ())
          LOGGER.warn (aInstance + " should have the @IsSPIImplementation annotation");
      ret.add (aInstance);
    }
    catch (final Exception ex)
    {
      aRealLogger.error ("Unable to load an SPI implementation of " + aSPIClass, ex);
    }
  }

  if (aRealLogger.isDebugEnabled ())
    aRealLogger.debug ("Finished retrieving all " + ret.size () + " SPI implementations of " + aSPIClass);

  return ret;
}