Example usage for java.util LinkedList addLast

List of usage examples for java.util LinkedList addLast

Introduction

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

Prototype

public void addLast(E e) 

Source Link

Document

Appends the specified element to the end of this list.

Usage

From source file:org.apache.metron.performance.load.monitor.writers.Writer.java

private void addToLookback(Double d, LinkedList<Double> lookback) {
    if (lookback.size() >= summaryLookback) {
        lookback.removeFirst();//w ww .  j av  a 2  s  .  c om
    }
    lookback.addLast(d);
}

From source file:org.rhq.enterprise.gui.legacy.util.SessionUtils.java

/**
 * Takes the current returnPath and pushes it onto the workflow's stack.
 *
 * @param session      The HttpSesion to get and save the workflow to/from
 * @param mapping      Use the input attribute from this mapping if a returnPath is not defined in the current
 *                     session.//from  w w w .ja v  a  2 s  . co  m
 * @param workflowName The name of the workflow scope to save the input under.
 */
public static void pushWorkflow(HttpSession session, ActionMapping mapping, String workflowName) {
    HashMap workflows = (HashMap) session.getAttribute(AttrConstants.WORKFLOW_SES_ATTR);
    if (workflows == null) {
        workflows = new HashMap();
    }

    String returnPath = getReturnPath(session);
    if (returnPath == null) {
        returnPath = mapping.getInput();
    }

    LinkedList urlStack = (LinkedList) workflows.get(workflowName);

    // whacking getIsFirst.. for some reason, even if i set the
    // property to false in struts-config.xml, it's still getting
    // set back to true. i can't have this, so i'm whacking the
    // check altogether. doesn't seem to harm anything. -bcm 7/9/03
    // if (urlStack == null || mapping.getIsFirst().booleanValue()) {
    if (urlStack == null) {
        urlStack = new LinkedList();
    }

    urlStack.addLast(returnPath);
    workflows.put(workflowName, urlStack);

    session.setAttribute(AttrConstants.WORKFLOW_SES_ATTR, workflows);
}

From source file:com.cyclopsgroup.waterview.web.RuntimeTreeNode.java

/**
 * Get node or child node by id/*  w w w  .j a v a  2  s.  c om*/
 *
 * @param nodeId Node id
 * @return Node or null if not found
 */
public RuntimeTreeNode getNodeById(String nodeId) {
    LinkedList buffer = new LinkedList();
    buffer.addLast(this);
    while (!buffer.isEmpty()) {
        RuntimeTreeNode node = (RuntimeTreeNode) buffer.removeFirst();
        if (StringUtils.equals(nodeId, node.getNodeId())) {
            return node;
        }
        buffer.addAll(node.children.values());
    }
    return null;
}

From source file:org.craftercms.studio.impl.repository.mongodb.services.impl.PathServicesImpl.java

private Node walkDownTheTree(String[] pathToDescent) throws MongoRepositoryException {

    Node tempNode = nodeService.getRootNode();
    //If pathToDescent length is 0 then you are getting root path right?
    for (int i = 0; i < pathToDescent.length; i++) {
        if (StringUtils.isBlank(pathToDescent[i])) {
            return nodeService.getRootNode();
        }/*  w  w w. ja v  a 2 s .  c om*/
        LinkedList<Node> ancestors = (LinkedList<Node>) tempNode.getAncestors().clone();
        ancestors.addLast(tempNode);
        tempNode = nodeService.findNodeByAncestorsAndName(ancestors, pathToDescent[i]);
        if (tempNode == null) {
            break;
        }
    }
    return tempNode;

}

From source file:org.openiam.idm.srvc.synch.srcadapter.SynchScriptFactory.java

public static List<TransformScript> createTransformationScript(SynchConfig config, SynchReview review)
        throws ClassNotFoundException, IOException {

    Map<String, Object> bindingMap = new HashMap<String, Object>();
    bindingMap.put("config", config);
    bindingMap.put("synchConfigId", config.getSynchConfigId());

    if (review != null) {
        bindingMap.put("review", review);
    }/*from   w ww.  j a  va 2s  .c  om*/

    LinkedList<TransformScript> scripts = new LinkedList<TransformScript>();

    if (config.getUsePolicyMap()) {
        AttributeMapDozerConverter attributeMapDozerConverter = (AttributeMapDozerConverter) SpringContextProvider
                .getBean("attributeMapDozerConverter");
        IdentitySynchService synchService = (IdentitySynchService) SpringContextProvider
                .getBean("synchService");
        List<AttributeMapEntity> attrMapEntity = synchService
                .getSynchConfigAttributeMaps(config.getSynchConfigId());
        List<AttributeMap> attrMap = attributeMapDozerConverter.convertToDTOList(attrMapEntity, true);

        TransformScript transformScript = new PolicyMapTransformScript(attrMap);
        scripts.add(transformScript);

    }
    if (config.getUseTransformationScript() && StringUtils.isNotBlank(config.getTransformationRule())) {
        TransformScript script = (TransformScript) createScript(config.getTransformationRule(), bindingMap);
        if (config.getPolicyMapBeforeTransformation()) {
            scripts.addLast(script);
        } else {
            scripts.addFirst(script);
        }
    }

    return scripts;
}

From source file:org.batoo.jpa.core.pool.GenericKeyedPool.java

/**
 * {@inheritDoc}/*from w w  w . j ava2s.c  o  m*/
 * 
 */
@Override
public void returnObject(K key, V obj) throws Exception {
    final LinkedList<V> pool = this.getPool(key);
    pool.addLast(obj);

    this.shrinkTo(key, pool, GenericKeyedPool.MAX_SIZE);
}

