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:fr.cls.atoll.motu.library.converter.jaxb.LocaleAdapter.java

/**
 * Tokenize the given String into a String array via a StringTokenizer.
 * <p>/*from   ww w. ja  va 2s.c  o m*/
 * The given delimiters string is supposed to consist of any number of delimiter characters. Each of those
 * characters can be used to separate tokens. A delimiter is always a single character; for
 * multi-character delimiters, consider using <code>delimitedListToStringArray</code>
 * 
 * @param str the String to tokenize
 * @param delimiters the delimiter characters, assembled as String (each of those characters is
 *            individually considered as delimiter)
 * @param trimTokens trim the tokens via String's <code>trim</code>
 * @param ignoreEmptyTokens omit empty tokens from the result array (only applies to tokens that are empty
 *            after trimming; StringTokenizer will not consider subsequent delimiters as token in the
 *            first place).
 * @return an array of the tokens (<code>null</code> if the input String was <code>null</code>)
 * @see java.util.StringTokenizer
 * @see java.lang.String#trim()
 * @see #delimitedListToStringArray
 */
private static String[] tokenizeToStringArray(String str, String delimiters, boolean trimTokens,
        boolean ignoreEmptyTokens) {

    if (str == null) {
        return null;
    }
    StringTokenizer st = new StringTokenizer(str, delimiters);
    List tokens = new ArrayList();
    while (st.hasMoreTokens()) {
        String token = st.nextToken();
        if (trimTokens) {
            token = token.trim();
        }
        if (!ignoreEmptyTokens || token.length() > 0) {
            tokens.add(token);
        }
    }
    return (String[]) tokens.toArray(new String[tokens.size()]);
}

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

public static Specification<Article> draft(Article article) {
    return (root, query, cb) -> {
        List<Predicate> predicates = new ArrayList<>();
        predicates.add(cb.equal(root.get(Article_.drafted), article));

        Subquery<Long> subquery = query.subquery(Long.class);
        Root<Article> p = subquery.from(Article.class);
        subquery.select(cb.max(p.get(Article_.id))).where(cb.equal(p.get(Article_.drafted), article));

        predicates.add(cb.equal(root.get(Article_.id), subquery));
        return cb.and(predicates.toArray(new Predicate[0]));
    };//from w w w. jav  a2 s.c o m
}

From source file:lucee.commons.i18n.FormatUtil.java

private static void add24(List<DateFormat> list, Locale locale) {

    // if found h:mm:ss a add H:mm:ss ...
    String p;//from   w  w  w .  j a  va2  s. c om
    int index;
    SimpleDateFormat sdf;
    DateFormat[] df = list.toArray(new DateFormat[list.size()]);
    for (int i = 0; i < df.length; i++) {
        if (df[i] instanceof SimpleDateFormat) {
            p = ((SimpleDateFormat) df[i]).toPattern() + "";

            if (check(list, p, locale, "hh:mm:ss a", "HH:mm:ss"))
                continue;
            if (check(list, p, locale, "h:mm:ss a", "H:mm:ss"))
                continue;
            if (check(list, p, locale, "hh:mm a", "HH:mm"))
                continue;
            if (check(list, p, locale, "h:mm a", "H:mm"))
                continue;

            if (check(list, p, locale, "hh:mm:ssa", "HH:mm:ss"))
                continue;
            if (check(list, p, locale, "h:mm:ssa", "H:mm:ss"))
                continue;
            if (check(list, p, locale, "hh:mma", "HH:mm"))
                continue;
            if (check(list, p, locale, "h:mma", "H:mm"))
                continue;

            //if(check(list,p,locale,"HH:mm:ss","hh:mm:ss a")) continue;
            //if(check(list,p,locale,"H:mm:ss","h:mm:ss a")) continue;
            //if(check(list,p,locale,"HH:mm","hh:mm a")) continue;
            //if(check(list,p,locale,"H:mm","h:mm a")) continue;
        }
    }
}

From source file:com.sun.star.lib.loader.FileFind.java

