Example usage for java.util LinkedList toArray

List of usage examples for java.util LinkedList toArray

Introduction

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

Prototype

@SuppressWarnings("unchecked")
public <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:orc.lib.orchard.forms.MultipartFormData.java

@Override
public FileItem[] getItems(final String key) {
    final LinkedList<FileItem> out = new LinkedList<FileItem>();
    for (final FileItem item : items) {
        if (item.getFieldName().equals(key)) {
            out.add(item);/*from   w  w  w . j a  va  2s  . c  o m*/
        }
    }
    return out.toArray(new FileItem[0]);
}

From source file:com.espertech.esper.epl.core.ResultSetProcessorSimple.java

/**
 * Applies the select-clause to the given events returning the selected events. The number of events stays the
 * same, i.e. this method does not filter it just transforms the result set.
 * <p>/*from   ww w . j a  va 2  s. c  o  m*/
 * Also applies a having clause.
 * @param exprProcessor - processes each input event and returns output event
 * @param events - input events
 * @param optionalHavingNode - supplies the having-clause expression
 * @param isNewData - indicates whether we are dealing with new data (istream) or old data (rstream)
 * @param isSynthesize - set to true to indicate that synthetic events are required for an iterator result set
 * @param exprEvaluatorContext context for expression evalauation
 * @return output events, one for each input event
 */
protected static EventBean[] getSelectEventsHaving(SelectExprProcessor exprProcessor,
        Set<MultiKey<EventBean>> events, ExprEvaluator optionalHavingNode, boolean isNewData,
        boolean isSynthesize, ExprEvaluatorContext exprEvaluatorContext) {
    LinkedList<EventBean> result = new LinkedList<EventBean>();

    for (MultiKey<EventBean> key : events) {
        EventBean[] eventsPerStream = key.getArray();

        Boolean passesHaving = (Boolean) optionalHavingNode.evaluate(eventsPerStream, isNewData,
                exprEvaluatorContext);
        if ((passesHaving == null) || (!passesHaving)) {
            continue;
        }

        EventBean resultEvent = exprProcessor.process(eventsPerStream, isNewData, isSynthesize,
                exprEvaluatorContext);
        result.add(resultEvent);
    }

    if (!result.isEmpty()) {
        return result.toArray(new EventBean[result.size()]);
    } else {
        return null;
    }
}

From source file:org.psidnell.omnifocus.cli.FixedParser.java

@Override
protected String[] flatten(Options options, String[] arguments, boolean stopAtNonOption) {

    LinkedList<String> result = new LinkedList<>();
    for (String arg : arguments) {
        if (!arg.startsWith("-")) {
            result.add('"' + arg + '"');
        } else {//from   ww  w . ja  v a2 s . c  om
            result.add(arg);
        }
    }

    return result.toArray(new String[result.size()]);
}

From source file:org.kuali.kra.test.infrastructure.ApplicationServer.java

/**
 * The jetty server's jsp compiler does not have access to the classpath artifacts to compile the jsps.
 * This method takes the current webapp classloader and creates one containing all of the
 * classpath artifacts on the test's classpath.
 *
 * See http://stackoverflow.com/questions/17685330/how-do-you-get-embedded-jetty-9-to-successfully-resolve-the-jstl-uri
 *
 * @param current the current webapp classpath
 * @return a classloader to replace it with
 * @throws IOException if an error occurs creating the classloader
 *///from   w ww  . j  a va2 s  .  co  m
