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.igormaznitsa.nbmindmap.nb.refactoring.RefactoringUtils.java

public static FileObject[] getMMDs(final Lookup lookup) {
    final Collection<? extends Node> nodes = lookup.lookupAll(Node.class);
    final List<FileObject> result = new ArrayList<FileObject>();
    for (final Node n : nodes) {
        final FileObject fo = n.getLookup().lookup(FileObject.class);
        if (fo != null) {
            if (isMMD(fo)) {
                result.add(fo);//ww  w  .j a  v a2s  . c  o m
            }
        }
    }
    return result.toArray(new FileObject[result.size()]);
}

From source file:net.padlocksoftware.padlock.keymaker.Main.java

private static String[] formatOutput(String publicKey) {
    List<String> list = new ArrayList<String>();

    // Break the public key String into 60 character strings
    int LENGTH = 60;
    int start = -LENGTH;
    int end = 0;//from   w w w .  j  a  v  a2s  .  co  m

    while (end < publicKey.length()) {
        end = Math.min(end + LENGTH, publicKey.length());
        start += LENGTH;
        list.add(publicKey.substring(start, end));
    }

    return list.toArray(new String[0]);
}

From source file:org.eclipse.virgo.ide.facet.core.FacetUtils.java

/**
 * Returns all bundle project in the current workspace regardless weather they are open or closed.
 *//*from  ww w.  java2s.  co  m*/
public static IProject[] getBundleProjects() {
    List<IProject> bundles = new ArrayList<IProject>();
    IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
    for (IProject candidate : projects) {
        if (FacetUtils.isBundleProject(candidate)) {
            bundles.add(candidate);
        }
    }
    return bundles.toArray(new IProject[bundles.size()]);
}

From source file:org.openmrs.module.sync.scheduler.CleanupSyncTablesTask.java

/**
 * Get the given property name from the given props and convert it to an array of
 * {@link SyncRecordState}s/*  w w  w .  j  a  v  a  2 s.c  om*/
 * 
 * @param propertyName the prop key to look for
 * @param props the key-value map to look in
 * @param defaultStates the default array if the value is invalid
 * @return an array of {@link SyncRecordState}s
 */
protected static SyncRecordState[] getSyncRecordStateProperty(String propertyName, Map<String, String> props,
        SyncRecordState[] defaultStates) {
    if (props != null) {
        String prop = props.get(propertyName);
        if (StringUtils.hasLength(prop)) {
            try {
                List<SyncRecordState> states = new ArrayList<SyncRecordState>();
                for (String stateName : prop.split(",")) {
                    SyncRecordState state = SyncRecordState.valueOf(stateName.trim());
                    states.add(state);
                }
                return states.toArray(new SyncRecordState[] {});
            } catch (Exception e) {
                log.error("Unable to convert property value for " + propertyName + " : '" + prop
                        + "' to an array of states");
            }
        }
    }

    return defaultStates;
}

From source file:org.pentaho.pat.server.servlet.ExportController.java

public static byte[] exportExcel(String queryId) throws IOException {
    exportResult = OlapUtil.cellSet2Matrix(OlapUtil.getCellSet(queryId));
    if (exportResult != null) {
        PatTableModel table = new PatTableModel(exportResult);
        AbstractBaseCell[][] rowData = table.getRowData();
        AbstractBaseCell[][] rowHeader = table.getColumnHeaders();

        String[][] result = new String[rowHeader.length + rowData.length][];
        for (int x = 0; x < rowHeader.length; x++) {
            List<String> cols = new ArrayList<String>();
            for (int y = 0; y < rowHeader[x].length; y++) {
                cols.add(rowHeader[x][y].getFormattedValue());
            }//  w w w  .  j a  v a  2s.co  m
            result[x] = cols.toArray(new String[cols.size()]);

        }
        for (int x = 0; x < rowData.length; x++) {
            int xTarget = rowHeader.length + x;
            List<String> cols = new ArrayList<String>();
            for (int y = 0; y < rowData[x].length; y++) {
                cols.add(rowData[x][y].getFormattedValue());
            }
            result[xTarget] = cols.toArray(new String[cols.size()]);

        }
        return export(result);
    }
    return new byte[0];
}

From source file:com.netflix.genie.server.repository.jpa.ClusterSpecs.java

/**
 * Generate a specification given the parameters.
 *
 * @param name          The name of the cluster to find
 * @param statuses      The statuses of the clusters to find
 * @param tags          The tags of the clusters to find
 * @param minUpdateTime The minimum updated time of the clusters to find
 * @param maxUpdateTime The maximum updated time of the clusters to find
 * @return The specification/*from   ww w .  ja va2  s.  co  m*/
 */