/**
 * Looks for files recursively in a directory tree
 * @param inFolder//from  w ww. ja va2s. c o  m
 * @param findTheseFiles
 * @return
 */
public static URL[] findFiles(String inFolder, String[] findTheseFiles) {
    List<URL> urls = new ArrayList<URL>(0);
    Collection<File> files = FileUtils.listFiles(new File(inFolder), new NameFileFilter(findTheseFiles),
            TrueFileFilter.INSTANCE);
    for (File file : files) {
        try {
            urls.add(file.toURI().toURL());
        } catch (MalformedURLException ex) {
            log.error("error while locating jar", ex);
        }
    }
    return urls.toArray(new URL[urls.size()]);
}

From source file:com.thalesgroup.sonar.plugins.tusar.utils.Utils.java

/**
 * Function that returns the extensions available in file open into the given Scanner
 * @param scanner//from ww  w . j a  v a2s . c  o  m
 * @return An array of strings containing the file extensions
 */
public static String[] getExtensions(Scanner scanner) {
    List<String> extensions = new ArrayList<String>();
    while (scanner.hasNextLine()) {
        String line = scanner.nextLine().trim();
        if (line.startsWith(".")) {
            line = line.substring(1, line.length());
        }
        if (!line.isEmpty()) {
            extensions.add(line);
        }
    }
    return extensions.toArray(new String[extensions.size()]);
}

From source file:ai.grakn.engine.controller.TasksController.java

static private <T> CompletableFuture<List<T>> all(List<CompletableFuture<T>> cf) {
    return CompletableFuture.allOf(cf.toArray(new CompletableFuture[cf.size()]))
            .thenApply(v -> cf.stream().map(CompletableFuture::join).collect(toList()));
}

From source file:com.darkstar.beanCartography.utils.NameUtils.java

/**
 * Return public, private, protected, etc. fields declared by the passed
 * class in a field array./* w  w w .  j a  va  2 s.  co m*/
 *
 * @param clazz class to inspect
 * @param includeSuperClasses <code>true</code> will cause superclasses to be included in the field collection
 * @return array of Fields found
 */
public static Field[] getClassFields(Class<?> clazz, boolean includeSuperClasses) {
    Preconditions.checkNotNull(clazz, "Class cannot be null!");
    List<Field> allFields = new ArrayList<>();
    do {
        allFields.addAll(Arrays.asList(clazz.getDeclaredFields()));
    } while (includeSuperClasses && (clazz = clazz.getSuperclass()) != null);

    Field[] fields = new Field[allFields.size()];
    return allFields.toArray(fields);
}

From source file:edu.utah.further.core.api.collections.ArrayUtil.java

/**
 * @param list/*from  www. j  a va2  s. c  o m*/
 * @return
 */
public static byte[] byteListToPrimitiveArray(final List<Byte> list) {
    return ArrayUtils.toPrimitive(list.toArray(ArrayUtils.EMPTY_BYTE_OBJECT_ARRAY));
}

From source file:com.netflix.spinnaker.clouddriver.aws.security.AmazonClientInvocationHandler.java

static Class[] getClassArgs(Object[] args) {
    List<Class> classes = new ArrayList<>();
    for (Object object : args) {
        classes.add(object.getClass());/*w  w  w .ja  v a  2 s .  com*/
    }
    return classes.toArray(new Class[classes.size()]);
}

From source file:com.norconex.jefmon.model.ConfigurationDAO.java

private static IJobAction[] loadJobActions(XMLConfiguration xml)
        throws InstantiationException, IllegalAccessException, ClassNotFoundException {
    List<HierarchicalConfiguration> nodes = xml.configurationsAt("job-actions.action");
    List<IJobAction> actions = new ArrayList<IJobAction>();
    for (HierarchicalConfiguration node : nodes) {
        String actionClass = node.getString("");
        IJobAction action = (IJobAction) Class.forName(actionClass).newInstance();
        actions.add(action);/*w  w  w  .  ja  v a2  s  .  c o m*/
    }
    return actions.toArray(new IJobAction[] {});
}