Example usage for java.util LinkedList get

List of usage examples for java.util LinkedList get

Introduction

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

Prototype

public E get(int index) 

Source Link

Document

Returns the element at the specified position in this list.

Usage

From source file:eu.uqasar.model.qmtree.QMTreeNode.java

@SuppressWarnings("unchecked")
@Override//from   w  w w .  jav  a 2s  . c  o  m
public boolean changePositionWithPreviousSibling(boolean changeParents) {
    LinkedList<QMTreeNode> directSiblings = (LinkedList<QMTreeNode>) getMutableSiblings();
    int currentIndex = directSiblings.indexOf(this);
    int newIndex = currentIndex - 1;
    if (currentIndex > 0) {
        // switch currently selected node with the previous one
        QMTreeNode movedNode = directSiblings.remove(currentIndex);
        directSiblings.add(newIndex, movedNode);
        getParent().setChildren(directSiblings);
        logger.info(String.format("Moving %s from index %s to %s", this, currentIndex, newIndex));
        return true;
    } else if (currentIndex == 0 && changeParents) {
        // add currently selected node as last entry to the previous
        // parent sibling
        LinkedList<QMTreeNode> parentSiblings = (LinkedList<QMTreeNode>) this.getParent().getMutableSiblings();
        int parentIndex = parentSiblings.indexOf(this.getParent());
        int newParentIndex = parentIndex - 1;
        if (parentIndex > 0) {
            QMTreeNode oldParent = this.getParent();
            LinkedList<QMTreeNode> oldParentChildren = (LinkedList) oldParent.getChildren();
            oldParentChildren.remove(0);
            oldParent.setChildren(oldParentChildren);

            QMTreeNode newParent = parentSiblings.get(newParentIndex);
            logger.info(String.format("Moving %s from parent %s to %s", this, this.getParent(), newParent));
            this.setParent(newParent);
            return true;
        }
    }
    return false;
}

From source file:edu.cmu.tetrad.search.Lingam.java

private StlPruneResult stlPrune(TetradMatrix bHat) {
    int m = bHat.rows();

    LinkedList<Entry> entries = getEntries(bHat);

    // Sort entries by absolute value.
    java.util.Collections.sort(entries);

    TetradMatrix bHat2 = bHat.copy();// ww w  . ja v  a 2  s. co  m
    //
    int numUpperTriangle = m * (m + 1) / 2;
    int numTotal = m * m;
    //
    for (int i = 0; i < numUpperTriangle; i++) {
        Entry entry = entries.get(i);
        bHat.set(entry.row, entry.column, 0);
    }

    // If that doesn't result in a permutation, try setting one more entry
    // to zero, iteratively, until you get a permutation.
    for (int i = numUpperTriangle; i < numTotal; i++) {
        int[] permutation = algorithmB(bHat);

        if (permutation != null) {
            TetradMatrix Bestcausal = permute(permutation, bHat2);

            return new StlPruneResult(Bestcausal, permutation);
        }

        Entry entry = entries.get(i);
        bHat.set(entry.row, entry.column, 0);
    }

    throw new IllegalArgumentException("No permutation was found.");
}

From source file:edu.ku.brc.specify.config.DateConverter.java

/**
 * @param dateStr/*from  w w w. j  a v a  2s  . c  o  m*/
 * @return
 */
protected DateFormats match(String dateStr) {
    LinkedList<DateFormats> matches = new LinkedList<DateFormats>();
    for (DateFormats format : DateFormats.values()) {
        if (format.matches(dateStr)) {
            matches.add(format);
        }
    }

    if (matches.size() == 0) {
        return null;
    }

    if (matches.size() == 1) {
        return matches.get(0);
    }

    for (DateFormats format : matches) {
        if (preferMonthDay && format.equals(DateFormats.MON_DAY_LYEAR)
                || format.equals(DateFormats.MON_DAY_SYEAR)) {
            return format;
        } else if (!preferMonthDay && format.equals(DateFormats.DAY_MON_LYEAR)
                || format.equals(DateFormats.DAY_MON_SYEAR)) {
            return format;
        }
    }
    /*
     * It shouldn't be possible for multiple matches to exist involving formats other than DAY_MON_LYEAR/SYEAR and MON_DAY_LYEAR/SYEAR.
     * But if it occurs, complain and return null.
     */
    //        if (matches.size() > 0)
    //        {
    //            log.error("Unable to resolve multiple date-format matches for '" + dateStr + "'");
    //        }

    return null;
}

