Example usage for java.util ArrayList remove

List of usage examples for java.util ArrayList remove

Introduction

In this page you can find the example usage for java.util ArrayList remove.

Prototype

public boolean remove(Object o) 

Source Link

Document

Removes the first occurrence of the specified element from this list, if it is present.

Usage

From source file:hu.ppke.itk.nlpg.purepos.model.internal.NGramModel.java

protected void iterate(TrieNode<Integer, Integer, W> node, ArrayList<TrieNode<Integer, Integer, W>> acc) {
    acc.add(node);/*from  w w w . j  av a  2  s . com*/
    if (node.getChildNodes() == null || node.getChildNodes().size() == 0) {
        for (W word : node.getWords().keySet()) {
            Pair<Integer, Double> max = findMax(acc, word);
            int index = max.getKey() + 1;
            if (max.getValue() != -1) {
                lambdas.set(index, lambdas.get(index) + node.getWord(word));
            }
            // logger.debug("Max:" + max + " add:" + node.getWord(word)
            // + " to:" + index + " lambdas:" + lambdas);
        }
    } else {
        for (TrieNode<Integer, Integer, W> child : node.getChildNodes().values()) {
            iterate(child, acc);

        }
    }
    acc.remove(acc.size() - 1);
}

From source file:extractsomecomments.TraversalFiles.java

public static void fileList(File inputFile, int node, ArrayList<String> path, String folderPath) {
    node++;/*from   ww w .  j  a v a 2 s.c  o m*/
    File[] files = inputFile.listFiles();
    if (!inputFile.exists()) {
        System.out.println("File doesn't exist!");
    } else if (inputFile.isDirectory()) {
        path.add(inputFile.getName());

        for (File f : files) {
            for (int i = 0; i < node - 1; i++) {
                System.out.print(" ");
            }
            System.out.print("|-" + f.getPath());

            String ext = FilenameUtils.getExtension(f.getName());
            if (ext.equals("java")) {
                try {
                    System.out.println(" => extracted");

                    //Get extracted file location and add it to output file name,
                    //in order to avoid files in different folder 
                    //have the same name.
                    String fileLocation = "";
                    for (String tmpPath : path) {
                        fileLocation += "-" + tmpPath;
                    }

                    String outFilePath = folderPath + "/" + f.getName() + fileLocation + "-all.txt";

                    //create output file
                    File outputFile = new File(outFilePath);
                    if (outputFile.createNewFile()) {
                        System.out.println("Create successful: " + outputFile.getName());
                    }

                    //extract comments
                    ExtractSomeComments.extractComments(f, outputFile);
                } catch (IOException ex) {
                    Logger.getLogger(TraversalFiles.class.getName()).log(Level.SEVERE, null, ex);
                }
            } else {
                System.out.println();
            }
            fileList(f, node, path, folderPath);
        }
        path.remove(node - 1);
    }
}

From source file:com.bluexml.side.form.clazz.utils.SynchronizeWithClass.java

protected void synchronizeMissingAttributes(FormContainer o, List<FormElement> children,
        AbstractClass real_class, Set<FormGroup> groups, String filterNS) {

    List<Attribute> allAttributes = real_class.getAllAttributes();

    // get FormElement that miss
    ArrayList<Attribute> missAtt = new ArrayList<Attribute>();

    if (allAttributes != null) {
        missAtt.addAll(allAttributes);/*from   ww w .  j  a v a 2  s.  c  o m*/
    }

    for (FormElement formElement : children) {
        ModelElement ref = formElement.getRef();
        if (ref != null && ref instanceof Attribute) {
            // linked element is attribute so remove this attribute from the missing list
            missAtt.remove(ref);
        }
    }

    EList<FormGroup> allSubGroups = o.getAllSubGroups();
    groups.addAll(allSubGroups);

    // now we have the attribute missing list
    // initialize missing Field
    for (Attribute attribute : missAtt) {
        // Field or searchField
        FormElement fieldForAttribute = null;
        if (o instanceof FormSearch) {
            fieldForAttribute = SearchInitialization.getSearchFieldForAttribute(attribute);
        } else if (o instanceof FormClass || o instanceof FormWorkflow) {
            fieldForAttribute = ClassDiagramUtils.getFieldForAttribute(attribute);
        } else {
            System.out.println("SynchronizeWithClass.synchronizeMissingAttributes() o :" + o);
        }
        if (WorkflowInitialization.filterFormElement(filterNS, fieldForAttribute)) {

            // get where to add the field
            FormGroup parent = null;
            // mybe a group exist with ref to the attribute container
            AbstractClass eContainer = (AbstractClass) attribute.eContainer();
            // search for matching group

            for (FormGroup formGroup : groups) {
                ModelElement ref = formGroup.getRef();
                if (ref != null && ref.equals(eContainer)) {
                    // matching group founded
                    parent = formGroup;
                    break;
                }
            }
            if (createMissingGroup && parent == null) {
                parent = ClassInitialization.createGroup(eContainer);
                groups.add(parent);
                addChild(o, parent);
            }
            if (parent == null) {
                parent = o;
            }

            // add new Field to the parent
            addChild(parent, fieldForAttribute);

        }
    }

}

