Example usage for java.util ArrayList iterator

List of usage examples for java.util ArrayList iterator

Introduction

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

Prototype

public Iterator<E> iterator() 

Source Link

Document

Returns an iterator over the elements in this list in proper sequence.

Usage

From source file:net.morphbank.mbsvc3.webservices.Uploader.java

private boolean processRequest(InputStream in, PrintWriter out, String fileName, String folderPath) {
    try {/*w w w .  java  2s.c  o  m*/
        ArrayList<String> filesToProcess = new ArrayList<String>();
        //TODO check if it is a csv file
        if (fileName.endsWith(".xls")) {
            filesToProcess = splitXls(folderPath);
            if (filesToProcess == null) {
                return false;
            }
        } else { //it's a csv file
            filesToProcess.add(folderPath + "temp.csv");
        }
        Iterator<String> iter = filesToProcess.iterator();
        while (iter.hasNext()) {
            String next = iter.next();
            Request requestDoc = createRequest(next, folderPath);
            //            if (requestDoc == null) {
            //               listOfXmlFiles.add("request null");
            //            }
            String xmlFileName = this.processXls(requestDoc, folderPath); //convert xls to xml
            if (sendToDB) { //upload the file to morphbank
                this.processUpload(xmlFileName, folderPath);
            }
        }
        Tools.eraseTempFile(folderPath, "temp.xls", false);
        Tools.eraseTempFile(folderPath, "temp.csv", false);
    } catch (Exception e) {
        e.printStackTrace(out);
        out.close();
    }
    return true;
}

From source file:com.esri.geoevent.solutions.adapter.cot.CoTAdapter.java

private String filterOutDots(String s) {
    String sStageOne = s.replace("h.", "").replace("t.", "").replace("r.", "").replace("q.", "").replace("o.",
            "");//from  w  w w . ja  v a2  s .  c o m

    String[] s2 = sStageOne.trim().split(" ");

    ArrayList<String> l1 = new ArrayList<String>();
    for (String item : s2) {
        l1.add(item);

    }
    ArrayList<String> l2 = new ArrayList<String>();

    Iterator<String> iterator = l1.iterator();

    while (iterator.hasNext()) {
        String o = (String) iterator.next();
        if (!l2.contains(o))
            l2.add(o);
    }

    StringBuffer sb = new StringBuffer();
    for (String item : l2) {
        sb.append(item);
        sb.append(" ");

    }

    return sb.toString().trim().toLowerCase();
}

From source file:com.cup.jmx.modeler.modules.MbeansDescriptorsDigesterSource.java

public void execute() throws Exception {
    if (registry == null) {
        registry = Registry.getRegistry(null, null);
    }//from  w  w w. j a  v a  2  s  .com

    InputStream stream = (InputStream) source;

    if (digester == null) {
        digester = createDigester();
    }
    ArrayList<ManagedBean> loadedMbeans = new ArrayList<ManagedBean>();

    synchronized (digester) {

        // Process the input file to configure our registry
        try {
            // Push our registry object onto the stack
            digester.push(loadedMbeans);
            digester.parse(stream);
        } catch (Exception e) {
            log.error("Error digesting Registry data", e);
            throw e;
        } finally {
            digester.reset();
            //                digester.resetRoot();
            //                digester.setErrorHandler(null);
            //                digester.clear();
        }

    }
    Iterator<ManagedBean> iter = loadedMbeans.iterator();
    while (iter.hasNext()) {
        registry.addManagedBean(iter.next());
    }
}

From source file:edu.umd.cfar.lamp.viper.geometry.ConvexPolygon.java

/**
 * Gets all the component polygons of this set.
 * /*from ww  w  . j a va 2 s . c  om*/
 * @return an iterator that just returns one element, <code>this</code>
 */
public Iterator getPolys() {
    ArrayList temp = new ArrayList(1);
    temp.add(this);
    return temp.iterator();
}

From source file:com.all4tec.sa.maven.proguard.ProGuardMojo.java

