Example usage for java.util LinkedList size

List of usage examples for java.util LinkedList size

Introduction

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

Prototype

int size

To view the source code for java.util LinkedList size.

Click Source Link

Usage

From source file:com.espertech.esper.regression.pattern.TestCronParameter.java

private boolean compareLists(EventBean[] receivedResults, LinkedList<EventDescriptor> expectedResults) {
    int receivedSize = (receivedResults == null) ? 0 : receivedResults.length;
    if (expectedResults.size() != receivedSize) {
        return false;
    }/*from   w  w  w  . jav a2 s .c  om*/

    // To make sure all received events have been expected
    LinkedList<EventDescriptor> expectedResultsClone = new LinkedList<EventDescriptor>(expectedResults);

    // Go through the list of expected results and remove from received result list if found
    for (EventDescriptor desc : expectedResults) {
        EventDescriptor foundMatch = null;

        for (EventBean received : receivedResults) {
            if (compareEvents(desc, received)) {
                foundMatch = desc;
                break;
            }
        }

        // No match between expected and received
        if (foundMatch == null) {
            return false;
        }

        expectedResultsClone.remove(foundMatch);
    }

    // Any left over received results also invalidate the test
    if (expectedResultsClone.size() > 0) {
        return false;
    }
    return true;
}

From source file:android.net.http.Connection.java

/**
 * After a send/receive failure, any pipelined requests must be
 * cleared back to the mRequest queue/*from  w ww .  java2 s  . c  om*/
 * @return true if mRequests is empty after pipe cleared
 */
private boolean clearPipe(LinkedList<Request> pipe) {
    boolean empty = true;
    if (HttpLog.LOGV)
        HttpLog.v("Connection.clearPipe(): clearing pipe " + pipe.size());
    synchronized (mRequestFeeder) {
        Request tReq;
        while (!pipe.isEmpty()) {
            tReq = (Request) pipe.removeLast();
            if (HttpLog.LOGV)
                HttpLog.v("clearPipe() adding back " + mHost + " " + tReq);
            mRequestFeeder.requeueRequest(tReq);
            empty = false;
        }
        if (empty)
            empty = !mRequestFeeder.haveRequest(mHost);
    }
    return empty;
}

From source file:net.erdfelt.android.sdkfido.configer.ConfigCmdLineParser.java

public void parse(String[] args) throws CmdLineParseException {
    LinkedList<String> arglist = new LinkedList<String>();
    arglist.addAll(Arrays.asList(args));

    // Quick Help
    if (arglist.contains("--" + OPT_HELP)) {
        usage();/*from   ww  w .j av  a2s.c o  m*/
        return;
    }

    // Configuration File Option
    int idx = arglist.indexOf("--" + OPT_CONFIG);
    if (idx >= 0) {
        if (idx + 1 > arglist.size()) {
            throw new CmdLineParseException("Expected <File> parameter for option: --" + OPT_CONFIG);
        }
        String value = arglist.get(idx + 1);
        File file = (File) ConvertUtils.convert(value, File.class);

        this.configer.setPersistFile(file);

        arglist.remove(idx + 1);
        arglist.remove(idx);
    }

    // Save Options Option
    boolean saveOptions = false;

    idx = arglist.indexOf("--" + OPT_SAVE);
    if (idx >= 0) {
        saveOptions = true;
        arglist.remove(idx);
    }

    // Restore from persist first.
    try {
        configer.restore();
    } catch (IOException e) {
        throw new CmdLineParseException("Unable to load configuration: " + e.getMessage(), e);
    }

    // Set values from command line now.
    String value;
    ListIterator<String> iter = arglist.listIterator();
    while (iter.hasNext()) {
        String arg = iter.next();
        if (arg.startsWith("--")) {
            // Its an option.
            String optname = arg.substring(2);

            Configurable cfgrbl = configer.getConfigurable(optname);

            if (cfgrbl == null) {
                throw new CmdLineParseException("Invalid Option: " + arg);
            }

            if (!iter.hasNext()) {
                throw new CmdLineParseException(
                        "Expected <" + cfgrbl.getType() + "> parameter for option: " + arg);
            }
            value = iter.next();
            configer.setValue(optname, value);
            continue; // process next arg
        }

        // All others are considered args.
        addToRawArgs(arg);
    }

    // Save options (if specified)
    if (saveOptions) {
        try {
            configer.persist();
        } catch (IOException e) {
            throw new CmdLineParseException("Unable to save configuration: " + e.getMessage(), e);
        }
    }
}

