Example usage for java.util Collection toArray

List of usage examples for java.util Collection toArray

Introduction

In this page you can find the example usage for java.util Collection toArray.

Prototype

default <T> T[] toArray(IntFunction<T[]> generator) 

Source Link

Document

Returns an array containing all of the elements in this collection, using the provided generator function to allocate the returned array.

Usage

From source file:com.opendoorlogistics.core.utils.strings.Strings.java

public static String toString(String separator, Collection<String> strs) {
    return toString(separator, strs.toArray(new String[strs.size()]));
}

From source file:br.msf.commons.mocca.ajax.AbstractAjaxService.java

/**
 * Efetua o parse de um parametro para um array de entidades.
 * <p/>//  ww w  . j a  v  a 2 s .c  o m
 * <span style="font-weight: bold; color: #006600;">O RETORNO DESTE MTODO  NULL SAFE.</span>
 *
 * @param <E>         Tipo de entidade do array.
 * @param targetClass Classe do tipo de entidade do retorno.
 * @param key         Chave para o valor do parametro.
 * @param params      Conjunto de parametros.
 * @param service     O service a ser usado na consulta.
 * @param joins       Joins a serem efetuados na consulta.
 * @return O parametro desejado em formato de array.
 */
protected static <E extends Entity<Long>> E[] getNullsafeArray(final Class<E> targetClass, final String key,
        final Map<String, String> params, final EntityService<Long, E> service, final String... joins) {
    final Collection<E> col = getNullsafeCollection(targetClass, key, params, service, joins);
    final E[] array = (E[]) Array.newInstance(targetClass, col.size());
    return col.toArray(array);
}

From source file:br.msf.commons.mocca.ajax.AbstractAjaxService.java

/**
 * Efetua o parse de um parametro para um array.
 * <p/>//from w  w  w . ja v a  2 s  .com
 * <span style="font-weight: bold; color: #006600;">O RETORNO DESTE MTODO  NULL SAFE.</span>
 * <p/>
 * Para saber quais <code>targetClass</code> este mtodo suporta,
 * vide {@link #parseValue(java.lang.Class, java.lang.String, java.lang.CharSequence, java.util.Locale, boolean) parseValue()}.
 *
 * @param <S>         Tipo de item do array.
 * @param targetClass Classe do tipo de Item do array.
 * @param key         Chave para o valor do parametro.
 * @param params      Conjunto de parametros.
 * @param pattern     O pattern de converso (se targetClass == Number, Date ou Calendar)
 * @param locale      O locale de converso (se targetClass == Number, Date ou Calendar)
 * @return O parametro desejado em formato de array.
 * @see #parseValue(java.lang.Class, java.lang.String, java.lang.CharSequence, java.util.Locale, boolean)parseValue()
 */
protected static <S extends Serializable> S[] getNullsafeArray(final Class<S> targetClass, final String key,
        final Map<String, String> params, final CharSequence pattern, final Locale locale) {
    final Collection<S> col = getNullsafeCollection(targetClass, key, params, pattern, locale);
    final S[] array = (S[]) Array.newInstance(targetClass, col.size());
    return col.toArray(array);
}

From source file:com.basho.riak.client.raw.http.ConversionUtil.java

/**
 * Converts a Collection from legacy http {@link RiakObject} to
 * {@link IRiakObject}//from   w w w  .j  a v a2s . c  o  m
 * 
 * @param siblings
 *            the siblings from the http client
 * @return an array of {@link IRiakObject}, one for each member of
 *         <code>siblings</code>
 */
static IRiakObject[] convert(Collection<com.basho.riak.client.http.RiakObject> siblings) {
    final Collection<IRiakObject> results = new ArrayList<IRiakObject>();

    for (com.basho.riak.client.http.RiakObject object : siblings) {
        results.add(convert(object));
    }

    return results.toArray(new IRiakObject[results.size()]);
}

From source file:com.easyjf.util.StringUtils.java

