Java Code Examples for com.helger.commons.collection.ArrayHelper#isEmpty()

The following examples show how to use com.helger.commons.collection.ArrayHelper#isEmpty() . 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: TextHelper.java    From ph-commons with Apache License 2.0 6 votes vote down vote up
@Nullable
public static String getFormattedText (@Nullable final String sText, @Nullable final Object... aArgs)
{
  if (sText == null)
  {
    // Avoid NPE in MessageFormat
    return null;
  }

  if (ArrayHelper.isEmpty (aArgs))
  {
    // Return text unchanged
    return sText;
  }

  final MessageFormat aMF = new MessageFormat (sText, Locale.getDefault (Locale.Category.FORMAT));
  return aMF.format (aArgs);
}
 
Example 2
Source File: TextHelper.java    From ph-commons with Apache License 2.0 6 votes vote down vote up
@Nullable
public static String getFormattedText (@Nonnull final Locale aDisplayLocale,
                                       @Nullable final String sText,
                                       @Nullable final Object... aArgs)
{
  ValueEnforcer.notNull (aDisplayLocale, "DisplayLocale");

  if (sText == null)
  {
    // Avoid NPE in MessageFormat
    return null;
  }

  if (ArrayHelper.isEmpty (aArgs))
  {
    // Return text unchanged
    return sText;
  }

  final MessageFormat aMF = new MessageFormat (sText, aDisplayLocale);
  return aMF.format (aArgs);
}
 
Example 3
Source File: CertificateHelper.java    From ph-commons with Apache License 2.0 6 votes vote down vote up
/**
 * Convert the passed String to an X.509 certificate without converting it to
 * a String first.
 *
 * @param aCertBytes
 *        The certificate bytes. May be <code>null</code>.
 * @return <code>null</code> if the passed array is <code>null</code> or empty
 * @throws CertificateException
 *         In case the passed bytes[] cannot be converted to an X.509
 *         certificate.
 * @since 9.3.4
 */
@Nullable
public static X509Certificate convertByteArrayToCertficateDirect (@Nullable final byte [] aCertBytes) throws CertificateException
{
  if (ArrayHelper.isEmpty (aCertBytes))
  {
    // No string -> no certificate
    return null;
  }

  final CertificateFactory aCertificateFactory = getX509CertificateFactory ();
  try (final NonBlockingByteArrayInputStream aBAIS = new NonBlockingByteArrayInputStream (aCertBytes))
  {
    return (X509Certificate) aCertificateFactory.generateCertificate (aBAIS);
  }
}
 
Example 4
Source File: QueueHelper.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
@Nonnull
@ReturnsMutableCopy
public static <SRCTYPE, DSTTYPE> PriorityQueue <DSTTYPE> newQueueMapped (@Nullable final SRCTYPE [] aArray,
                                                                         @Nonnull final Function <? super SRCTYPE, DSTTYPE> aMapper)
{
  if (ArrayHelper.isEmpty (aArray))
    return newQueue (0);
  final PriorityQueue <DSTTYPE> ret = newQueue (aArray.length);
  for (final SRCTYPE aValue : aArray)
    ret.add (aMapper.apply (aValue));
  return ret;
}
 
Example 5
Source File: QueueHelper.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
@Nonnull
@ReturnsMutableCopy
@SafeVarargs
public static <ELEMENTTYPE> PriorityQueue <ELEMENTTYPE> newQueue (@Nullable final ELEMENTTYPE... aValues)
{
  // Don't user Arrays.asQueue since aIter returns an unmodifiable list!
  if (ArrayHelper.isEmpty (aValues))
    return newQueue (0);

  final PriorityQueue <ELEMENTTYPE> ret = newQueue (aValues.length);
  Collections.addAll (ret, aValues);
  return ret;
}
 
Example 6
Source File: VectorHelper.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
@Nonnull
@ReturnsMutableCopy
public static <SRCTYPE, DSTTYPE> CommonsVector <DSTTYPE> newVectorMapped (@Nullable final SRCTYPE [] aArray,
                                                                          @Nonnull final Function <? super SRCTYPE, DSTTYPE> aMapper)
{
  if (ArrayHelper.isEmpty (aArray))
    return newVector (0);
  final CommonsVector <DSTTYPE> ret = newVector (aArray.length);
  ret.addAllMapped (aArray, aMapper);
  return ret;
}
 
