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

The following examples show how to use com.helger.commons.collection.CollectionHelper#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: URLHelper.java    From ph-commons with Apache License 2.0 6 votes vote down vote up
/**
 * Create a parameter string. This is also suitable for POST body (e.g. for
 * web form submission).
 *
 * @param aQueryParams
 *        Parameter map. May be <code>null</code> or empty.
 * @param aQueryParameterEncoder
 *        The encoder to be used to encode parameter names and parameter
 *        values. May be <code>null</code>. This may be e.g. a
 *        {@link URLParameterEncoder}.
 * @return <code>null</code> if no parameter is present.
 */
@Nullable
public static String getQueryParametersAsString (@Nullable final List <? extends URLParameter> aQueryParams,
                                                 @Nullable final IEncoder <String, String> aQueryParameterEncoder)
{
  if (CollectionHelper.isEmpty (aQueryParams))
    return null;

  final StringBuilder aSB = new StringBuilder ();
  // add all values
  for (final URLParameter aParam : aQueryParams)
  {
    // Separator
    if (aSB.length () > 0)
      aSB.append (AMPERSAND);
    aParam.appendTo (aSB, aQueryParameterEncoder);
  }

  return aSB.toString ();
}
 
Example 2
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 Collection <? extends SRCTYPE> aCollection,
                                                                         @Nonnull final Function <? super SRCTYPE, DSTTYPE> aMapper)
{
  if (CollectionHelper.isEmpty (aCollection))
    return newQueue (0);
  final PriorityQueue <DSTTYPE> ret = newQueue (aCollection.size ());
  for (final SRCTYPE aValue : aCollection)
    ret.add (aMapper.apply (aValue));
  return ret;
}
 
Example 3
Source File: QueueHelper.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
@Nonnull
@ReturnsMutableCopy
public static <ELEMENTTYPE> PriorityQueue <ELEMENTTYPE> newQueue (@Nullable final Collection <? extends ELEMENTTYPE> aCont)
{
  if (CollectionHelper.isEmpty (aCont))
    return newQueue (0);
  return new PriorityQueue <> (aCont);
}
 
Example 4
Source File: QueueHelper.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
@Nonnull
@ReturnsMutableCopy
public static <ELEMENTTYPE> PriorityQueue <ELEMENTTYPE> newQueue (@Nullable final Collection <? extends ELEMENTTYPE> aCollection,
                                                                  @Nonnull final Predicate <? super ELEMENTTYPE> aFilter)
{
  if (CollectionHelper.isEmpty (aCollection))
    return newQueue (0);
  final PriorityQueue <ELEMENTTYPE> ret = newQueue (aCollection.size ());
  CollectionHelper.findAll (aCollection, aFilter, ret::add);
  return ret;
}
 
Example 5
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 Collection <? extends SRCTYPE> aCollection,
                                                                          @Nonnull final Function <? super SRCTYPE, DSTTYPE> aMapper)
{
  if (CollectionHelper.isEmpty (aCollection))
    return newVector (0);
  final CommonsVector <DSTTYPE> ret = newVector (aCollection.size ());
  ret.addAllMapped (aCollection, aMapper);
  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 <ELEMENTTYPE> CommonsVector <ELEMENTTYPE> newVector (@Nullable final Collection <? extends ELEMENTTYPE> aCollection,
                                                                   @Nonnull final Predicate <? super ELEMENTTYPE> aFilter)
{
  if (CollectionHelper.isEmpty (aCollection))
    return newVector (0);
  final CommonsVector <ELEMENTTYPE> ret = newVector (aCollection.size ());
  ret.addAll (aCollection, aFilter);
  return ret;
}
 
Example 7
Source File: VectorHelper.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
@Nonnull
@ReturnsMutableCopy
public static <ELEMENTTYPE> CommonsVector <ELEMENTTYPE> newVector (@Nullable final Collection <? extends ELEMENTTYPE> aCont)
{
  if (CollectionHelper.isEmpty (aCont))
    return newVector (0);

  return new CommonsVector <> (aCont);
}
 
Example 8
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 Collection <String> aSearchFieldNames)
{
  if (CollectionHelper.isEmpty (aSearchFieldNames))
  {
    // Empty sublist
    return getSubList (x -> false);
  }
  return getSubList (x -> x.hasErrorFieldName () && aSearchFieldNames.contains (x.getErrorFieldName ()));
}