Example usage for java.util LinkedList getLast

List of usage examples for java.util LinkedList getLast

Introduction

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

Prototype

public E getLast() 

Source Link

Document

Returns the last element in this list.

Usage

From source file:mulavito.algorithms.shortestpath.disjoint.SuurballeTarjan.java

private List<E> recombinePaths(List<E> path, V target, List<E> union) {
    LinkedList<E> p = new LinkedList<E>(); // provides getLast
    p.add(path.get(0));/* www .  j a v  a 2  s . c om*/
    union.remove(path.get(0));

    V curDest;
    while (!(curDest = graph.getDest(p.getLast())).equals(target)) {
        boolean progress = false;
        for (E e : union)
            if (graph.isSource(curDest, e)) {
                p.add(e);
                progress = true;
                union.remove(e);
                break;
            }

        if (!progress)
            return null;

        if (union.isEmpty()) {
            if (!graph.isDest(target, p.getLast())) {
                throw new AssertionError("bug");
            } else
                break;
        }
    }
    return p;
}

From source file:com.github.lindenb.jvarkit.tools.misc.BamTile.java

@Override
public Collection<Throwable> call(final String inputName) throws Exception {
    SAMRecordIterator iter = null;/*  ww w  .  ja va2  s .  c  om*/
    SamReader sfr = null;
    SAMFileWriter sfw = null;
    try {
        sfr = openSamReader(inputName);

        SAMFileHeader header1 = sfr.getFileHeader();
        if (header1 == null) {
            return wrapException("File header missing");
        }

        if (header1.getSortOrder() != SAMFileHeader.SortOrder.coordinate) {
            return wrapException("File header not sorted on coordinate");
        }

        SAMFileHeader header2 = header1.clone();
        header2.addComment(getName() + ":" + getVersion() + ":" + getProgramCommandLine());

        sfw = openSAMFileWriter(header2, true);

        SAMSequenceDictionaryProgress progress = new SAMSequenceDictionaryProgress(header1);
        iter = sfr.iterator();
        LinkedList<SAMRecord> buffer = new LinkedList<>();
        for (;;) {
            SAMRecord rec = null;
            if (iter.hasNext()) {
                rec = progress.watch(iter.next());
                if (rec.getReadUnmappedFlag())
                    continue;
                if (!buffer.isEmpty()) {
                    SAMRecord last = buffer.getLast();
                    if (last.getReferenceIndex() == rec.getReferenceIndex()
                            && last.getAlignmentStart() <= rec.getAlignmentStart()
                            && last.getAlignmentEnd() >= rec.getAlignmentEnd()) {
                        continue;
                    }
                }
            }
            if (rec == null
                    || (!buffer.isEmpty() && buffer.getLast().getReferenceIndex() != rec.getReferenceIndex())) {
                while (!buffer.isEmpty()) {
                    sfw.addAlignment(buffer.removeFirst());
                }
                if (rec == null)
                    break;
            }
            buffer.add(rec);

            if (buffer.size() > 2) {
                int index = buffer.size();
                SAMRecord prev = buffer.get(index - 3);
                SAMRecord curr = buffer.get(index - 2);
                SAMRecord next = buffer.get(index - 1);

                if (prev.getAlignmentEnd() >= next.getAlignmentStart()
                        || curr.getAlignmentEnd() <= prev.getAlignmentEnd()) {
                    buffer.remove(index - 2);
                } else if (curr.getAlignmentStart() == prev.getAlignmentStart()
                        && curr.getAlignmentEnd() > prev.getAlignmentEnd()) {
                    buffer.remove(index - 3);
                }

            }
            while (buffer.size() > 3) {
                sfw.addAlignment(buffer.removeFirst());
            }

        }
        progress.finish();
        LOG.info("done");
        return Collections.emptyList();
    } catch (Exception err) {
        return wrapException(err);
    } finally {
        CloserUtil.close(iter);
        CloserUtil.close(sfr);
        CloserUtil.close(sfw);
    }
}

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

public Object getFormattedValue(DataRowBase rowCurrent) {
    Object oValue = null;/*from w w  w . j av a  2 s  . co  m*/

    // First, find correct row!
    if (_dataBindingField.isForeignKey()) {
        LinkedList<DataBindingElement> elements = rowCurrent
                .getFKeyDisplayPath(_dataBindingField.getFieldName());

        DataRowBase rowFKey = getResolvedRow(elements, rowCurrent);

        oValue = getRawValue(rowFKey, elements.getLast().getPathElement());
    } else if ((_dataBindingMember.getDataBindingPathName().split("\\.").length > 1)) {
        // based on row, find referenced row
        if (_dataBindingField._strTableName.equals(rowCurrent.getTableName()))
            oValue = getRawValue(rowCurrent);
        else
            oValue = getRawValue(getResolvedRow(rowCurrent));
    } else {
        // then, read value from row
        oValue = getRawValue(rowCurrent);
    }

    String strFormattedValue = null;

    DataTypeFormat format = _dataBindingField.getDataFormat();
    if ((format == null) || (format instanceof EmptyTypeFormat)) {
        return ObjectUtils.toString(oValue);

    } else {
        try {
            if (oValue == null)
                strFormattedValue = null;
            else
                strFormattedValue = format.getFieldFormat().format(oValue);
        } catch (Exception ex) {
            LOG.debug(ex.getMessage());
            strFormattedValue = "";
        }
    }

    return strFormattedValue;
}

