Example usage for java.util List toArray

List of usage examples for java.util List toArray

Introduction

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

Prototype

<T> T[] toArray(T[] a);

Source Link

Document

Returns an array containing all of the elements in this list in proper sequence (from first to last element); the runtime type of the returned array is that of the specified array.

Usage

From source file:Main.java

/**
 * Join the {@code strings} into one string with {@code delimiter} in 
 * between./*  www.  j  a  v  a2  s .  com*/
 * 
 * @param strings the string list to join
 * @param delimiter the delimiter
 * 
 * @return the joined string
 */
public static String join(List<String> strings, String delimiter) {
    if (strings == null) {
        throw new NullPointerException("argument 'strings' cannot be null");
    }
    return join(strings.toArray(new String[strings.size()]), delimiter);
}

From source file:es.emergya.consultas.IncidenciaConsultas.java

public static Object[] getStatuses(boolean hasBlankSpace) {
    List<Object> res = new LinkedList<Object>();
    if (hasBlankSpace)
        res.add("");
    res.addAll(incidenciaHome.getStatuses());
    return res.toArray(new Object[0]);
}

From source file:es.emergya.consultas.IncidenciaConsultas.java

public static Object[] getCategorias(boolean hasBlankSpace) {
    List<Object> res = new LinkedList<Object>();
    if (hasBlankSpace)
        res.add("");
    res.addAll(incidenciaHome.getCategorias());
    return res.toArray(new Object[0]);
}

From source file:jease.cms.service.Contents.java

/**
 * Returns all available content containers.
 *//*from   w w w . j a v  a2s  .  c om*/
public static Content[] getContainer() {
    List<Content> query = Database.query(Content.class, Content::isContainer);
    return query.toArray(new Content[query.size()]);
}

From source file:edu.utah.further.core.ws.WsUtil.java

/**
 *
 * Takes a list of path segments and returns an array of paths. Useful for gathering
 * multiple parameters in the form of /parameterlist/param1/param2/param3/param4 where
 * the array would contain param1-param4.
 *
 * @param parameters/* w ww  .j ava2s . co  m*/
 * @return
 */
public static String[] pathSegmentToPathArray(final List<? extends PathSegment> parameters) {
    final List<String> pathParams = newList();
    for (final PathSegment segment : parameters) {
        pathParams.add(segment.getPath());
    }
    return pathParams.toArray(new String[pathParams.size()]);
}

From source file:Main.java

public static Integer[] findAllIndexes(String str, String searchStr) {
    List<Integer> list = new ArrayList<Integer>();

    int index = str.indexOf(searchStr);
    while (index >= 0) {
        list.add(index);//from ww w .  j a  v  a2 s. c om
        index = str.indexOf(searchStr, index + searchStr.length());
    }
    return list.toArray(new Integer[list.size()]);
}

From source file:org.wallride.repository.CategorySpecifications.java

public static Specification<Category> hasArticle(String language) {
    return (root, query, cb) -> {
        query.distinct(true);/*  w  ww  .ja  v a  2s.co  m*/

        Subquery<Long> subquery = query.subquery(Long.class);
        Root<Article> a = subquery.from(Article.class);
        Join<Article, Category> c = a.join(Article_.categories, JoinType.INNER);
        subquery.select(c.get(Category_.id)).where(cb.equal(a.get(Article_.status), Article.Status.PUBLISHED));

        List<Predicate> predicates = new ArrayList<>();
        predicates.add(root.get(Category_.id).in(subquery));
        predicates.add(cb.equal(root.get(Category_.language), language));
        return cb.and(predicates.toArray(new Predicate[0]));
    };
}

From source file:com.adobe.acs.commons.mcp.util.ValueMapSerializer.java

public static String[] serializeToStringArray(Object value) {
    if (value == null) {
        return new String[0];
    } else if (value instanceof String[]) {
        return (String[]) value;
    } else if (value.getClass().isArray()) {
        List<String> values = (List) Arrays.asList((Object[]) value).stream().map(String::valueOf)
                .collect(Collectors.toList());
        return (String[]) values.toArray(new String[0]);
    } else if (value instanceof Collection) {
        List<String> values = (List) ((Collection) value).stream().map(String::valueOf)
                .collect(Collectors.toList());
        return (String[]) values.toArray(new String[0]);
    } else {//from   ww w . j av a2  s . c o m
        return new String[] { value.toString() };
    }
}

From source file:de.unentscheidbar.validation.internal.Methods.java

public static MethodChain findMethod(Class<?> clazz, String methodName, List<Class<?>> parameterTypes,
        String... propertyHierarchy) {

    Class<?>[] paramTypesAsArray = parameterTypes.toArray(new Class<?>[parameterTypes.size()]);
    Method m = MethodUtils.getMatchingAccessibleMethod(clazz, methodName, paramTypesAsArray);

    Builder<Method> builder = ImmutableList.builder();
    for (int i = 0; clazz != null && m == null && i < propertyHierarchy.length; i++) {
        Method propertyAccessor = MethodUtils.getMatchingAccessibleMethod(clazz, propertyHierarchy[i]);
        if (propertyAccessor != null) {
            builder.add(propertyAccessor);
            clazz = propertyAccessor.getReturnType();
            m = MethodUtils.getMatchingAccessibleMethod(clazz, methodName, paramTypesAsArray);
        }/*w  w  w .jav a  2 s. com*/
    }
    if (m == null) {
        /* No such method found */
        return null;
    } else {
        /*
         * The list builder now contains all properties that lead to an accessible method m
         * which has the desired signature
         */
        builder.add(m);
        return new MethodChain(builder.build());
    }
}

From source file:ml.shifu.guagua.yarn.GuaguaSplitWriter.java

@SuppressWarnings("unchecked")
public static <T extends InputSplit> void createSplitFiles(Path jobSubmitDir, Configuration conf, FileSystem fs,
        List<InputSplit> splits) throws IOException, InterruptedException {
    T[] array = (T[]) splits.toArray(new InputSplit[splits.size()]);
    createSplitFiles(jobSubmitDir, conf, fs, array);
}