From source file:com.evolveum.midpoint.web.component.wizard.resource.SynchronizationStep.java

private void deleteSyncObjectPerformed(AjaxRequestTarget target, ObjectSynchronizationType syncObject) {
    if (isSelected(syncObject)) {
        syncDtoModel.getObject().setSelected(null);
        insertEmptyThirdRow();//from ww  w.j  a v  a 2s .  co  m
        resetSelections(target);
        target.add(getThirdRowContainer());
    }

    ArrayList<ObjectSynchronizationType> list = (ArrayList<ObjectSynchronizationType>) syncDtoModel.getObject()
            .getObjectSynchronizationList();
    list.remove(syncObject);
    if (list.isEmpty()) {
        insertEmptyThirdRow();
        resetSelections(target);
        target.add(getThirdRowContainer());
    }

    target.add(getSyncObjectEditor(), getSyncObjectTable(), getNavigator());
    parentPage.refreshIssues(target);
}

From source file:com.piusvelte.hydra.ConnectionManager.java

void cleanDatabaseConnections(String database) {
    synchronized (databaseLock) {
        ArrayList<DatabaseConnection> connections = sDatabaseConnections.get(database);
        for (int i = 0; (i < connections.size())
                && (connections.size() > queuedDatabaseRequests.get(database)); i++) {
            DatabaseConnection connection = connections.get(i);
            if (!connection.isLocked()) {
                try {
                    connection.disconnect();
                } catch (Exception e) {
                    e.printStackTrace();
                }// w w  w.j  a  va 2s.  co  m
                connections.remove(i--);
            }
        }
        sDatabaseConnections.put(database, connections);
    }
}

From source file:fr.mobilit.neo4j.server.service.nantes.CycleRentTest.java

@BeforeClass
public void setUp() throws Exception {
    super.setUp(true);
    HttpClient client = new HttpClient();
    GetMethod get = null;/*  w w w  . j  a  va  2  s  .c o m*/
    try {
        // we do the http call and parse the xml response
        get = new GetMethod(CycleRentImpl.IMPORT_URL);
        client.executeMethod(get);
        javax.xml.stream.XMLInputFactory factory = javax.xml.stream.XMLInputFactory.newInstance();
        javax.xml.stream.XMLStreamReader parser = factory.createXMLStreamReader(get.getResponseBodyAsStream());
        ArrayList<String> currentXMLTags = new ArrayList<String>();
        int depth = 0;
        while (true) {
            int event = parser.next();
            if (event == javax.xml.stream.XMLStreamConstants.END_DOCUMENT) {
                break;
            }
            switch (event) {
            case javax.xml.stream.XMLStreamConstants.START_ELEMENT:
                currentXMLTags.add(depth, parser.getLocalName());
                String tagPath = currentXMLTags.toString();
                // here we have a match, so we construct the POI
                if (tagPath.equals("[carto, markers, marker]")) {
                    numberOfStations++;
                }
                depth++;
                break;
            case javax.xml.stream.XMLStreamConstants.END_ELEMENT:
                depth--;
                currentXMLTags.remove(depth);
                break;
            default:
                break;
            }
        }
    } catch (Exception e) {
        throw new RuntimeException(e.getMessage(), e.getCause());
    } finally {
        get.releaseConnection();
    }
}

From source file:com.dev.pygmy.game.GameHomePageActivity.java

private void onReportClick() {
    final ArrayList<String> selectedItems = new ArrayList<String>();
    final String[] reasons = getResources().getStringArray(R.array.report_reasons);

    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle("Report: " + ((TextView) findViewById(R.id.name_game)).getText());
    builder.setMultiChoiceItems(reasons, null, new DialogInterface.OnMultiChoiceClickListener() {

        @Override/*  w  w w  .ja  v a 2 s.  c om*/
        public void onClick(DialogInterface dialog, int indexSelected, boolean isChecked) {
            String reason = reasons[indexSelected];
            if (isChecked) {
                selectedItems.add(reason);
            } else if (selectedItems.contains(reason)) {
                selectedItems.remove(reason);
            }

            Button positiveButton = ((AlertDialog) dialog).getButton(DialogInterface.BUTTON_POSITIVE);
            positiveButton.setEnabled((selectedItems.size() != 0));
        }
    })
            // Assign action buttons
            .setPositiveButton("OK", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int id) {
                    new GameReportTask(GameHomePageActivity.this, selectedItems).execute(mGame.name);
                }
            }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int id) {
                    Toast.makeText(GameHomePageActivity.this, "Report canceled", Toast.LENGTH_SHORT).show();
                }
            });

    reportDialog = builder.create();
    reportDialog.show();
    reportDialog.getButton(DialogInterface.BUTTON_POSITIVE).setEnabled(false);
}