public static Specification<Cluster> find(final String name, final Set<ClusterStatus> statuses,
        final Set<String> tags, final Long minUpdateTime, final Long maxUpdateTime) {
    return new Specification<Cluster>() {
        @Override
        public Predicate toPredicate(final Root<Cluster> root, final CriteriaQuery<?> cq,
                final CriteriaBuilder cb) {
            final List<Predicate> predicates = new ArrayList<>();
            if (StringUtils.isNotBlank(name)) {
                predicates.add(cb.like(root.get(Cluster_.name), name));
            }
            if (minUpdateTime != null) {
                predicates.add(cb.greaterThanOrEqualTo(root.get(Cluster_.updated), new Date(minUpdateTime)));
            }
            if (maxUpdateTime != null) {
                predicates.add(cb.lessThan(root.get(Cluster_.updated), new Date(maxUpdateTime)));
            }
            if (tags != null) {
                for (final String tag : tags) {
                    if (StringUtils.isNotBlank(tag)) {
                        predicates.add(cb.isMember(tag, root.get(Cluster_.tags)));
                    }
                }
            }
            if (statuses != null && !statuses.isEmpty()) {
                //Could optimize this as we know size could use native array
                final List<Predicate> orPredicates = new ArrayList<>();
                for (final ClusterStatus status : statuses) {
                    orPredicates.add(cb.equal(root.get(Cluster_.status), status));
                }
                predicates.add(cb.or(orPredicates.toArray(new Predicate[orPredicates.size()])));
            }

            return cb.and(predicates.toArray(new Predicate[predicates.size()]));
        }
    };
}

From source file:com.adobe.acs.commons.util.CookieUtil.java

/**
 * Remove the named Cookies from Response
 *
 * @param request     Request to get the Cookies to drop
 * @param response    Response to expire the Cookies on
 * @param cookieNames Names of cookies to drop
 * @return Number of Cookies dropped//from   ww w  .  j  a  v  a2  s .  c o  m
 */
public static int dropCookies(final HttpServletRequest request, final HttpServletResponse response,
        final String cookiePath, final String... cookieNames) {
    int count = 0;
    if (cookieNames == null) {
        return count;
    }

    final List<Cookie> cookies = new ArrayList<Cookie>();
    for (final String cookieName : cookieNames) {
        cookies.add(getCookie(request, cookieName));
    }

    return dropCookies(response, cookies.toArray(new Cookie[cookies.size()]), cookiePath);
}

From source file:org.uimafit.spring.SpringContextResourceManager.java

/**
 * Instantiate a non-visible class.//  ww w . java2s  . c om
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
private static <T> T newInstance(String aClassName, Object... aArgs) throws ResourceInitializationException {
    Constructor constr = null;
    try {
        Class<?> cl = Class.forName(aClassName);

        List<Class> types = new ArrayList<Class>();
        List<Object> values = new ArrayList<Object>();
        for (int i = 0; i < aArgs.length; i += 2) {
            types.add((Class) aArgs[i]);
            values.add(aArgs[i + 1]);
        }

        constr = cl.getDeclaredConstructor(types.toArray(new Class[types.size()]));
        constr.setAccessible(true);
        return (T) constr.newInstance(values.toArray(new Object[values.size()]));
    } catch (Exception e) {
        throw new ResourceInitializationException(e);
    } finally {
        if (constr != null) {
            constr.setAccessible(false);
        }
    }
}

From source file:edu.harvard.iq.dataverse.util.SumStatCalculator.java

/**
 * Returns a new double array of nulls and non-Double.NaN values only
 *
 *//*from   w  ww .  j ava2s.c  o m*/
// TODO: 
// implement this in some way that does not require allocating a new 
// ArrayList for the values of every vector. -- L.A. Aug. 11 2014
private static double[] removeInvalidValues(Double[] x) {
    List<Double> dl = new ArrayList<Double>();
    for (Double d : x) {
        if (d != null && !Double.isNaN(d)) {
            dl.add(d);
        }
    }
    return ArrayUtils.toPrimitive(dl.toArray(new Double[dl.size()]));
}

From source file:$pkg.$.java

private static CSLName[] toAuthors(String[] authors) {
     List<CSLName> result = new ArrayList<CSLName>();
     for (String a : authors) {
         CSLName[] names = NameParser.parse(a);
         for (CSLName n : names) {
             result.add(n);//from w w w .j  a  v a2 s . com
         }
     }
     return result.toArray(new CSLName[result.size()]);
 }