From source file:net.rptools.tokentool.controller.ManageOverlays_Controller.java

private boolean confirmDelete(LinkedList<File> overlayFiles) {
    String confirmationText = I18N.getString("ManageOverlays.dialog.delete.confirmation");

    if (overlayFiles.isEmpty())
        return false;
    else if (overlayFiles.size() == 1) {
        confirmationText += overlayFiles.get(0).getName() + "?";
    } else {/*from  ww w  .  j  ava 2  s .  co m*/
        confirmationText += I18N.getString("ManageOverlays.dialog.delete.confirmation.these")
                + overlayFiles.size() + I18N.getString("ManageOverlays.dialog.delete.confirmation.overlays");
    }

    Alert alert = new Alert(AlertType.CONFIRMATION);
    alert.setTitle(I18N.getString("ManageOverlays.dialog.delete.title"));
    alert.setContentText(confirmationText);

    Optional<ButtonType> result = alert.showAndWait();

    if ((result.isPresent()) && (result.get() == ButtonType.OK)) {
        return true;
    }

    return false;
}

From source file:com.espertech.esper.regression.pattern.TestCronParameter.java

private void runTestEvent() {
    int totalEventsReceived = 0;

    Configuration config = SupportConfigFactory.getConfiguration();
    EPServiceProvider serviceProvider = EPServiceProviderManager.getDefaultProvider(config);
    serviceProvider.initialize();//from   w  w w .j a  va 2s.com

    EPRuntime runtime = serviceProvider.getEPRuntime();
    // Send the start time to the runtime
    TimerEvent startTime = new CurrentTimeEvent(baseTime);
    runtime.sendEvent(startTime);
    log.debug(".runTest Start time is " + startTime);
    try {
        patternStmt = serviceProvider.getEPAdministrator().createPattern(expressionText);
    } catch (Exception ex) {
        log.fatal(".runTest Failed to create statement for pattern expression=" + expressionText, ex);
        TestCase.fail();
    }
    patternStmt.addListener(listener);

    // Send actual test events
    for (Map.Entry<String, Object> entry : testData.entrySet()) {
        String eventId = entry.getKey();

        // Manipulate the time when this event was send
        if (testData.getTime(eventId) != null) {
            TimerEvent currentTimeEvent = new CurrentTimeEvent(testData.getTime(eventId));
            runtime.sendEvent(currentTimeEvent);
            log.debug(".runTest Sending event " + entry.getKey() + " = " + entry.getValue() + "  timed "
                    + currentTimeEvent);
        }

        // Send event itself
        runtime.sendEvent(entry.getValue());

        // Check expected results for this event
        checkResults(eventId);

        // Count and clear the list of events that each listener has received
        totalEventsReceived += countListenerEvents();
    }

    // Count number of expected matches
    int totalExpected = 0;
    for (LinkedList<EventDescriptor> events : testCase.getExpectedResults().values()) {
        totalExpected += events.size();
    }

    if (totalExpected != totalEventsReceived) {
        log.debug(".test Count expected does not match count received, expected=" + totalExpected + " received="
                + totalEventsReceived);
        TestCase.assertTrue(false);
    }

    // Kill expression
    patternStmt.removeAllListeners();

    // Send test events again to also test that all were indeed killed
    for (Map.Entry<String, Object> entry : testData.entrySet()) {
        runtime.sendEvent(entry.getValue());
    }

    if (listener.getNewDataList().size() > 0) {
        log.debug(".test A match was received after stopping all expressions");
        TestCase.assertTrue(false);
    }

    // test the object model
    String epl = "select * from pattern [" + expressionText + "]";
    EPStatementObjectModel model = serviceProvider.getEPAdministrator().compileEPL(epl);
    assertEquals(epl, model.toEPL());
    EPStatement stmt = serviceProvider.getEPAdministrator().create(model);
    assertEquals(epl, stmt.getText());
}

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  w  ww.j ava 2 s.co m*/
 * Also applies a having clause.
 * @param exprProcessor - processes each input event and returns output event
 * @param orderByProcessor - for sorting output events according to the order-by clause
 * @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,
        OrderByProcessor orderByProcessor, EventBean[] events, ExprEvaluator optionalHavingNode,
        boolean isNewData, boolean isSynthesize, ExprEvaluatorContext exprEvaluatorContext) {
    if (events == null) {
        return null;
    }

    LinkedList<EventBean> result = new LinkedList<EventBean>();
    List<EventBean[]> eventGenerators = null;
    if (orderByProcessor != null) {
        eventGenerators = new ArrayList<EventBean[]>();
    }

    EventBean[] eventsPerStream = new EventBean[1];
    for (EventBean theEvent : events) {
        eventsPerStream[0] = theEvent;

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

        result.add(exprProcessor.process(eventsPerStream, isNewData, isSynthesize, exprEvaluatorContext));
        if (orderByProcessor != null) {
            eventGenerators.add(new EventBean[] { theEvent });
        }
    }

    if (!result.isEmpty()) {
        if (orderByProcessor != null) {
            return orderByProcessor.sort(result.toArray(new EventBean[result.size()]),
                    eventGenerators.toArray(new EventBean[eventGenerators.size()][]), isNewData,
                    exprEvaluatorContext);
        } else {
            return result.toArray(new EventBean[result.size()]);
        }
    } else {
        return null;
    }
}