private static void proguardMain(File proguardJar, ArrayList<String> argsList, ProGuardMojo mojo)
        throws MojoExecutionException {

    Java java = new Java();

    Project antProject = new Project();
    antProject.setName(mojo.mavenProject.getName());
    antProject.init();//  ww  w  . j a  v a2 s  .c  om

    DefaultLogger antLogger = new DefaultLogger();
    antLogger.setOutputPrintStream(System.out);
    antLogger.setErrorPrintStream(System.err);
    antLogger.setMessageOutputLevel(mojo.log.isDebugEnabled() ? Project.MSG_DEBUG : Project.MSG_INFO);

    antProject.addBuildListener(antLogger);
    antProject.setBaseDir(mojo.mavenProject.getBasedir());

    java.setProject(antProject);
    java.setTaskName("proguard");

    mojo.getLog().info("proguard jar: " + proguardJar);

    java.createClasspath().setLocation(proguardJar);
    // java.createClasspath().setPath(System.getProperty("java.class.path"));
    java.setClassname(mojo.proguardMainClass);

    java.setFailonerror(true);

    java.setFork(true);

    // get the maxMemory setting
    if (mojo.maxMemory != null) {
        java.setMaxmemory(mojo.maxMemory);
    }

    for (Iterator<String> i = argsList.iterator(); i.hasNext();) {
        java.createArg().setValue(i.next());
    }

    int result = java.executeJava();
    if (result != 0) {
        throw new MojoExecutionException("Obfuscation failed (result=" + result + ")");
    }
}

From source file:com.nubits.nubot.trading.wrappers.CcedkWrapper.java

@Override
public ApiResponse getOrderDetail(String orderID) {
    ApiResponse apiResponse = new ApiResponse();

    ApiResponse getActiveOrders = getActiveOrders();
    boolean found = false;
    if (getActiveOrders.isPositive()) {
        apiResponse.setResponseObject(false);
        ArrayList<Order> orderList = (ArrayList) getActiveOrders.getResponseObject();
        for (Iterator<Order> order = orderList.iterator(); order.hasNext();) {
            Order thisOrder = order.next();
            if (thisOrder.getId().equals(orderID)) {
                apiResponse.setResponseObject(thisOrder);
                found = true;//  w w w  .jav a 2  s . com
                break;
            }
        }
        if (!found)
            apiResponse.setError(errors.orderNotFound);
    } else {
        apiResponse = getActiveOrders;
    }

    return apiResponse;
}

From source file:de.sub.goobi.forms.AdministrationForm.java

/**
 * Correct PPNs for statistic.//from  www .j  a v a  2  s  . c  o m
 */
@SuppressWarnings("unchecked")
public void PPNsFuerStatistischesJahrbuchKorrigieren() throws DAOException {
    Session session = Helper.getHibernateSession();
    Criteria crit = session.createCriteria(Process.class);
    crit.add(Restrictions.eq("template", Boolean.FALSE));
    crit.createCriteria("project", "proj");
    crit.add(Restrictions.like("proj.titel", "UB-MannheimDigizeit"));

    /* alle Prozesse durchlaufen */
    for (Iterator<Process> iter = crit.list().iterator(); iter.hasNext();) {
        Process p = iter.next();
        if (serviceManager.getProcessService().getBlockedUsers(p) != null) {
            Helper.setFehlerMeldung("metadata locked: ", p.getTitle());
        } else {
            String ppn = BeanHelper.determineWorkpieceProperty(p, "PPN digital").replace("PPN ", "")
                    .replace("PPN", "");
            String jahr = BeanHelper.determineScanTemplateProperty(p, "Bandnummer");
            String ppnAufBandebene = "PPN" + ppn + "_" + jahr;

            Prefs myPrefs = serviceManager.getRulesetService().getPreferences(p.getRuleset());
            try {
                Fileformat gdzfile = serviceManager.getProcessService().readMetadataFile(p);
                DocStruct dsTop = gdzfile.getDigitalDocument().getLogicalDocStruct();
                DocStruct dsFirst = null;
                if (dsTop.getAllChildren() != null && dsTop.getAllChildren().size() > 0) {
                    dsFirst = dsTop.getAllChildren().get(0);
                }

                MetadataType mdtPpnDigital = UghHelper.getMetadataType(myPrefs, "CatalogIDDigital");

                /* digitale PPN korrigieren */
                if (dsFirst != null) {
                    List<? extends Metadata> alleMetadaten = dsFirst.getAllMetadataByType(mdtPpnDigital);
                    if (alleMetadaten == null || alleMetadaten.size() == 0) {
                        Metadata md = new Metadata(mdtPpnDigital);
                        md.setValue(ppnAufBandebene);
                        dsFirst.addMetadata(md);
                    }
                }

                /* Collections korrigieren */
                List<String> myKollektionenTitel = new ArrayList<String>();
                MetadataType coltype = UghHelper.getMetadataType(myPrefs, "singleDigCollection");
                ArrayList<Metadata> myCollections;
                if (dsTop.getAllMetadataByType(coltype) != null) {
                    myCollections = new ArrayList<Metadata>(dsTop.getAllMetadataByType(coltype));
                    if (myCollections.size() > 0) {
                        for (Iterator<Metadata> it = myCollections.iterator(); it.hasNext();) {
                            Metadata md = it.next();
                            if (myKollektionenTitel.contains(md.getValue())) {
                                dsTop.removeMetadata(md);
                            } else {
                                myKollektionenTitel.add(md.getValue());
                            }
                        }
                    }
                }
                if (dsFirst != null && dsFirst.getAllMetadataByType(coltype).size() > 0) {
                    myKollektionenTitel = new ArrayList<String>();
                    myCollections = new ArrayList<Metadata>(dsFirst.getAllMetadataByType(coltype));
                    if (myCollections.size() > 0) {
                        for (Iterator<Metadata> it = myCollections.iterator(); it.hasNext();) {
                            Metadata md = it.next();
                            if (myKollektionenTitel.contains(md.getValue())) {
                                dsFirst.removeMetadata(md);
                            } else {
                                myKollektionenTitel.add(md.getValue());
                            }
                        }
                    }
                }

                serviceManager.getProcessService().writeMetadataFile(gdzfile, p);

            } catch (ReadException e) {
                Helper.setFehlerMeldung("", "ReadException: " + p.getTitle() + " - " + e.getMessage());
                myLogger.error("ReadException: " + p.getTitle(), e);
            } catch (IOException e) {
                Helper.setFehlerMeldung("", "IOException: " + p.getTitle() + " - " + e.getMessage());
                myLogger.error("IOException: " + p.getTitle(), e);
            } catch (InterruptedException e) {
                Helper.setFehlerMeldung("", "InterruptedException: " + p.getTitle() + " - " + e.getMessage());
                myLogger.error("InterruptedException: " + p.getTitle(), e);
            } catch (PreferencesException e) {
                Helper.setFehlerMeldung("", "PreferencesException: " + p.getTitle() + " - " + e.getMessage());
                myLogger.error("PreferencesException: " + p.getTitle() + " - " + e.getMessage());
            } catch (UghHelperException e) {
                Helper.setFehlerMeldung("", "UghHelperException: " + p.getTitle() + " - " + e.getMessage());
                myLogger.error("UghHelperException: " + p.getTitle(), e);
            } catch (Exception e) {
                Helper.setFehlerMeldung("", "Exception: " + p.getTitle() + " - " + e.getMessage());
                myLogger.error("Exception: " + p.getTitle(), e);
            }
        }
    }
    Helper.setMeldung(null, "", "------------------------------------------------------------------");
    Helper.setMeldung(null, "", "PPNs adjusted");
}