Example 7
Source File: VectorHelper.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
@Nonnull
@ReturnsMutableCopy
@SafeVarargs
public static <ELEMENTTYPE> CommonsVector <ELEMENTTYPE> newVector (@Nullable final ELEMENTTYPE... aValues)
{
  // Don't user Arrays.asVector since aIter returns an unmodifiable list!
  if (ArrayHelper.isEmpty (aValues))
    return newVector (0);

  return new CommonsVector <> (aValues);
}
 
Example 8
Source File: ThreadDescriptorList.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
@Nonnull
public static ThreadDescriptorList createWithAllThreads ()
{
  // add dump of all threads
  final StopWatch aSW = StopWatch.createdStarted ();
  final ThreadDescriptorList ret = new ThreadDescriptorList ();
  try
  {
    // Get all stack traces, sorted by thread ID
    for (final Map.Entry <Thread, StackTraceElement []> aEntry : CollectionHelper.getSortedByKey (Thread.getAllStackTraces (),
                                                                                                  Comparator.comparing (Thread::getId))
                                                                                 .entrySet ())
    {
      final StackTraceElement [] aStackTrace = aEntry.getValue ();
      final String sStackTrace = ArrayHelper.isEmpty (aStackTrace) ? "No stack trace available!\n"
                                                                   : StackTraceHelper.getStackAsString (aStackTrace,
                                                                                                        false);
      ret.addDescriptor (new ThreadDescriptor (aEntry.getKey (), sStackTrace));
    }
  }
  catch (final Exception ex)
  {
    LOGGER.error ("Error collecting all thread descriptors", ex);
    ret.setError ("Error collecting all thread descriptors: " + _getAsString (ex));
  }
  finally
  {
    final long nMillis = aSW.stopAndGetMillis ();
    if (nMillis > 1000)
      if (LOGGER.isWarnEnabled ())
        LOGGER.warn ("Took " + nMillis + " ms to get all thread descriptors!");
  }
  return ret;
}
 
Example 9
Source File: IErrorList.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
/**
 * Get a sub-list with all entries for the specified field names
 *
 * @param aSearchFieldNames
 *        The field names to search.
 * @return Never <code>null</code>.
 */
@Nonnull
@ReturnsMutableCopy
default IErrorList getListOfFields (@Nullable final String... aSearchFieldNames)
{
  if (ArrayHelper.isEmpty (aSearchFieldNames))
  {
    // Empty sublist
    return getSubList (x -> false);
  }
  return getSubList (x -> x.hasErrorFieldName () && ArrayHelper.contains (aSearchFieldNames, x.getErrorFieldName ()));
}
 
Example 10
Source File: IErrorList.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
/**
 * Get a sub-list with all entries that have field names starting with one of
 * the supplied names.
 *
 * @param aSearchFieldNames
 *        The field names to search.
 * @return Never <code>null</code>.
 */
@Nonnull
@ReturnsMutableCopy
default IErrorList getListOfFieldsStartingWith (@Nullable final String... aSearchFieldNames)
{
  if (ArrayHelper.isEmpty (aSearchFieldNames))
  {
    // Empty sublist
    return getSubList (x -> false);
  }
  return getSubList (x -> x.hasErrorFieldName () &&
                          ArrayHelper.containsAny (aSearchFieldNames, y -> x.getErrorFieldName ().startsWith (y)));
}
 
Example 11
Source File: GenericReflection.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
/**
 * Get an array with all the classes of the passed object array.
 *
 * @param aObjs
 *        The object array. May be <code>null</code>. No contained element may
 *        be <code>null</code>.
 * @return A non-<code>null</code> array of classes.
 */
@Nonnull
public static Class <?> [] getClassArray (@Nullable final Object... aObjs)
{
  if (ArrayHelper.isEmpty (aObjs))
    return EMPTY_CLASS_ARRAY;

  final Class <?> [] ret = new Class <?> [aObjs.length];
  for (int i = 0; i < aObjs.length; ++i)
    ret[i] = aObjs[i].getClass ();
  return ret;
}
 