From source file:com.linuxbox.util.queueservice.mongodb.JavaQueueService.java

@Override
public synchronized void enqueue(String identifier, int shardKey, Object note) throws QueueServiceException {
    QueueEntry entry = new AbstractQueueEntry(new Date(), identifier, note, shardKey);
    LinkedList<QueueEntry> list = queue.get(identifier);
    if (list == null) {
        list = new LinkedList<QueueEntry>();
        queue.put(identifier, list);/* w ww .j  a va 2  s.c  o  m*/
    }
    list.addLast(entry);
}

From source file:opennlp.model.OnePassDataIndexer.java

/**
 * Reads events from <tt>eventStream</tt> into a linked list. The predicates
 * associated with each event are counted and any which occur at least
 * <tt>cutoff</tt> times are added to the <tt>predicatesInOut</tt> map along
 * with a unique integer index.//  w  w w  .  jav  a 2s  .c  om
 * 
 * @param eventStream
 *          an <code>EventStream</code> value
 * @param predicatesInOut
 *          a <code>TObjectIntHashMap</code> value
 * @param cutoff
 *          an <code>int</code> value
 * @return a <code>TLinkedList</code> value
 */
private LinkedList<Event> computeEventCounts(EventStream eventStream, Map<String, Integer> predicatesInOut,
        int cutoff) throws IOException {
    Set predicateSet = new HashSet();
    Map<String, Integer> counter = new HashMap<String, Integer>();
    LinkedList<Event> events = new LinkedList<Event>();
    while (eventStream.hasNext()) {
        Event ev = eventStream.next();
        events.addLast(ev);
        update(ev.getContext(), predicateSet, counter, cutoff);
    }
    predCounts = new int[predicateSet.size()];
    int index = 0;
    for (Iterator pi = predicateSet.iterator(); pi.hasNext(); index++) {
        String predicate = (String) pi.next();
        predCounts[index] = counter.get(predicate);
        predicatesInOut.put(predicate, index);
    }
    return events;
}

From source file:uk.ac.cam.cl.dtg.teaching.programmingtest.java.FittedCurve.java

private double fit(List<Point> mapped, double proportion) {
    Collections.shuffle(mapped);/*from w  w w  . j a  va 2s  .  c o  m*/
    int total = (int) (mapped.size() * proportion);
    double[][] x = new double[total][];
    double[] y = new double[total];
    Iterator<Point> step = mapped.iterator();
    for (int i = 0; i < total; ++i) {
        Point next = step.next();
        x[i] = next.xcoeff;
        y[i] = next.yvalue;
    }

    OLSMultipleLinearRegression ols = new OLSMultipleLinearRegression();
    ols.setNoIntercept(true);
    ols.newSampleData(y, x);
    RealMatrix coef = MatrixUtils.createColumnRealMatrix(ols.estimateRegressionParameters());
    double rsqTotal = 0.0;
    for (Point p : mapped) {
        double yhat = coef.preMultiply(p.xcoeff)[0];
        rsqTotal += unmapY(Math.pow(p.yvalue - yhat, 2.0));
    }

    if (DEBUG) {
        List<Point> newMaps = mapValues(this.xs, this.ys);
        LinkedList<Double> xs = new LinkedList<>();
        LinkedList<Double> ys = new LinkedList<>();
        int i = 0;
        for (Point p : newMaps) {
            double yhat = unmapY(coef.preMultiply(p.xcoeff)[0]);
            ys.addLast(yhat);
            xs.addLast(this.xs[i++]);
        }
        System.out.println("x=[" + Joiner.on(",").join(xs) + "]");
        System.out.println("y=[" + Joiner.on(",").join(ys) + "]");
    }
    return rsqTotal;
}

From source file:pl.otros.logview.gui.message.StackTraceFinder.java

public SortedSet<SubText> findStackTraces(String text) {
    SortedSet<SubText> set = new TreeSet<SubText>();
    LinkedList<Integer> newLineIndexes = new LinkedList<Integer>();
    newLineIndexes.add(0);/*ww w . ja  v a2 s  .c o  m*/
    int newLineIndex = -1;
    while ((newLineIndex = StringUtils.indexOf(text, '\n', newLineIndex + 1)) > -1) {
        newLineIndexes.addLast(newLineIndex);
    }
    if (newLineIndexes.getLast() < text.length()) {
        newLineIndexes.addLast(text.length());
    }

    int startLine;
    int endLine;
    boolean found = false;
    int startedLineException = -1;
    for (int i = 0; i < newLineIndexes.size() - 1; i++) {
        startLine = newLineIndexes.get(i);
        endLine = newLineIndexes.get(i + 1);
        String line = text.substring(startLine, endLine);
        Matcher matcher = exceptionLine.matcher(line);
        boolean f = matcher.find();
        if (f && !found) {
            startedLineException = i - 1;
        } else if (!f && found) {
            // exception end
            int start = newLineIndexes.get(startedLineException);
            int end = newLineIndexes.get(i);
            SubText subText = new SubText(start, end);
            set.add(subText);
        }
        found = f;
    }
    // Add stacktrace if string with end of stacktrace
    if (found) {
        int start = newLineIndexes.get(startedLineException);
        int end = newLineIndexes.getLast();
        SubText subText = new SubText(start, end);
        set.add(subText);
    }
    // for (SubText subText : set) {
    // System.out.printf("[%d -> %d] \n\"%s\"", subText.start, subText.end, text.substring(subText.start, subText.end));
    // }
    return set;
}