From source file:name.marcelomorales.siqisiqi.openjpa.impl.OrmFinderImpl.java

protected Predicate newFullTextPredicate(CriteriaBuilder cb, Root<T> p, String terms) {
    LinkedList<Predicate> predicatesOr = Lists.newLinkedList();
    Iterable<Path<String>> fullTexts = settings.getFullTexts(p, persistentClass);
    if (fullTexts != null) {
        for (Path<String> x : fullTexts) {
            StringTokenizer tokenizer = new StringTokenizer(terms, " \t\n\r\f,.;:/");
            LinkedList<Predicate> predicatesAnd = Lists.newLinkedList();
            while (tokenizer.hasMoreTokens()) {
                String token = "%" + tokenizer.nextToken() + "%";

                predicatesAnd.add(cb.like(cb.lower(x), StringUtils.lowerCase(token)));
            }// w w  w  . j  av a2  s  .c  om
            predicatesOr.add(cb.and(predicatesAnd.toArray(new Predicate[predicatesAnd.size()])));
        }
    }
    final Predicate[] restrictions = predicatesOr.toArray(new Predicate[predicatesOr.size()]);
    return cb.or(restrictions);
}

From source file:com.swordlord.gozer.databinding.DataBindingManager.java

public DataRowBase getResolvedRow(LinkedList<DataBindingElement> elements, String strTableName,
        DataRowBase rowFather) {//  ww w.  j ava 2s .co  m
    if ((elements == null) || (elements.size() == 0)) {
        LOG.error("elements is empty");
    }

    int i = 0;
    boolean propertyFound = true;
    for (DataBindingElement element : elements) {
        i++;
        if (!element.isField() && i < elements.size()) {
            String strPathElement = element.getPathElement();

            // ignore the same level
            if (strPathElement.compareToIgnoreCase(strTableName) != 0) {
                Object property = rowFather.getProperty(strPathElement);

                if (property == null) {
                    // continuous with next
                    propertyFound = false;
                } else {
                    propertyFound = true;
                    if (property instanceof DataRowBase) {
                        rowFather = (DataRowBase) property;
                    } else if (property instanceof ToManyList) {
                        ToManyList list = (ToManyList) property;
                        if (list.size() > 0) {
                            rowFather = (DataRowBase) list.get(element.getRowNumber());
                        }
                    }
                }
                // this is some nice side effect where we just loop as long
                // as we
                // are not at the right level
            }
        }
    }

    if (propertyFound)
        return rowFather;
    else
        return null;

}