From source file:extractcomments.TraversalFiles.java

public static void fileList(File inputFile, int node, ArrayList<String> path, String folderPath) {
    node++;/*  w  w  w .j a  v  a 2  s . c  o  m*/
    File[] files = inputFile.listFiles();
    if (!inputFile.exists()) {
        System.out.println("File doesn't exist!");
    } else if (inputFile.isDirectory()) {
        path.add(inputFile.getName());

        for (File f : files) {
            for (int i = 0; i < node - 1; i++) {
                System.out.print(" ");
            }
            System.out.print("|-" + f.getPath());

            String ext = FilenameUtils.getExtension(f.getName());
            if (ext.equals("java")) {
                try {
                    System.out.println(" => extracted");

                    //Get extracted file location and add it to output file name,
                    //in order to avoid files in different folder 
                    //have the same name.
                    String fileLocation = "";
                    for (String tmpPath : path) {
                        fileLocation += "-" + tmpPath;
                    }

                    String outFilePath = folderPath + "/" + f.getName() + fileLocation + "-all.txt";

                    //create output file
                    File outputFile = new File(outFilePath);
                    if (outputFile.createNewFile()) {
                        System.out.println("Create successful: " + outputFile.getName());
                    }

                    //extract comments
                    ExtractComments.extractComments(f, outputFile);
                } catch (IOException ex) {
                    Logger.getLogger(TraversalFiles.class.getName()).log(Level.SEVERE, null, ex);
                }
            } else {
                System.out.println(" isn't a java file.");
            }
            fileList(f, node, path, folderPath);
        }
        path.remove(node - 1);
    }
}

From source file:com.l2jfree.gameserver.geodata.pathfinding.PathFinding.java

public final Node[] searchByClosest(Node start, Node end, int instanceId) {
    // Note: This is the version for cell-based calculation, harder
    // on cpu than from block-based pathnode files. However produces better routes.

    // Always continues checking from the closest to target non-blocked
    // node from to_visit list. There's extra length in path if needed
    // to go backwards/sideways but when moving generally forwards, this is extra fast
    // and accurate. And can reach insane distances (try it with 8000 nodes..).
    // Minimum required node count would be around 300-400.
    // Generally returns a bit (only a bit) more intelligent looking routes than
    // the basic version. Not a true distance image (which would increase CPU
    // load) level of intelligence though.

    // List of Visited Nodes
    CellNodeMap known = CellNodeMap.newInstance();
    // List of Nodes to Visit
    ArrayList<Node> to_visit = L2Collections.newArrayList();
    to_visit.add(start);//from   w w w  .j ava 2s . c  o m
    known.add(start);
    try {
        int targetx = end.getNodeX();
        int targety = end.getNodeY();
        int targetz = end.getZ();

        int dx, dy, dz;
        boolean added;
        int i = 0;
        while (i < 3500) {
            if (to_visit.isEmpty()) {
                // No Path found
                return null;
            }

            Node node = to_visit.remove(0);

            i++;

            node.attachNeighbors(instanceId);
            if (node.equals(end)) {
                //path found! note that node z coordinate is updated only in attach
                //to improve performance (alternative: much more checks)
                //System.out.println("path found, i:"+i);
                return constructPath(node);
            }

            Node[] neighbors = node.getNeighbors();
            if (neighbors == null)
                continue;
            for (Node n : neighbors) {
                if (!known.contains(n)) {

                    added = false;
                    n.setParent(node);
                    dx = targetx - n.getNodeX();
                    dy = targety - n.getNodeY();
                    dz = targetz - n.getZ();
                    n.setCost(dx * dx + dy * dy + dz / 2 * dz/*+n.getCost()*/);
                    for (int index = 0; index < to_visit.size(); index++) {
                        // supposed to find it quite early..
                        if (to_visit.get(index).getCost() > n.getCost()) {
                            to_visit.add(index, n);
                            added = true;
                            break;
                        }
                    }
                    if (!added)
                        to_visit.add(n);
                    known.add(n);
                }
            }
        }
        //No Path found
        //System.out.println("no path found");
        return null;
    } finally {
        CellNodeMap.recycle(known);
        L2Collections.recycle(to_visit);
    }
}

From source file:com.xpn.xwiki.plugin.chronopolys.FolderManager.java

public ArrayList<Object> getProjectContainerBrothers(String uid, boolean elder, XWikiContext context)
        throws XWikiException {
    Object container = getProjectContainer(uid, context);
    ArrayList<Object> containers = getProjectContainerBrothers(uid, context);
    Object obj;//from   w  ww.j  av  a  2  s.  com

    int index = Integer.parseInt(container.display("order", "view").toString());
    for (int i = 0; i < containers.size(); i++) {
        obj = containers.get(i);
        if (index > Integer.parseInt(obj.display("order", "view").toString())) {
            if (elder) {
                containers.remove(i);
                i--;
            }
        } else {
            if (!elder) {
                containers.remove(i);
                i--;
            }
        }
    }
    return containers;
}