Example 12
Source File: StringHelper.java    From ph-commons with Apache License 2.0 3 votes vote down vote up
/**
 * Get a concatenated String from all elements of the passed array, without a
 * separator.
 *
 * @param aElements
 *        The container to convert. May be <code>null</code> or empty.
 * @param aMapper
 *        The mapping function to convert from ELEMENTTYPE to String. May not
 *        be <code>null</code>.
 * @return The concatenated string.
 * @param <ELEMENTTYPE>
 *        The type of elements to be imploded.
 * @since 8.5.6
 */
@Nonnull
public static <ELEMENTTYPE> String getImplodedMapped (@Nullable final ELEMENTTYPE [] aElements,
                                                      @Nonnull final Function <? super ELEMENTTYPE, String> aMapper)
{
  ValueEnforcer.notNull (aMapper, "Mapper");

  if (ArrayHelper.isEmpty (aElements))
    return "";
  return getImplodedMapped (aElements, 0, aElements.length, aMapper);
}
 
Example 13
Source File: StringHelper.java    From ph-commons with Apache License 2.0 3 votes vote down vote up
/**
 * Get a concatenated String from all elements of the passed array, separated
 * by the specified separator string.
 *
 * @param sSep
 *        The separator to use. May not be <code>null</code>.
 * @param aElements
 *        The container to convert. May be <code>null</code> or empty.
 * @param aMapper
 *        The mapping function to convert from ELEMENTTYPE to String. May not
 *        be <code>null</code>.
 * @return The concatenated string.
 * @param <ELEMENTTYPE>
 *        The type of elements to be imploded.
 * @since 8.5.6
 */
@Nonnull
public static <ELEMENTTYPE> String getImplodedMapped (@Nonnull final String sSep,
                                                      @Nullable final ELEMENTTYPE [] aElements,
                                                      @Nonnull final Function <? super ELEMENTTYPE, String> aMapper)
{
  ValueEnforcer.notNull (sSep, "Separator");
  ValueEnforcer.notNull (aMapper, "Mapper");

  if (ArrayHelper.isEmpty (aElements))
    return "";
  return getImplodedMapped (sSep, aElements, 0, aElements.length, aMapper);
}
 
Example 14
Source File: StringHelper.java    From ph-commons with Apache License 2.0 3 votes vote down vote up
/**
 * Get a concatenated String from all elements of the passed array, separated
 * by the specified separator string. This the very generic version of
 * {@link #getConcatenatedOnDemand(String, String, String)} for an arbitrary
 * number of elements.
 *
 * @param sSep
 *        The separator to use. May not be <code>null</code>.
 * @param aElements
 *        The container to convert. May be <code>null</code> or empty.
 * @param aMapper
 *        The mapping function to convert from ELEMENTTYPE to String. May not
 *        be <code>null</code>.
 * @return The concatenated string.
 * @param <ELEMENTTYPE>
 *        Array component type
 * @since 8.5.6
 */
@Nonnull
public static <ELEMENTTYPE> String getImplodedMappedNonEmpty (@Nonnull final String sSep,
                                                              @Nullable final ELEMENTTYPE [] aElements,
                                                              @Nonnull final Function <? super ELEMENTTYPE, String> aMapper)
{
  ValueEnforcer.notNull (sSep, "Separator");
  ValueEnforcer.notNull (aMapper, "Mapper");

  if (ArrayHelper.isEmpty (aElements))
    return "";
  return getImplodedMappedNonEmpty (sSep, aElements, 0, aElements.length, aMapper);
}
 
Example 15
Source File: CertificateHelper.java    From ph-commons with Apache License 2.0 3 votes vote down vote up
/**
 * Convert the passed byte array to an X.509 certificate object.
 *
 * @param aCertBytes
 *        The original certificate bytes. May be <code>null</code> or empty.
 * @return <code>null</code> if the passed byte array is <code>null</code> or
 *         empty
 * @throws CertificateException
 *         In case the passed string cannot be converted to an X.509
 *         certificate.
 */
@Nullable
public static X509Certificate convertByteArrayToCertficate (@Nullable final byte [] aCertBytes) throws CertificateException
{
  if (ArrayHelper.isEmpty (aCertBytes))
    return null;

  // Certificate is always ISO-8859-1 encoded
  return convertStringToCertficate (new String (aCertBytes, CERT_CHARSET));
}