From source file:com.swordlord.gozer.databinding.DataBindingManager.java

private void updatePath(DataBindingMember dbm) {
    LinkedList<DataBindingElement> elements = dbm.getDataBindingElements();
    if ((elements == null) || (elements.size() == 0)) {
        throw new NullArgumentException("dataBindingMember");
    }/*ww  w .j  a v  a  2 s .c o  m*/

    ObjEntity oeLastTable = null;
    ObjEntity oeCurrentTable = null;

    String strConcatPath = "";

    EntityResolver er = _dc.getObjectContext().getEntityResolver();

    for (DataBindingElement element : elements) {
        String strPathElement = element.getPathElement();

        // Find table from binding info
        if (strPathElement.startsWith("rel_")) {
            ObjRelationship rel = (ObjRelationship) oeLastTable.getRelationship(strPathElement);

            if (rel == null) {
                LOG.error("Relation is not known: " + strPathElement);
                throw new NullArgumentException(strPathElement);
            }

            oeCurrentTable = (ObjEntity) rel.getTargetEntity();
        } else {
            oeCurrentTable = er.getObjEntity(strPathElement);
        }

        // add the whole path instead of current element only to make sure
        // that binding over the same table multiple times does not confuse
        // the binding
        String strFather = strConcatPath;
        strConcatPath += strConcatPath.length() > 0 ? "." + strPathElement : strPathElement;
        if (!_dataViews.containsKey(strConcatPath) && !element.isField()) {
            String strTableName = oeCurrentTable.getClassName();

            strTableName = strTableName.replaceAll("DataRow", "DataTable");
            strTableName = strTableName.replaceAll("datarow", "datatable");

            DataTableBase dtb = _dc.getTableByAbsoluteName(strTableName);
            if (dtb == null) {
                LOG.info("Table can not be found: " + strTableName);
            }

            DataViewBase dvFather = null;

            if (strFather.length() > 0) {
                dvFather = _dataViews.get(strFather);
            }

            DataViewBase dvb = new DataViewBase(strConcatPath, strPathElement, dvFather, dtb);
            dvb.setPosition(element.getRowNumber());

            if (element.hasFilter()) {
                dvb.setFilter(ViewFilterBuilder.createSimple(element.getFilter()));
            }

            // Store the dataviewbase under the name of the path element so
            // that no
            // further lookup is needed to find dataview from path element
            // during binding
            _dataViews.put(strConcatPath, dvb);
        }

        // set last table so that next path element can load correct
        // objentity.
        oeLastTable = oeCurrentTable;
    }
}

From source file:com.amazonaws.services.logs.connectors.kinesis.KinesisTransformer.java

@Override
public Collection<Record> fromClasses(Collection<CloudWatchLogsEvent> events) throws IOException {
    LinkedList<Record> records = new LinkedList<Record>();

    LinkedList<CloudWatchLogsEvent> buffer = new LinkedList<CloudWatchLogsEvent>();
    String key = null;/*from   w  w w  . j  a va  2s  .  com*/
    Iterator<CloudWatchLogsEvent> iter = events.iterator();
    while (iter.hasNext()) {
        CloudWatchLogsEvent event = iter.next();
        String nextKey = getPartitionKey(event);
        if (key != null && !key.equals(nextKey)) {
            records.addAll(createRecords(buffer));
            buffer.clear();
        }
        buffer.add(event);
    }
    if (buffer.size() > 0)
        records.addAll(createRecords(buffer));
    return records;
}