From source file:com.nubits.nubot.trading.wrappers.AllCoinWrapper.java

@Override
public ApiResponse getOrderDetail(String orderID) {
    ApiResponse apiResponse = new ApiResponse();

    boolean found = false;
    ApiResponse activeOrders = getActiveOrders();
    if (activeOrders.isPositive()) {
        ArrayList<Order> orders = (ArrayList) activeOrders.getResponseObject();
        for (Iterator<Order> order = orders.iterator(); order.hasNext();) {
            Order thisOrder = order.next();
            if (thisOrder.getId().equals(orderID)) {
                apiResponse.setResponseObject(thisOrder);
                found = true;/*  w  w  w . j  a va 2 s . c  om*/
                break;
            }
        }
        if (!found)
            apiResponse.setError(errors.orderNotFound);
    } else {
        apiResponse = activeOrders;
    }
    return apiResponse;
}

From source file:coolmap.application.widget.impl.WidgetUserGroup.java

private void initPopup() {
    JPopupMenu popup = new JPopupMenu();
    table.setComponentPopupMenu(popup);/*from   w  ww  .ja  v  a 2 s .  co  m*/

    JMenuItem item = new JMenuItem("Rename");
    popup.add(item);
    item.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            List<String> groupNames = getSelectedGroups();
            if (groupNames.isEmpty()) {
                return;
            }

            String returnVal = JOptionPane.showInputDialog(CoolMapMaster.getCMainFrame(),
                    "Please provide a new name:");
            if (returnVal == null || returnVal.length() == 0) {
                returnVal = "Untitled";
            }

            int counter = 0;
            String newName;
            for (String groupName : groupNames) {
                if (counter == 0) {
                    newName = returnVal;
                } else {
                    newName = returnVal + "_" + counter;
                }

                //new name must not exist
                int subCounter = 0;
                String name = newName;
                while (nodeGroups.containsKey(name)) {
                    subCounter++;
                    name = newName + "_" + subCounter;
                }
                newName = name;

                Color c = nodeColor.get(groupName);
                Set<VNode> nodes = new HashSet(nodeGroups.get(groupName));

                nodeColor.remove(groupName);
                nodeGroups.removeAll(groupName);

                nodeColor.put(newName, c);
                nodeGroups.putAll(newName, nodes);

                //                    System.out.println(newName + " " + c + " " + nodes);
                counter++;
            }

            updateTable();

        }
    });
    ////////////////////////////////////////////////////////////////////////

    //remove operations
    item = new JMenuItem("Remove");
    popup.add(item);
    item.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            List<String> groupNames = getSelectedGroups();
            for (String group : groupNames) {
                nodeColor.remove(group);
                nodeGroups.removeAll(group);
            }
            updateTable();
        }
    });

    //add separarator
    popup.addSeparator();
    JMenu insertRow = new JMenu("Add selected to row");
    popup.add(insertRow);

    JMenu insertColumn = new JMenu("Add selected to column");
    popup.add(insertColumn);

    item = new JMenuItem("prepend", UI.getImageIcon("prependRow"));
    insertRow.add(item);
    item.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            insertRow(0);
        }
    });

    item = new JMenuItem("prepend", UI.getImageIcon("prependColumn"));
    insertColumn.add(item);
    item.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            insertColumn(0);
        }
    });

    item = new JMenuItem("insert", UI.getImageIcon("insertRow"));
    item.setToolTipText("Insert selected groups to the selected region in the active coolmap view");
    insertRow.add(item);
    item.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {

            CoolMapObject obj = CoolMapMaster.getActiveCoolMapObject();
            if (obj == null) {
                return;
            }

            int index = 0;
            ArrayList selectedRows = obj.getCoolMapView().getSelectedRows();
            if (!selectedRows.isEmpty()) {
                index = ((Range<Integer>) selectedRows.iterator().next()).lowerEndpoint();
            }
            insertRow(index);
        }
    });

    item = new JMenuItem("insert", UI.getImageIcon("insertColumn"));
    item.setToolTipText("Insert selected groups to the selected region in the active coolmap view");
    insertColumn.add(item);
    item.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {

            CoolMapObject obj = CoolMapMaster.getActiveCoolMapObject();
            if (obj == null) {
                return;
            }

            int index = 0;
            ArrayList selectedColumns = obj.getCoolMapView().getSelectedColumns();
            if (!selectedColumns.isEmpty()) {
                index = ((Range<Integer>) selectedColumns.iterator().next()).lowerEndpoint();
            }
            insertColumn(index);
        }
    });

    item = new JMenuItem("append", UI.getImageIcon("appendRow"));
    insertRow.add(item);
    item.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            if (CoolMapMaster.getActiveCoolMapObject() == null) {
                return;
            }
            insertRow(CoolMapMaster.getActiveCoolMapObject().getViewNumRows());
        }
    });

    item = new JMenuItem("append", UI.getImageIcon("appendColumn"));
    insertColumn.add(item);
    item.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            if (CoolMapMaster.getActiveCoolMapObject() == null) {
                return;
            }
            insertColumn(CoolMapMaster.getActiveCoolMapObject().getViewNumColumns());
        }
    });

    item = new JMenuItem("replace", UI.getImageIcon("replaceRow"));
    insertRow.add(item);
    item.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            replaceRow();
        }
    });

    item = new JMenuItem("replace", UI.getImageIcon("replaceColumn"));
    insertColumn.add(item);
    item.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            replaceColumn();
        }
    });
}