From source file:org.matsim.contrib.analysis.christoph.ActivitiesAnalyzer.java

@Override
public void notifyBeforeMobsim(BeforeMobsimEvent event) {

    ActivityData overallActivityData = this.overallCount.getLast();

    for (Person person : event.getServices().getScenario().getPopulation().getPersons().values()) {

        if (this.observedAgents != null && !this.observedAgents.contains(person.getId()))
            continue;

        Plan plan = person.getSelectedPlan();
        Activity firstActivity = (Activity) plan.getPlanElements().get(0);
        LinkedList<ActivityData> list = activityCountData.get(firstActivity.getType());

        // ignore not observed activity types
        if (list == null)
            continue;

        ActivityData activityData = list.getLast();
        activityData.activityCount += 1;
        overallActivityData.activityCount += 1;
    }//from ww w  .  j a v a  2  s .c o  m
}

From source file:com.codenjoy.dojo.services.dao.PlayerGameSaverTest.java

@Test
public void shouldSaleOnlyLastMessages_saveLoadChat() {
    ChatServiceImpl chat = new ChatServiceImpl();
    LinkedList<ChatMessage> messages = new LinkedList<ChatMessage>();
    chat.setMessages(messages);/*from  www.  j  a v  a 2  s.  co m*/

    setTime(0);
    chat.chat("apofig", "message1");

    setTime(1);
    chat.chat("apofig", "message2");

    setTime(2);
    chat.chat("apofig", "message3");
    assertEquals(TIME + 2000, messages.getLast().getTime().getTime());

    saver.saveChat(chat.getMessages());

    setTime(3);
    chat.chat("apofig", "message4");

    setTime(4);
    chat.chat("apofig", "message5");

    setTime(5);
    chat.chat("apofig", "message6");

    setTime(6);
    chat.chat("apofig", "message7");

    setTime(7);
    assertEquals(TIME + 6000, messages.getLast().getTime().getTime());

    saver.saveChat(chat.getMessages());

    List<ChatMessage> chatMessages = saver.loadChat();
    chat.setMessages(chatMessages);

    assertEquals("apofig, ?     ?\n"
            + "[15:03] apofig: message6\n" + "[15:03] apofig: message5\n" + "[15:03] apofig: message4\n"
            + "[15:03] apofig: message3\n" + "[15:03] apofig: message2\n" + "[15:03] apofig: message1\n",
            StringEscapeUtils.unescapeJava(chat.getChatLog()));
}

From source file:org.jboss.dashboard.error.ErrorManager.java

/**
 * Get the error cause (if any) thrown by the application logic.
 *///  w  w w. j a  v a2  s  .c  o m
public ApplicationError getApplicationErrorCause(Throwable e) {
    LinkedList<ApplicationError> appErrors = new LinkedList<ApplicationError>();
    Throwable cause = e;
    while (cause != null) {
        if (cause instanceof ApplicationError)
            appErrors.add((ApplicationError) cause);
        cause = cause.getCause();
    }
    if (appErrors.isEmpty())
        return null;
    return appErrors.getLast();
}

From source file:WaitSemaphore.java

protected void logAcquire() {
    if (m_debug) {
        // Check if thread is already mapped
        Thread thread = Thread.currentThread();

        // Create stack trace
        StringWriter sw = new StringWriter();
        new Exception().printStackTrace(new PrintWriter(sw));
        String trace = sw.toString();

        LinkedList list = (LinkedList) m_logMap.get(thread);
        if (list != null) {
            // Thread is mapped
            // Add info
            Info prevInfo = (Info) list.getLast();
            Info info = new Info(thread, m_users, trace);
            list.add(info);/* w  ww  . jav a  2  s.c o  m*/
        } else {
            // Thread is not mapped, create list and add counter
            list = new LinkedList();
            Info info = new Info(thread, m_users, trace);
            list.add(info);
            // Map thread
            m_logMap.put(thread, list);
        }
    }
}

From source file:bamboo.openhash.fileshare.FileShare.java

/**
 * Transfer wblocks from the wblocks array to the ready queue.
 *//*from   w w w  . j av a 2s . com*/
