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

The following examples show how to use com.helger.commons.collection.ArrayHelper#getSize() . 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: CommonsMock.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
/**
 * This method is responsible for invoking the provided
 * factory/supplier/function with the provided parameters.
 *
 * @param aProvidedParams
 *        The parameter array. May be <code>null</code> or empty.
 * @return The mocked value. May be <code>null</code> but that would be a
 *         relatively rare case.
 */
@Nullable
public Object getMockedValue (@Nullable final Object [] aProvidedParams)
{
  IGetterDirectTrait [] aEffectiveParams = null;
  if (m_aParams != null && m_aParams.length > 0)
  {
    // Parameters are present - convert all to IConvertibleTrait
    final int nRequiredParams = m_aParams.length;
    final int nProvidedParams = ArrayHelper.getSize (aProvidedParams);

    aEffectiveParams = new IGetterDirectTrait [nRequiredParams];
    for (int i = 0; i < nRequiredParams; ++i)
    {
      if (i < nProvidedParams && aProvidedParams[i] != null)
      {
        // Param provided and not null -> use provided
        final Object aVal = aProvidedParams[i];
        aEffectiveParams[i] = () -> aVal;
      }
      else
      {
        // Not provided or null -> use default
        aEffectiveParams[i] = m_aParams[i].getDefaultValue ();
      }
    }
  }
  return m_aFct.apply (aEffectiveParams);
}
 
Example 2
Source File: CommonsVector.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
@Nonnull
@ReturnsMutableCopy
public static <ELEMENTTYPE> CommonsVector <ELEMENTTYPE> createFiltered (@Nullable final ELEMENTTYPE [] aValues,
                                                                        @Nullable final Predicate <? super ELEMENTTYPE> aFilter)
{
  final CommonsVector <ELEMENTTYPE> ret = new CommonsVector <> (ArrayHelper.getSize (aValues));
  ret.addAll (aValues, aFilter);
  return ret;
}
 
Example 3
Source File: CommonsVector.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
@Nonnull
@ReturnsMutableCopy
public static <SRCTYPE, ELEMENTTYPE> CommonsVector <ELEMENTTYPE> createFiltered (@Nullable final SRCTYPE [] aValues,
                                                                                 @Nullable final Predicate <? super SRCTYPE> aFilter,
                                                                                 @Nonnull final Function <? super SRCTYPE, ? extends ELEMENTTYPE> aMapper)
{
  final CommonsVector <ELEMENTTYPE> ret = new CommonsVector <> (ArrayHelper.getSize (aValues));
  ret.addAllMapped (aValues, aFilter, aMapper);
  return ret;
}
 
Example 4
Source File: CommonsHashSet.java    From ph-commons with Apache License 2.0 4 votes vote down vote up
@SafeVarargs
public CommonsHashSet (@Nullable final ELEMENTTYPE... aValues)
{
  super (ArrayHelper.getSize (aValues));
  addAll (aValues);
}
 
Example 5
Source File: CommonsHashSet.java    From ph-commons with Apache License 2.0 4 votes vote down vote up
public <SRCTYPE> CommonsHashSet (@Nullable final SRCTYPE [] aValues,
                                 @Nonnull final Function <? super SRCTYPE, ? extends ELEMENTTYPE> aMapper)
{
  super (ArrayHelper.getSize (aValues));
  addAllMapped (aValues, aMapper);
}
 
Example 6
Source File: CommonsVector.java    From ph-commons with Apache License 2.0 4 votes vote down vote up
@SafeVarargs
public CommonsVector (@Nullable final ELEMENTTYPE... aValues)
{
  super (ArrayHelper.getSize (aValues));
  addAll (aValues);
}
 
Example 7
Source File: CommonsVector.java    From ph-commons with Apache License 2.0 4 votes vote down vote up
public <SRCTYPE> CommonsVector (@Nullable final SRCTYPE [] aValues,
                                @Nonnull final Function <? super SRCTYPE, ? extends ELEMENTTYPE> aMapper)
{
  super (ArrayHelper.getSize (aValues));
  addAllMapped (aValues, aMapper);
}
 
Example 8
Source File: CommonsLinkedHashSet.java    From ph-commons with Apache License 2.0 4 votes vote down vote up
@SafeVarargs
public CommonsLinkedHashSet (@Nullable final ELEMENTTYPE... aValues)
{
  super (ArrayHelper.getSize (aValues));
  addAll (aValues);
}
 
Example 9
Source File: CommonsLinkedHashSet.java    From ph-commons with Apache License 2.0 4 votes vote down vote up
public <SRCTYPE> CommonsLinkedHashSet (@Nullable final SRCTYPE [] aValues,
                                       @Nonnull final Function <? super SRCTYPE, ? extends ELEMENTTYPE> aMapper)
{
  super (ArrayHelper.getSize (aValues));
  addAllMapped (aValues, aMapper);
}
 
Example 10
Source File: CommonsArrayList.java    From ph-commons with Apache License 2.0 3 votes vote down vote up
/**
 * Create a new array list that contains the same elements as the provided
 * array.
 *
 * @param aValues
 *        The array to copy the initial capacity and the elements from. May be
 *        <code>null</code>.
 * @see #addAll(Object...)
 */
@SafeVarargs
public CommonsArrayList (@Nullable final ELEMENTTYPE... aValues)
{
  super (ArrayHelper.getSize (aValues));
  addAll (aValues);
}
 