From source file:edu.ku.brc.util.DateConverter.java

/**
 * @param dateStr/*from   w  w  w  . ja v a 2  s. c  om*/
 * @return
 */
protected DateFormats match(String dateStr) {
    LinkedList<DateFormats> matches = new LinkedList<DateFormats>();
    for (DateFormats format : DateFormats.values()) {
        if (format.matches(dateStr)) {
            matches.add(format);
        }
    }

    if (matches.size() == 0) {
        return null;
    }

    if (matches.size() == 1) {
        return matches.get(0);
    }

    for (DateFormats format : matches) {
        if (preferMonthDay && format.equals(DateFormats.MON_DAY_LYEAR)
                || format.equals(DateFormats.MON_DAY_SYEAR)) {
            return format;
        } else if (!preferMonthDay && format.equals(DateFormats.DAY_MON_LYEAR)
                || format.equals(DateFormats.DAY_MON_SYEAR)) {
            return format;
        }
    }
    /*
     * It shouldn't be possible for multiple matches to exist involving formats other than DAY_MON_LYEAR/SYEAR and MON_DAY_LYEAR/SYEAR.
     * But if it occurs, complain and return null.
     */
    if (matches.size() > 0) {
        log.error("Unable to resolve multiple date-format matches for '" + dateStr + "'");
    }

    return null;
}

From source file:eu.uqasar.model.qmtree.QMTreeNode.java

@SuppressWarnings("unchecked")
@Override//from   w  w w .  jav a2  s.c om
public boolean changePositionWithNextSibling(boolean changeParents) {
    LinkedList<QMTreeNode> directSiblings = (LinkedList<QMTreeNode>) getMutableSiblings();
    int currentIndex = directSiblings.indexOf(this);
    int newIndex = currentIndex + 1;
    if (newIndex < directSiblings.size()) {
        // switch currently selected node with the next one
        QMTreeNode movedNode = directSiblings.remove(currentIndex);
        directSiblings.add(newIndex, movedNode);
        getParent().setChildren(directSiblings);
        logger.info(String.format("Moving %s from index %s to %s", this, currentIndex, newIndex));
        return true;
    } else if (newIndex >= directSiblings.size() && changeParents) {
        // add currently selected node as first entry to the next parent
        // sibling
        LinkedList<QMTreeNode> parentSiblings = (LinkedList<QMTreeNode>) this.getParent().getMutableSiblings();
        int parentIndex = parentSiblings.indexOf(this.getParent());
        int newParentIndex = parentIndex + 1;
        if (newParentIndex < parentSiblings.size()) {
            QMTreeNode oldParent = this.getParent();
            LinkedList<QMTreeNode> oldParentChildren = (LinkedList) oldParent.getChildren();
            oldParentChildren.removeLast();
            oldParent.setChildren(oldParentChildren);

            QMTreeNode newParent = parentSiblings.get(newParentIndex);
            logger.info(String.format("Moving %s from parent %s to %s", this, this.getParent(), newParent));
            this.setParent(newParent);
            return true;
        }
    }
    return false;
}

From source file:org.zeroxlab.zeroxbenchmark.Benchmark.java

public void runCase(LinkedList<Case> list) {
        Case pointer = null;//  w w w. j a  v a 2s. co  m
        boolean finish = true;
        for (int i = 0; i < list.size(); i++) {
            pointer = list.get(i);
            if (!pointer.isFinish()) {
                finish = false;
                break;
            }
        }

        if (finish) {
            //            mBannerInfo.setText("Benchmarking complete.\nClick Show to upload.\nUploaded results:\nhttp://0xbenchmark.appspot.com");
            String result = getResult();
            writeResult(mOutputFile, result);

            final ProgressDialog dialogGetXml = new ProgressDialog(this).show(this, "Generating XML Report",
                    "Please wait...", true, false);
            new Thread() {
                public void run() {
                    mJSONResult = getJSONResult();
                    mXMLResult = getXMLResult();
                    Log.d(TAG, "XML: " + mXMLResult);
                    writeResult(mOutputXMLFile, mXMLResult);
                    Log.d(TAG, "JSON: " + mJSONResult);
                    writeResult(mOutputJSONFile, mJSONResult);
                    mShow.setClickable(true);
                    onClick(mShow);
                    mTouchable = true;
                    dialogGetXml.dismiss();
                }
            }.start();
        } else {
            Intent intent = pointer.generateIntent();
            if (intent != null) {
                startActivityForResult(intent, 0);
            }
        }
    }