private static ClassLoader createClassLoaderForJasper(ClassLoader current) throws IOException {
    // Replace classloader with a new classloader with all URLs in manifests
    // from the parent loader bubbled up so Jasper looks at them.
    final ClassLoader parentLoader = current.getParent();
    if (current instanceof WebAppClassLoader && parentLoader instanceof URLClassLoader) {
        final LinkedList<URL> allURLs = new LinkedList<URL>(
                Arrays.asList(((URLClassLoader) parentLoader).getURLs()));

        for (URL url : ((LinkedList<URL>) allURLs.clone())) {
            try {
                final URLConnection conn = new URL("jar:" + url.toString() + "!/").openConnection();
                if (conn instanceof JarURLConnection) {
                    final JarURLConnection jconn = (JarURLConnection) conn;
                    final Manifest jarManifest = jconn.getManifest();
                    final String[] classPath = ((String) jarManifest.getMainAttributes().getValue("Class-Path"))
                            .split(" ");

                    for (String cpurl : classPath) {
                        allURLs.add(new URL(url, cpurl));
                    }
                }
            } catch (IOException | NullPointerException e) {
                //do nothing
            }
        }
        LOG.info("Creating new classloader for Application Server");
        return new WebAppClassLoader(new URLClassLoader(allURLs.toArray(new URL[] {}), parentLoader),
                ((WebAppClassLoader) current).getContext());
    }
    LOG.warn("Cannot create new classloader for app server " + current);
    return current;
}

From source file:SearchStyleText.java

public SearchStyleText() {
    shell.setLayout(new GridLayout(2, false));

    styledText = new StyledText(shell, SWT.MULTI | SWT.WRAP | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
    GridData gridData = new GridData(GridData.FILL_BOTH);
    gridData.horizontalSpan = 2;/*from   w  ww  .  j a  v  a2 s. c om*/
    styledText.setLayoutData(gridData);

    keywordText = new Text(shell, SWT.SINGLE | SWT.BORDER);
    keywordText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    Font font = new Font(shell.getDisplay(), "Courier New", 12, SWT.NORMAL);
    styledText.setFont(font);

    button = new Button(shell, SWT.PUSH);
    button.setText("Search");
    button.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            keyword = keywordText.getText();
            styledText.redraw();
        }
    });

    styledText.addLineStyleListener(new LineStyleListener() {
        public void lineGetStyle(LineStyleEvent event) {
            if (keyword == null || keyword.length() == 0) {
                event.styles = new StyleRange[0];
                return;
            }

            String line = event.lineText;
            int cursor = -1;

            LinkedList list = new LinkedList();
            while ((cursor = line.indexOf(keyword, cursor + 1)) >= 0) {
                list.add(getHighlightStyle(event.lineOffset + cursor, keyword.length()));
            }

            event.styles = (StyleRange[]) list.toArray(new StyleRange[list.size()]);
        }
    });

    keyword = "SW";

    styledText.setText("AWT, SWING \r\nSWT & JFACE");

    shell.pack();
    shell.open();
    //textUser.forceFocus();

    // Set up the event loop.
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            // If no more entries in event queue
            display.sleep();
        }
    }

    display.dispose();
}

From source file:edu.umd.cfar.lamp.viper.gui.chronology.ViperChronicleSelectionModel.java

public TemporalRange getSelectedTime() {
    if (nodeWhoseTimeToSelect instanceof TemporalNode) {
        return ((TemporalNode) nodeWhoseTimeToSelect).getRange();
    } else if (nodeWhoseTimeToSelect instanceof Config) {
        Sourcefile sf = mediator.getCurrFile();
        if (sf != null) {
            Iterator iter = sf.getDescriptorsBy((Config) nodeWhoseTimeToSelect);
            if (iter.hasNext()) {
                LinkedList ll = new LinkedList();
                while (iter.hasNext()) {
                    ll.add(((Descriptor) iter.next()).getRange());
                }/*w  w w .  ja v a 2  s  .  c o m*/
                TemporalRange[] R = new TemporalRange[ll.size()];
                ll.toArray(R);
                return new MultipleRange(R);
            }
        }
    }
    return null;
}

From source file:com.oneops.util.SearchSenderTest.java