From source file:com.cyberway.issue.crawler.util.BloomUriUniqFilterTest.java

/**
 * Test inserting.//from  w ww  .  j av a2 s  . c  o m
 * @throws URIException
 * @throws IOException
 * @throws FileNotFoundException
 */
public void testWriting() throws URIException {
    long start = System.currentTimeMillis();
    ArrayList<UURI> list = new ArrayList<UURI>(1000);
    int count = 0;
    final int MAX_COUNT = 1000;
    for (; count < MAX_COUNT; count++) {
        assertEquals("count off", count, filter.count());
        UURI u = UURIFactory.getInstance("http://www" + count + ".archive.org/" + count + "/index.html");
        assertFalse("already contained " + u.toString(), filter.bloom.contains(u.toString()));
        logger.fine("adding " + u.toString());
        filter.add(u.toString(), new CandidateURI(u));
        assertTrue("not in bloom", filter.bloom.contains(u.toString()));
        if (count > 0 && ((count % 100) == 0)) {
            list.add(u);
        }
    }
    logger.fine("Added " + count + " in " + (System.currentTimeMillis() - start));

    start = System.currentTimeMillis();
    for (Iterator i = list.iterator(); i.hasNext();) {
        UURI uuri = (UURI) i.next();
        filter.add(uuri.toString(), new CandidateURI(uuri));
    }
    logger.fine("Readded subset " + list.size() + " in " + (System.currentTimeMillis() - start));

    assertTrue("Count is off: " + filter.count(), filter.count() == MAX_COUNT);
}