public void make_parents(boolean done) {

    for (int l = 0; l < wblocks.size(); ++l) {
        logger.debug("level " + l + " of " + wblocks.size() + " size=" + wblocks.elementAt(l).size() + " done="
                + done);
        while ((wblocks.elementAt(l).size() >= BRANCHING) || (done && (wblocks.elementAt(l).size() > 1))) {
            int count = min(BRANCHING, wblocks.elementAt(l).size());
            logger.debug("count=" + count);
            for (int i = 0; i < count; ++i) {
                ByteBuffer bb = wblocks.elementAt(l).removeFirst();
                bb.flip();
                md.update(secret);
                md.update(bb.array(), 0, bb.limit());
                byte[] dig = md.digest();
                ready.addLast(new Pair<byte[], ByteBuffer>(dig, bb));
                if (l + 1 >= wblocks.size()) {
                    wblocks.setSize(max(wblocks.size(), l + 2));
                    wblocks.setElementAt(new LinkedList<ByteBuffer>(), l + 1);
                }
                LinkedList<ByteBuffer> next_level = wblocks.elementAt(l + 1);
                if (next_level.isEmpty() || (next_level.getLast().position() == 1024)) {
                    logger.debug("adding a new block to level " + (l + 1));
                    next_level.addLast(ByteBuffer.wrap(new byte[1024]));
                    next_level.getLast().putInt(l + 1);
                }
                logger.debug("adding a digest to level " + (l + 1));
                next_level.getLast().put(dig);
            }

            if (done)
                break;
        }
    }
    logger.debug("make_parents done");
}

From source file:com.mchp.android.PIC32_BTSK.TemperatureFragment.java

public void updateGraph(LinkedList<Integer> l) {
    setGraphViewData(l);//from   www . ja v a 2  s.c  o m
    graphViewSeries.resetData(graphViewData);
    graphViewSeries.removeGraphView(graphView);
    graphViewSeries.addGraphView(graphView);

    graphView.scrollToEnd();
    mLastTemp.setText(l.getLast().toString() + "\u00b0");
}

From source file:edu.csun.ecs.cs.multitouchj.ui.event.ObjectEventManager.java

protected void handleEvent() {
    setRunning(true);/*from ww w. ja  va  2  s  .  co m*/

    for (ObjectType objectType : ObjectType.values()) {
        eventsCleaned.put(objectType, true);
    }

    while (isRunning()) {
        synchronized (activeObjects) {
            // check for "started" or "moved"
            if (isUpdated()) {
                for (ObjectType objectType : activeObjects.keySet()) {
                    LinkedHashMap<Integer, ObjectObserverEvent> objects = activeObjects.get(objectType);
                    if (objects.size() > 0) {
                        LinkedList<ObjectObserverEvent> ooes = new LinkedList<ObjectObserverEvent>(
                                objects.values());
                        ObjectEvent objectEvent = null;
                        if (ObjectType.Floated.equals(objectType)) {
                            objectEvent = new FloatEvent(this, ooes.getLast(), ooes,
                                    (eventsCleaned.get(objectType)) ? ObjectEvent.Status.Started
                                            : ObjectEvent.Status.Moved);
                        } else {
                            objectEvent = new TouchEvent(this, ooes.getLast(), ooes,
                                    (eventsCleaned.get(objectType)) ? ObjectEvent.Status.Started
                                            : ObjectEvent.Status.Moved);
                        }
                        notifyEventListeners(objectEvent);

                        eventsCleaned.put(objectType, false);
                    }
                }

                setUpdated(false);
            }

            // check for "ended"
            for (ObjectType objectType : activeObjects.keySet()) {
                LinkedHashMap<Integer, ObjectObserverEvent> objects = activeObjects.get(objectType);
                if (objects.size() > 0) {
                    LinkedList<ObjectObserverEvent> ooes = new LinkedList<ObjectObserverEvent>(
                            objects.values());

                    // check for ones expired
                    long currentTime = (new Date()).getTime();
                    LinkedList<Integer> deletedIds = new LinkedList<Integer>();
                    for (ObjectObserverEvent ooe : ooes) {
                        if ((currentTime - ooe.getTime()) >= CLEAN_UP_TIME) {
                            deletedIds.add(ooe.getId());
                        }
                    }
                    for (int deletedId : deletedIds) {
                        objects.remove(deletedId);
                    }

                    // check if all expired
                    if (objects.size() == 0) {
                        ObjectEvent objectEvent = null;
                        if (ObjectType.Floated.equals(objectType)) {
                            objectEvent = new FloatEvent(this, ooes.getLast(), ooes, ObjectEvent.Status.Ended);
                        } else {
                            objectEvent = new TouchEvent(this, ooes.getLast(), ooes, ObjectEvent.Status.Ended);
                        }
                        notifyEventListeners(objectEvent);

                        eventsCleaned.put(objectType, true);
                    }
                }
            }
        }

        try {
            Thread.sleep(15);
        } catch (Exception exception) {
        }
    }
}