Example usage for java.util LinkedList indexOf

List of usage examples for java.util LinkedList indexOf

Introduction

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

Prototype

public int indexOf(Object o) 

Source Link

Document

Returns the index of the first occurrence of the specified element in this list, or -1 if this list does not contain the element.

Usage

From source file:eu.uqasar.model.tree.TreeNode.java

@Override
public boolean canChangePositionWithPreviousSibling(boolean changeParents) {
    LinkedList<TreeNode> directSiblings = (LinkedList<TreeNode>) getMutableSiblings();
    int currentIndex = directSiblings.indexOf(this);
    if (currentIndex > 0) {
        // switch currently selected node with the previous one
        return true;
    } else if (currentIndex == 0 && changeParents) {
        // add currently selected node as last entry to the previous
        // parent sibling
        LinkedList<TreeNode> parentSiblings = (LinkedList<TreeNode>) this.getParent().getMutableSiblings();
        int parentIndex = parentSiblings.indexOf(this.getParent());
        return parentIndex > 0;
    }//from   www.  ja  va  2 s . c  o  m
    return false;
}

From source file:eu.uqasar.model.tree.TreeNode.java

@Override
public boolean canChangePositionWithNextSibling(boolean changeParents) {
    LinkedList<TreeNode> directSiblings = (LinkedList<TreeNode>) getMutableSiblings();
    int currentIndex = directSiblings.indexOf(this);
    int newIndex = currentIndex + 1;
    if (newIndex < directSiblings.size()) {
        // switch currently selected node with the next one
        return true;
    } else if (newIndex >= directSiblings.size() && changeParents) {
        // add currently selected node as first entry to the next parent
        // sibling
        LinkedList<TreeNode> parentSiblings = (LinkedList<TreeNode>) this.getParent().getMutableSiblings();
        int parentIndex = parentSiblings.indexOf(this.getParent());
        int newParentIndex = parentIndex + 1;
        if (newParentIndex < parentSiblings.size()) {
            return true;
        }//from w  w  w. j  ava2s  .c  om
    }
    return false;
}

From source file:eu.uqasar.model.tree.TreeNode.java

