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:com.hengyi.japp.execution.Util.java

public static void queryCommand(CriteriaBuilder cb, CriteriaQuery<?> cq, Root<Experience> root,
        ExperienceQueryCommand command) {
    List<Predicate> ps = Lists.newArrayListWithCapacity(2);
    if (command.getCustomers() != null) {
        ps.add(root.get(Experience_.customer).in(command.getCustomers()));
    }// www .  j av  a2 s  .  co m
    if (!isBlank(command.getName())) {
        ps.add(cb.like(root.get(Experience_.name), command.getNameQuery()));
    }
    cq.where(ps.toArray(new Predicate[ps.size()]));
}

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

/**
 * @param list// w  ww . j  a  v  a2s.  c o  m
 * @return
 */
public static int[] intListToPrimitiveArray(final List<Integer> list) {
    return ArrayUtils.toPrimitive(list.toArray(ArrayUtils.EMPTY_INTEGER_OBJECT_ARRAY));
}

From source file:com.google.api.ads.dfp.lib.utils.v201208.PqlUtils.java

/**
 * Gets the row values for a row of the result set in a the form of a string
 * array. {@code null} values are interperted as empty strings.
 *
 * @param row the row to get the values for
 * @return the string array of the row values
 * @throws IllegalAccessException//from  w  w w  .j a v a2  s .  com
 * @throws IllegalArgumentException
 * @throws IllegalArgumentException if the value could not be extracted from
 *     the row value
 * @throws IllegalAccessException if the row value could not be accessed
 */
public static String[] getRowStringValues(Row row) throws IllegalArgumentException, IllegalAccessException {
    Object[] rowValues = getRowValues(row);
    List<String> rowStringValues = new ArrayList<String>();
    for (Object obj : rowValues) {
        if (obj != null) {
            rowStringValues.add(obj.toString());
        } else {
            rowStringValues.add("");
        }
    }
    return rowStringValues.toArray(new String[] {});
}

From source file:com.microsoft.tfs.client.common.ui.framework.dialog.DialogSettingsHelper.java

public static StoredDialogStatistics[] getStatistics() {
    final IDialogSettings settings = TFSCommonUIClientPlugin.getDefault().getDialogSettings();
    final IDialogSettings[] sections = settings.getSections();
    final List statistics = new ArrayList();
    if (sections != null) {
        for (int i = 0; i < sections.length; i++) {
            statistics.add(createStatistics(sections[i]));
        }/*from   w  ww .j  a  v  a  2 s. c  o  m*/
    }
    return (StoredDialogStatistics[]) statistics.toArray(new StoredDialogStatistics[] {});
}

From source file:de.tor.tribes.util.TribeUtils.java

public static Tribe[] getTribeByVillage(Village[] pVillages, boolean pUseBarbarians,
        Comparator<Tribe> pComparator) {
    List<Tribe> tribes = new LinkedList<>();

    for (Village v : pVillages) {
        Tribe t = v.getTribe();/*from w  w  w.  ja  v  a  2 s .  c  o m*/
        if (pUseBarbarians || !t.equals(Barbarians.getSingleton())) {
            if (!tribes.contains(t)) {
                tribes.add(t);
            }
        }
    }

    if (pComparator != null) {
        Collections.sort(tribes, pComparator);
    }

    return tribes.toArray(new Tribe[tribes.size()]);
}

From source file:com.norconex.commons.lang.io.IOUtil.java

/**
 * Gets the first lines from an input stream, using the specified encoding.  
 * This method is null-safe.// ww  w.  j  a v a2  s.com
 * If the input stream is null or empty, an empty string array will
 * be returned.
 * @param is input stream
 * @param encoding character encoding
 * @param lineQty maximum number of lines to return
 * @return lines as a string array
 * @throws IOException problem reading lines
 */
public static String[] head(final InputStream is, String encoding, final int lineQty) throws IOException {
    if (is == null) {
        return EMPTY_STRINGS;
    }
    String safeEncoding = encoding;
    if (StringUtils.isBlank(safeEncoding)) {
        safeEncoding = CharEncoding.UTF_8;
    }
    BufferedReader br = new BufferedReader(new InputStreamReader(is, safeEncoding));
    List<String> lines = new ArrayList<String>(lineQty);
    String line;
    while ((line = br.readLine()) != null) {
        lines.add(line);
        if (lines.size() == lineQty) {
            break;
        }
    }
    br.close();
    return lines.toArray(EMPTY_STRINGS);
}

From source file:hudson.scm.util.ParamUtils.java

/**
 * Populates text with parameter values.
 *
 * @param text input text to process//from w  ww  . j  av a2  s . c  o m
 * @param parameters map with parameters.
 * @return populated text.
 */
public static String populateParamValues(String text, Map<String, String> parameters) {
    if (MapUtils.isEmpty(parameters) || StringUtils.isEmpty(text)) {
        return text;
    }
    List<String> searchList = new ArrayList<String>(parameters.keySet().size());
    List<String> replacementList = new ArrayList<String>(parameters.keySet().size());
    for (String key : parameters.keySet()) {
        searchList.add(String.format(PARAM_FORMAT, key));
        replacementList.add(parameters.get(key));
    }
    return org.apache.commons.lang.StringUtils.replaceEach(text,
            searchList.toArray(new String[searchList.size()]),
            replacementList.toArray(new String[replacementList.size()]));
}

From source file:net.sf.companymanager.qbe.JpaUtil.java

public static Predicate orPredicate(final CriteriaBuilder builder,
        final Iterable<Predicate> predicatesNullAllowed) {
    List<Predicate> predicates = withoutNullEntries(predicatesNullAllowed);
    if (predicates.isEmpty()) {
        return null;
    } else if (predicates.size() == 1) {
        return predicates.get(0);
    } else {//from   w w  w .j a  v  a  2 s  .  c om
        return builder.or(predicates.toArray(new Predicate[predicates.size()]));
    }
}

From source file:net.sf.companymanager.qbe.JpaUtil.java

public static Predicate andPredicate(final CriteriaBuilder builder,
        final Iterable<Predicate> predicatesNullAllowed) {
    List<Predicate> predicates = withoutNullEntries(predicatesNullAllowed);
    if (predicates.isEmpty()) {
        return null;
    } else if (predicates.size() == 1) {
        return predicates.get(0);
    } else {//ww  w . j  a v  a2s .c o m
        return builder.and(predicates.toArray(new Predicate[predicates.size()]));
    }
}