Example 11
Source File: CommonsArrayList.java    From ph-commons with Apache License 2.0 3 votes vote down vote up
/**
 * Create a new array list that contains mapped elements of the provided
 * array.
 *
 * @param aValues
 *        The array to copy the initial capacity and the elements from. May be
 *        <code>null</code>.
 * @param aMapper
 *        The mapping function to be executed for all provided elements. May
 *        not be <code>null</code>.
 * @see #addAllMapped(Object[], Function)
 * @param <SRCTYPE>
 *        source data type
 */
public <SRCTYPE> CommonsArrayList (@Nullable final SRCTYPE [] aValues,
                                   @Nonnull final Function <? super SRCTYPE, ? extends ELEMENTTYPE> aMapper)
{
  super (ArrayHelper.getSize (aValues));
  addAllMapped (aValues, aMapper);
}
 
Example 12
Source File: CommonsArrayList.java    From ph-commons with Apache License 2.0 3 votes vote down vote up
/**
 * Create a new array list that contains a subset of the provided array.<br>
 * Note: this method is a static factory method because the compiler sometimes
 * cannot deduce between {@link Predicate} and {@link Function} and the
 * mapping case occurs more often.
 *
 * @param aValues
 *        The array from which the elements are copied from. May be
 *        <code>null</code>.
 * @param aFilter
 *        The filter to be applied to check if the element should be added or
 *        not.
 * @return The created array list. Never <code>null</code>.
 * @see #addAll(Object[], Predicate)
 * @param <ELEMENTTYPE>
 *        data type of the list
 */
@Nonnull
@ReturnsMutableCopy
public static <ELEMENTTYPE> CommonsArrayList <ELEMENTTYPE> createFiltered (@Nullable final ELEMENTTYPE [] aValues,
                                                                           @Nullable final Predicate <? super ELEMENTTYPE> aFilter)
{
  final CommonsArrayList <ELEMENTTYPE> ret = new CommonsArrayList <> (ArrayHelper.getSize (aValues));
  ret.addAll (aValues, aFilter);
  return ret;
}
 
Example 13
Source File: CommonsArrayList.java    From ph-commons with Apache License 2.0 3 votes vote down vote up
/**
 * Create a new array list that contains a subset of the provided array. This
 * method filters the elements before they are mapped.<br>
 * Note: this method is a static factory method because the compiler sometimes
 * cannot deduce between {@link Predicate} and {@link Function} and the
 * mapping case occurs more often.
 *
 * @param aValues
 *        The array from which the elements are copied from. May be
 *        <code>null</code>.
 * @param aFilter
 *        The filter to be applied to check if the element should be added or
 *        not.
 * @param aMapper
 *        The mapping function to be executed for all provided elements. May
 *        not be <code>null</code>.
 * @return The created array list. Never <code>null</code>.
 * @see #addAllMapped(Object[], Predicate, Function)
 * @param <SRCTYPE>
 *        source data type
 * @param <ELEMENTTYPE>
 *        final data type of the list
 */
@Nonnull
@ReturnsMutableCopy
public static <SRCTYPE, ELEMENTTYPE> CommonsArrayList <ELEMENTTYPE> createFiltered (@Nullable final SRCTYPE [] aValues,
                                                                                    @Nullable final Predicate <? super SRCTYPE> aFilter,
                                                                                    @Nonnull final Function <? super SRCTYPE, ? extends ELEMENTTYPE> aMapper)
{
  final CommonsArrayList <ELEMENTTYPE> ret = new CommonsArrayList <> (ArrayHelper.getSize (aValues));
  ret.addAllMapped (aValues, aFilter, aMapper);
  return ret;
}
 
Example 14
Source File: CommonsArrayList.java    From ph-commons with Apache License 2.0 3 votes vote down vote up
/**
 * Create a new array list that contains a subset of the provided array. This
 * method maps the elements before they are filtered.<br>
 * Note: this method is a static factory method because the compiler sometimes
 * cannot deduce between {@link Predicate} and {@link Function} and the
 * mapping case occurs more often.
 *
 * @param aValues
 *        The array from which the elements are copied from. May be
 *        <code>null</code>.
 * @param aMapper
 *        The mapping function to be executed for all provided elements. May
 *        not be <code>null</code>.
 * @param aFilter
 *        The filter to be applied on the mapped element to check if the
 *        element should be added or not.
 * @return The created array list. Never <code>null</code>.
 * @see #addAllMapped(Iterable, Function, Predicate)
 * @since 9.1.3
 * @param <SRCTYPE>
 *        source data type
 * @param <ELEMENTTYPE>
 *        final data type of the list
 */
@Nonnull
@ReturnsMutableCopy
public static <SRCTYPE, ELEMENTTYPE> CommonsArrayList <ELEMENTTYPE> createFiltered (@Nullable final SRCTYPE [] aValues,
                                                                                    @Nonnull final Function <? super SRCTYPE, ? extends ELEMENTTYPE> aMapper,
                                                                                    @Nullable final Predicate <? super ELEMENTTYPE> aFilter)
{
  final CommonsArrayList <ELEMENTTYPE> ret = new CommonsArrayList <> (ArrayHelper.getSize (aValues));
  ret.addAllMapped (aValues, aMapper, aFilter);
  return ret;
}