@SuppressWarnings("unchecked")
@Override/*from  ww  w .  j  a  v a  2s.  c o m*/
public boolean changePositionWithNextSibling(boolean changeParents) {
    LinkedList<TreeNode> directSiblings = (LinkedList<TreeNode>) getMutableSiblings();
    int currentIndex = directSiblings.indexOf(this);
    int newIndex = currentIndex + 1;
    if (newIndex < directSiblings.size()) {
        // switch currently selected node with the next one
        TreeNode 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<TreeNode> parentSiblings = (LinkedList<TreeNode>) this.getParent().getMutableSiblings();
        int parentIndex = parentSiblings.indexOf(this.getParent());
        int newParentIndex = parentIndex + 1;
        if (newParentIndex < parentSiblings.size()) {
            TreeNode oldParent = this.getParent();
            LinkedList<TreeNode> oldParentChildren = oldParent.getChildren();
            oldParentChildren.removeLast();
            oldParent.setChildren(oldParentChildren);

            TreeNode 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:eu.uqasar.model.tree.TreeNode.java

@SuppressWarnings("unchecked")
@Override//from w w w  .  j a v  a 2s.co  m
public boolean changePositionWithPreviousSibling(boolean changeParents) {
    LinkedList<TreeNode> directSiblings = (LinkedList<TreeNode>) getMutableSiblings();
    int currentIndex = directSiblings.indexOf(this);
    int newIndex = currentIndex - 1;
    if (currentIndex > 0) {
        // switch currently selected node with the previous one
        TreeNode 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<TreeNode> parentSiblings = (LinkedList<TreeNode>) this.getParent().getMutableSiblings();
        int parentIndex = parentSiblings.indexOf(this.getParent());
        int newParentIndex = parentIndex - 1;
        if (parentIndex > 0) {
            TreeNode oldParent = this.getParent();
            LinkedList<TreeNode> oldParentChildren = oldParent.getChildren();
            oldParentChildren.remove(0);
            oldParent.setChildren(oldParentChildren);

            TreeNode 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.openmrs.module.chartsearch.solr.ChartSearchSearcher.java

/**
 * Adds filter Queries to the query for selected categories returned from the UI
 * /*from  ww  w  .  j a  v  a  2 s .c o  m*/
 * @param query
 * @param selectedCats
 */
public void addSelectedFilterQueriesToQuery(SolrQuery query, List<String> selectedCats) {
    String filterQuery = "";
    LinkedList<String> selectedCategories = new LinkedList<String>();
    selectedCategories.addAll(selectedCats);
    if (selectedCategories == null || selectedCategories.isEmpty()) {
    } else {
        LinkedList<CategoryFilter> existingCategories = new LinkedList<CategoryFilter>();
        existingCategories.addAll(getChartSearchService().getAllCategoryFilters());
        int indexOfFirstSelected = selectedCategories.indexOf(selectedCategories.getFirst());
        int indexOfLastSelected = selectedCategories.indexOf(selectedCategories.getLast());
        int indexOfFirstExisting = existingCategories.indexOf(existingCategories.getFirst());
        int indexOfLastExisting = existingCategories.indexOf(existingCategories.getLast());

        for (int i = indexOfFirstSelected; i <= indexOfLastSelected; i++) {
            String currentSelected = selectedCategories.get(i);
            for (int j = indexOfFirstExisting; j <= indexOfLastExisting; j++) {
                CategoryFilter currentExisting = existingCategories.get(j);
                String currentExistingName = currentExisting.getCategoryName();
                if (currentSelected.equals(currentExistingName.toLowerCase())) {
                    if (i != indexOfLastSelected) {
                        filterQuery += currentExisting.getFilterQuery() + " OR ";
                    } else
                        filterQuery += currentExisting.getFilterQuery();
                }
            }
        }
        query.addFilterQuery(filterQuery);
    }
}

From source file:com.helpinput.spring.SourceScaner.java

private void replaceList(LinkedList<Node> list, Node oldNode, Node newNode) {
    int idx = list.indexOf(oldNode);
    list.remove(idx);//from  w  ww  .ja v  a 2s.com
    list.add(idx, newNode);
}

From source file:acromusashi.stream.component.rabbitmq.AbstractContextBuilder.java

/**
 * ????????????RabbitMQ??// w  w w  .jav a2s . c  o  m
 * 
 * @param contextList ?
 * @return RabbitMQ
 * @throws RabbitmqCommunicateException ??????????
 */
protected Map<String, List<String>> initProcessLists(List<RabbitmqClusterContext> contextList)
        throws RabbitmqCommunicateException {
    if (this.contextMap == null) {
        this.contextMap = initContextMap(contextList);
    }

    Map<String, List<String>> processLists = new HashMap<String, List<String>>();

    LinkedList<String> processList = null;
    String connectionProcess = null;
    int processIndex = 0;

    for (String queueName : this.contextMap.keySet()) {
        //???????
        RabbitmqClusterContext context = this.contextMap.get(queueName);
        processList = new LinkedList<String>(context.getMqProcessList());

        //RabbitMQ????????
        //??(0)
        processIndex = 0;
        connectionProcess = context.getConnectionProcessMap().get(getClientId(queueName));
        if (connectionProcess != null) {
            processIndex = processList.indexOf(connectionProcess);
        }

        //RabbitMQ?????RabbitMQ??
        LinkedList<String> backwardProcesses = new LinkedList<String>(processList.subList(0, processIndex));
        LinkedList<String> forwardProcesses = new LinkedList<String>(
                processList.subList(processIndex, processList.size()));
        forwardProcesses.addAll(backwardProcesses);
        processList = new LinkedList<String>(forwardProcesses);

        processLists.put(queueName, processList);
    }

    return processLists;
}

From source file:view.visualization.TXTVisualization.java

public static void drawChart(String a, String b, String txt) {
    String[] boje = null;/*  w ww .j  ava2s . c om*/
    LinkedList<String> atributi = new LinkedList<String>();
    LinkedList<String> sviAtributi = new LinkedList<String>();
    String[] vrAtribut = null;
    XYSeries[] xy = null;
    XYSeriesCollection xySeriesCollection = new XYSeriesCollection();
    int brojac = 0;
    boolean kraj = false;
    LinkedList<Integer> numeric = new LinkedList<Integer>();

    try {
        BufferedReader in = new BufferedReader(new FileReader(txt));
        int br = Integer.parseInt(in.readLine().split(" ")[1]);
        for (int j = 0; j < br + 1; j++) {

            String pom = in.readLine();
            if (pom.contains("@attribute")) {
                if (pom.contains("numeric")) {
                    sviAtributi.add(pom.substring(11, pom.lastIndexOf("n") - 1));
                } else {
                    sviAtributi.add(pom.split(" ")[1]);
                }
            }
            if (pom.contains("@attribute") && pom.contains("numeric")) {
                atributi.add(pom.substring(11, pom.lastIndexOf("n") - 1));
            }
            if (!pom.contains("numeric")) {
                brojac++;
                numeric.add(j - 2);
            }

        }
        String s = in.readLine();
        boje = s.substring(s.indexOf("{") + 1, s.lastIndexOf("}")).split(",");
        xy = new XYSeries[boje.length];
        for (int i = 0; i < boje.length; i++) {

            xy[i] = new XYSeries(boje[i]);

        }
        while (!kraj) {
            String pom2 = in.readLine();

            if (!(pom2.contains("@data"))) {
                vrAtribut = pom2.split(",");
                for (int i = 0; i < xy.length; i++) {
                    if (xy[i].getKey().equals(vrAtribut[vrAtribut.length - 1])) {

                        xy[i].add(Double.parseDouble(vrAtribut[sviAtributi.indexOf(a)]),
                                Double.parseDouble(vrAtribut[sviAtributi.indexOf(b)]));

                    }
                }
            }
        }
        in.close();
    } catch (Exception e) {
        e.getMessage();
    }
    for (int i = 0; i < xy.length; i++) {
        xySeriesCollection.addSeries(xy[i]);
    }

    JFreeChart grafik = ChartFactory.createScatterPlot("Vizuelizacija", a, b, xySeriesCollection,
            PlotOrientation.VERTICAL, true, true, false);
    ChartFrame proba = new ChartFrame("DataMiner", grafik);

    proba.setVisible(true);
    proba.setSize(500, 600);

}

From source file:comingle.dragracing.TrackActivity.java

private void initMarkers(LinkedList<Integer> locs) {
    Paint text_paint = new Paint();
    text_paint.setColor(Color.BLACK);
    text_paint.setTextSize(20);/*from w w w.  j  a  v a 2s  .  c  om*/

    String prev = "Start";
    String next = "End";
    int x = locs.indexOf(getLocation());

    if (x == locs.size() - 1) {
        initEndFlag();
    }

    if (x == 0) {
        initStartFlag();
    }

    if (x > 0) {
        prev = String.format("<< %s", INTERVAL_MARKERS[x - 1]);
    }

    if (x < locs.size() - 1) {
        next = String.format("%s >>", INTERVAL_MARKERS[x]);
    }

    //adjusted placement of markers
    track_canvas.drawText(prev, 20, TOP_MARGIN - 70, text_paint);
    track_canvas.drawText(next, 800 - 50, TOP_MARGIN - 70, text_paint);

}

From source file:net.sourceforge.seqware.pipeline.plugins.MetadataTest.java

@Test
public void testListAllTables() {
    systemErr.println("Test List all Tables\n");
    launchPlugin("--list-tables");
    String output = getOut();//  w  ww .j a  v a 2 s  . com
    // fix up test to support basic workflow/run creation tools, see git commit 4862eaba7f3d7c7495155dc913ead745b544f358
    String[] tables = new String[] { "TableName", "study", "experiment", "sample", "ius", "lane",
            "sequencer_run", "workflow", "workflow_run" };
    LinkedList<String> stuff = new LinkedList(Arrays.asList(output.split("\n")));
    for (String table : tables) {
        int index = stuff.indexOf(table);
        if (index >= 0) {
            stuff.remove(index);
        } else {
            Assert.fail("Missing a table:" + table);
        }
    }
    while (!stuff.isEmpty()) {
        String s = stuff.poll();
        Assert.fail("There are extra tables listed: " + s);
    }
}