@Test
public void testQueueFailure() {
    BrokerService searchBroker = context.getBean("searchBroker", BrokerService.class);
    try {/*from w  w w  .  j  a  va2s .c  om*/
        searchBroker.stop();
    } catch (Exception e) {
        Assert.fail();
    }
    try {
        searchBroker.waitUntilStopped();
        if (searchBroker.isStopped()) {

            MessageData[] dataList = getMessages();

            for (MessageData data : dataList) {
                searchPublisher.publish(data);
            }

            Thread.sleep(2000);
            consumer.startRecording();
            searchBroker.start(true);
            searchBroker.waitUntilStarted(5000);
            if (searchBroker.isStarted()) {
                await().atMost(10, TimeUnit.SECONDS).until(() -> (consumer.getCounter() == 3));
                LinkedList<MessageData> list = consumer.getMessages();
                assertMessages(dataList, list.toArray(new MessageData[] {}));
            }
            consumer.reset();
            // send messages again
            for (MessageData data : dataList) {
                searchPublisher.publish(data);
            }
            await().atMost(10, TimeUnit.SECONDS).until(() -> (consumer.getCounter() == 3));
            LinkedList<MessageData> list = consumer.getMessages();
            assertMessages(dataList, list.toArray(new MessageData[] {}));
        }
    } catch (Exception e) {
        Assert.fail(e.getMessage());
    }
}

From source file:com.erudika.para.rest.RestUtils.java

/**
 * Batch create response as JSON/*from  w w  w  .ja v a  2  s. co  m*/
 * @param app the current App object
 * @param is entity input stream
 * @return a status code 200 or 400
 */
public static Response getBatchCreateResponse(final App app, InputStream is) {
    final LinkedList<ParaObject> objects = new LinkedList<ParaObject>();
    Response entityRes = getEntity(is, List.class);
    if (entityRes.getStatusInfo() == Response.Status.OK) {
        List<Map<String, Object>> items = (List<Map<String, Object>>) entityRes.getEntity();
        for (Map<String, Object> object : items) {
            ParaObject pobj = ParaObjectUtils.setAnnotatedFields(object);
            if (pobj != null && ValidationUtils.isValidObject(pobj)) {
                pobj.setAppid(app.getAppIdentifier());
                objects.add(pobj);
            }
        }

        Para.getDAO().createAll(app.getAppIdentifier(), objects);

        Para.asyncExecute(new Runnable() {
            public void run() {
                int typesCount = app.getDatatypes().size();
                app.addDatatypes(objects.toArray(new ParaObject[objects.size()]));
                if (typesCount < app.getDatatypes().size()) {
                    app.update();
                }
            }
        });
    } else {
        return entityRes;
    }
    return Response.ok(objects).build();
}

From source file:cc.kune.core.server.rack.filters.gwts.DelegatedRemoteServlet.java

@SuppressWarnings({ "unused", "rawtypes" })
@Override/*ww w  .jav a  2 s .com*/
protected Method getMethod(final GwtRpcCommLayerPojoRequest stressTestRequest)
        throws NoSuchMethodException, ClassNotFoundException {
    final int count = 0;
    final Class<?> paramClasses[] = new Class[stressTestRequest.getMethodParameters().size()];

    final LinkedList<Class<?>> lstParameterClasses = new LinkedList<Class<?>>();
    for (final String methodName : stressTestRequest.getParameterClassNames()) {
        lstParameterClasses.add(Class.forName(methodName));
    }

    final Class[] arrParameterClasses = lstParameterClasses.toArray(new Class[0]);
    // patched here for kune
    return service.getClass().getMethod(stressTestRequest.getMethodName(), arrParameterClasses);
}

From source file:org.quartz.jobs.ee.jmx.JMXInvokerJob.java

private String[] split(String str, String splitStr) // Same as String.split(.) in JDK 1.4
{
    LinkedList l = new LinkedList();

    StringTokenizer strTok = new StringTokenizer(str, splitStr);
    while (strTok.hasMoreTokens()) {
        String tok = strTok.nextToken();
        l.add(tok);/*from  w w  w  .  j  a v  a2s  .  co  m*/
    }

    return (String[]) l.toArray(new String[l.size()]);
}