From source file:org.nekorp.workflow.desktop.view.CobranzaView.java

@Override
public void updateModel(Object origen, String property, Object value) {
    if (!ignore.remove(value)) {
        LinkedList<PagoCobranzaVB> param = (LinkedList<PagoCobranzaVB>) value;
        LinkedList<PagoCobranzaVB> borrar = new LinkedList<>();
        for (PagoCobranzaVB obj : modelo) {
            if (!param.contains(obj)) {
                borrar.add(obj);/*from   ww w. j  a  va2  s.  c  o  m*/
            }
        }
        for (PagoCobranzaVB x : borrar) {
            removePago(x);
        }
        for (int i = 0; i < param.size(); i++) {
            if (this.modelo.size() > i) {
                if (!param.get(i).equals(this.modelo.get(i))) {
                    this.modelo.add(i, param.get(i));
                    addPagoView(this.modelo.get(i), i);
                }
            } else {
                this.modelo.add(param.get(i));
                addPagoView(this.modelo.get(i), i);
            }
        }
        this.updateUI();
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                jScrollPane1.getVerticalScrollBar().setValue(jScrollPane1.getVerticalScrollBar().getMaximum());
            }
        });
    }
}

From source file:org.kitodo.production.forms.dataeditor.StructurePanel.java

private void checkLogicalDragDrop(IncludedStructuralElement dragStructure,
        IncludedStructuralElement dropStructure) {
    StructuralElementViewInterface divisionView = dataEditor.getRuleset().getStructuralElementView(
            dropStructure.getType(), dataEditor.getAcquisitionStage(), dataEditor.getPriorityList());

    LinkedList<IncludedStructuralElement> dragParents;
    if (divisionView.getAllowedSubstructuralElements().containsKey(dragStructure.getType())) {
        dragParents = MetadataEditor.getAncestorsOfStructure(dragStructure,
                dataEditor.getWorkpiece().getRootElement());
        if (!dragParents.isEmpty()) {
            IncludedStructuralElement parentStructure = dragParents.get(dragParents.size() - 1);
            if (parentStructure.getChildren().contains(dragStructure)) {
                preserveLogical();//  ww w  .  ja  va2 s.com
                return;
            } else {
                Helper.setErrorMessage(
                        "Parents of structure " + dragStructure.getType() + " do not contain structure!");
            }
        } else {
            Helper.setErrorMessage("No parents of structure " + dragStructure.getType() + " found!");
        }
    } else {
        Helper.setErrorMessage("Structure of type '" + dragStructure.getType()
                + "' NOT allowed as child of structure of type '" + dropStructure.getType() + "'! ");
    }
    show();
}

From source file:org.overture.codegen.vdm2java.JavaFormat.java

public String formatInterfaces(AClassDeclCG classDecl) {
    LinkedList<AInterfaceDeclCG> interfaces = classDecl.getInterfaces();

    if (interfaces == null || interfaces.isEmpty()) {
        return "";
    }//  w  w w  . java2s. c o m

    String implementsClause = "implements";

    implementsClause += " " + interfaces.get(0).getName();

    for (int i = 1; i < interfaces.size(); i++) {
        implementsClause += ", " + interfaces.get(i).getName();
    }

    return implementsClause;
}

From source file:org.samjoey.gui.GraphicalViewer.java

private void Graphs_MenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_Graphs_MenuItemActionPerformed
    String inputValue = JOptionPane.showInputDialog("Please input a values separated by commas:");
    try {/*from  w  w  w  . j  a v a 2 s  .  co  m*/
        String[] vals = inputValue.split(",");
        LinkedList<Game> getFor = new LinkedList<>();
        for (String str : vals) {
            getFor.add(games.get(Integer.parseInt(str)));
        }
        for (String s : getFor.get(0).getVarData().keySet()) {
            this.Variable_Chooser.addItem(s);
        }
        graphs = GraphUtility.getGraphs(getFor);
    } catch (Exception e) {
        try {
            String[] vals = inputValue.split(", ");
            LinkedList<Game> getFor = new LinkedList<>();
            for (String str : vals) {
                getFor.add(games.get(Integer.parseInt(str)));
            }
            for (String s : getFor.get(0).getVarData().keySet()) {
                this.Variable_Chooser.addItem(s);
            }
            graphs = GraphUtility.getGraphs(getFor);
        } catch (Exception ee) {
        }
    }
}