/**
 * Copy the given Collection into a String array. The Collection must
 * contain String elements only./*w ww . j av  a2 s  .  c o m*/
 * 
 * @param collection
 *            the Collection to copy
 * @return the String array (<code>null</code> if the Collection was
 *         <code>null</code> as well)
 */
public static String[] toStringArray(Collection collection) {
    if (collection == null)
        return null;
    return (String[]) collection.toArray(new String[collection.size()]);
}

From source file:org.codehaus.griffon.commons.GriffonClassUtils.java

/**
 * Convenience method for converting a collection to an Object[]
 * @param c The collection//from  w ww  .ja  va  2 s. co m
 * @return  An object array
 */
public static Object[] collectionToObjectArray(Collection c) {
    if (c == null)
        return new Object[0];

    return c.toArray(new Object[c.size()]);
}

From source file:br.msf.commons.mocca.ajax.AbstractAjaxService.java

/**
 * Efetua o parse de um parametro para um array.
 * <p/>//  ww w.j  av  a2s . c  o  m
 * <span style="font-weight: bold; color: #660000;">O RETORNO DESTE MTODO NO  NULL SAFE.</span>
 * <p/>
 * Para saber quais <code>targetClass</code> este mtodo suporta,
 * vide {@link #parseValue(java.lang.Class, java.lang.String, java.lang.CharSequence, java.util.Locale, boolean) parseValue()}.
 *
 * @param <S>         Tipo de item do array.
 * @param targetClass Classe do tipo de Item do array.
 * @param key         Chave para o valor do parametro.
 * @param params      Conjunto de parametros.
 * @param pattern     O pattern de converso (se targetClass == Number, Date ou Calendar)
 * @param locale      O locale de converso (se targetClass == Number, Date ou Calendar)
 * @return O parametro desejado em formato de array.
 * @see #parseValue(java.lang.Class, java.lang.String, java.lang.CharSequence, java.util.Locale, boolean)parseValue()
 */
protected static <S extends Serializable> S[] getArray(final Class<S> targetClass, final String key,
        final Map<String, String> params, final CharSequence pattern, final Locale locale) {
    final Collection<S> col = getCollection(targetClass, key, params, pattern, locale);
    if (col == null) {
        return null;
    }
    final S[] array = (S[]) Array.newInstance(targetClass, col.size());
    return col.toArray(array);
}

From source file:com.smartitengineering.cms.ws.resources.content.searcher.ContentSearcherResource.java

public static ContentTypeId[] parseCollectionContentTypeId(List<String> strCollectionContentTypeId) {
    Collection<ContentTypeId> contentTypeIds = new ArrayList<ContentTypeId>();
    for (String strContentTypeId : strCollectionContentTypeId) {
        if (StringUtils.isBlank(strContentTypeId)) {
            continue;
        }//from  w  w w. j a va  2 s.c  o  m
        final ContentTypeId id = parseContentTypeId(strContentTypeId);
        if (id != null) {
            contentTypeIds.add(id);
        }
    }
    ContentTypeId[] retContentTypeIds = contentTypeIds.toArray(new ContentTypeId[contentTypeIds.size()]);
    return retContentTypeIds;
}

From source file:com.aliyun.odps.utils.StringUtils.java

/**
 * Returns an arraylist of strings.// w ww .j  a v a 2s.  c  o m
 *
 * @param str
 *     the comma seperated string values
 * @return the arraylist of the comma seperated string values
 */
public static String[] getStrings(String str) {
    Collection<String> values = getStringCollection(str);
    if (values.size() == 0) {
        return null;
    }
    return values.toArray(new String[values.size()]);
}

From source file:com.krawler.common.util.BaseStringUtil.java

public static <E> String join(String delimiter, Collection<E> col) {
    if (col == null) {
        return null;
    }/*from w  ww. j  a  v  a 2s.  c o m*/
    Object[] array = new Object[col.size()];
    col.toArray(array);
    return join(delimiter, array);
}