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:javaapplication3.ZCorpDialog.java

private void submitBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_submitBtnActionPerformed
    if (validateForm()) {
        Integer day = Integer.parseInt(days.getSelectedItem().toString());
        Integer hr = Integer.parseInt(hours.getSelectedItem().toString());
        Integer min = Integer.parseInt(minutes.getSelectedItem().toString());
        buildTime = day + ":" + hr + ":" + min;

        String buildPath = BPath.getText();
        buildName = new File(buildPath).getName();
        buildPath = buildPath.replace("\\", "\\\\");
        //File file = new File(buildPath);
        //buildName = file.getName();
        modelAmount = Integer.parseInt(numOfModels.getText());
        comments = comment.getText();// w w  w  .j av a2  s.c o  m
        //hideErrorFields();

        //this is stuff about price
        ResultSet res = ZCorpMain.dba.searchPrinterSettings("zcorp");
        try {
            if (res.next()) {
                monoPrice = Double.parseDouble(res.getString("materialCostPerUnit"));
                yellowPrice = Double.parseDouble(res.getString("materialCostPerUnit2"));
                magentaPrice = Double.parseDouble(res.getString("materialCostPerUnit3"));
                cyanPrice = Double.parseDouble(res.getString("materialCostPerUnit4"));
            }
        } catch (SQLException ex) {
            Logger.getLogger(ZCorpDialog.class.getName()).log(Level.SEVERE, null, ex);
        }

        //now dealing with buildCost
        try {
            buildCost = Calculations.ZcorpCost(cubicInches);

        } catch (Exception e) {
            errFree = false;
        }
        //Checks if there were errors
        if (errFree) {
            try {
                //This is where we would add the call to the method that udpates things in completed Jobs
                //Updates project cost in pending
                ZCorpMain.calc.BuildtoProjectCost(buildName, "Zcorp", buildCost);

                ResultSet res2 = ZCorpMain.dba.searchPendingByBuildName(buildName);
                ArrayList list = new ArrayList();
                try {
                    while (res2.next()) {
                        list.add(res2.getString("buildName"));
                    }
                } catch (SQLException ex) {
                    Logger.getLogger(ZCorpDialog.class.getName()).log(Level.SEVERE, null, ex);
                }
                Iterator itr = list.iterator();
                //Date date = Calendar.getInstance().getTime();
                //SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");
                while (itr.hasNext()) {
                    ResultSet res3 = ZCorpMain.dba.searchPendingByBuildName(itr.next().toString());
                    if (res3.next()) {
                        System.out.println("Now doing this shiz");
                        String ID = res3.getString("idJobs");
                        System.out.println(ID);
                        String Printer = res3.getString("printer");
                        String firstName = res3.getString("firstName");
                        String lastName = res3.getString("lastName");
                        String course = res3.getString("course");
                        String section = res3.getString("section");
                        String fileName = res3.getString("fileName");
                        System.out.println(fileName);

                        File newDir = new File(ZCorpMain.getInstance().getZcorpPrinted());
                        FileUtils.moveFileToDirectory(
                                new File(ZCorpMain.getInstance().getZcorpToPrint() + fileName), newDir, true);

                        String filePath = newDir.getAbsolutePath().replace("\\", "\\\\"); //Needs to be changed
                        String dateStarted = res3.getString("dateStarted");
                        String Status = "completed";
                        String Email = res3.getString("Email");
                        String Comment = res3.getString("comment");
                        String nameOfBuild = res3.getString("buildName");
                        double volume = Double.parseDouble(res3.getString("volume"));
                        double cost = Double.parseDouble(res3.getString("cost"));

                        ZCorpMain.dba.insertIntoCompletedJobs(ID, Printer, firstName, lastName, course, section,
                                fileName, filePath, dateStarted, Status, Email, Comment, nameOfBuild, volume,
                                cost);
                        ZCorpMain.dba.delete("pendingjobs", ID);
                        //In Open Builds, it should go back and change status to complete so it doesn't show up again if submitted
                    }
                }

                // if there is no matching record
                ZCorpMain.dba.insertIntoZcorp(buildName, monoBinder, yellowBinder, magentaBuilder, cyanBuilder,
                        cubicInches, modelAmount, comments, buildCost, "complete");
            } catch (IOException ex) {
                Logger.getLogger(ZCorpDialog.class.getName()).log(Level.SEVERE, null, ex);
            } catch (SQLException ex) {
                Logger.getLogger(ZCorpDialog.class.getName()).log(Level.SEVERE, null, ex);
            }

            dispose();
        } else {
            System.out.println("ERRORS");
            JOptionPane.showMessageDialog(null,
                    "There were errors that prevented your build information from being submitted to the database. \nPlease consult the red error text on screen.");
        }
    }
}

From source file:jp.or.openid.eiwg.scim.operation.Operation.java

/**
 * /*from ww  w. ja va  2  s  .  c o  m*/
 *
 * @param context
 * @param request
 * @param targetId
 * @param attributes
 * @param filter
 * @param sortBy
 * @param sortOrder
 * @param startIndex
 * @param count
 */
public ArrayList<LinkedHashMap<String, Object>> searchUserInfo(ServletContext context,
        HttpServletRequest request, String targetId, String attributes, String filter, String sortBy,
        String sortOrder, String startIndex, String count) {
    ArrayList<LinkedHashMap<String, Object>> result = null;

    Set<String> returnAttributeNameSet = new HashSet<>();

    // ?
    setError(0, null, null);

    // ??
    if (attributes != null && !attributes.isEmpty()) {
        // 
        String[] tempList = attributes.split(",");
        for (int i = 0; i < tempList.length; i++) {
            String attributeName = tempList[i].trim();
            // ???????
            LinkedHashMap<String, Object> attributeSchema = SCIMUtil.getUserAttributeInfo(context,
                    attributeName, true);
            if (attributeSchema != null && !attributeSchema.isEmpty()) {
                returnAttributeNameSet.add(attributeName);
            } else {
                // ???????
                String message = String.format(MessageConstants.ERROR_INVALID_ATTRIBUTES, attributeName);
                setError(HttpServletResponse.SC_BAD_REQUEST, null, message);
                return result;
            }
        }
    }

    // ????????
    // (sortBy)?
    // (sortOrder)?
    // ?(startIndex)?
    // 1??(count)?
    //
    // ()

    // 
    result = new ArrayList<LinkedHashMap<String, Object>>();

    // ?
    @SuppressWarnings("unchecked")
    ArrayList<LinkedHashMap<String, Object>> users = (ArrayList<LinkedHashMap<String, Object>>) context
            .getAttribute("Users");
    if (users != null && !users.isEmpty()) {
        Iterator<LinkedHashMap<String, Object>> usersIt = users.iterator();
        while (usersIt.hasNext()) {
            boolean isMatched = false;
            LinkedHashMap<String, Object> userInfo = usersIt.next();

            // id???????
            if (targetId != null && !targetId.isEmpty()) {
                Object id = SCIMUtil.getAttribute(userInfo, "id");
                if (id != null && id instanceof String) {
                    // id????
                    if (targetId.equals(id.toString())) {
                        if (filter != null && !filter.isEmpty()) {
                            // ????
                            boolean matched = false;
                            try {
                                matched = SCIMUtil.checkUserSimpleFilter(context, userInfo, filter);
                            } catch (SCIMUtilException e) {
                                result = null;
                                setError(e.getCode(), e.getType(), e.getMessage());
                                break;
                            }

                            if (matched) {
                                isMatched = true;
                            }
                        } else {
                            isMatched = true;
                        }
                    }
                }
            } else {
                if (filter != null && !filter.isEmpty()) {
                    // ????
                    boolean matched = false;
                    try {
                        matched = SCIMUtil.checkUserSimpleFilter(context, userInfo, filter);
                    } catch (SCIMUtilException e) {
                        result = null;
                        setError(e.getCode(), e.getType(), e.getMessage());
                        break;
                    }

                    if (matched) {
                        isMatched = true;
                    }
                } else {
                    isMatched = true;
                }
            }

            if (isMatched) {
                // ??
                LinkedHashMap<String, Object> resultInfo = new LinkedHashMap<String, Object>();
                Iterator<String> attributeIt = userInfo.keySet().iterator();
                while (attributeIt.hasNext()) {
                    // ???
                    String attributeName = attributeIt.next();

                    // ?
                    LinkedHashMap<String, Object> attributeSchema = SCIMUtil.getUserAttributeInfo(context,
                            attributeName, true);
                    Object returned = attributeSchema.get("returned");

                    if (returned != null && returned.toString().equalsIgnoreCase("never")) {
                        continue;
                    }

                    // ?
                    Object attributeValue = userInfo.get(attributeName);

                    resultInfo.put(attributeName, attributeValue);
                }

                result.add(resultInfo);
            }
        }
    }

    return result;
}

From source file:de.dfki.madm.anomalydetection.evaluator.cluster_based.CMGOSEvaluator.java

public CovarianceMatrix Cstep(CovarianceMatrix covMat, double[][] data, int[] indexArray, int h) {
    HashMap<Double, LinkedList<Integer>> map = new HashMap<Double, LinkedList<Integer>>();
    double[][] newMat = new double[h][];
    Matrix mh = new Matrix(covMat.getCovMat());

    if (mh.det() == 0) {
        covMat.addMinimum();//  w  w  w  .  j a va 2s . c om
        mh = new Matrix(covMat.getCovMat());
    }

    mh = mh.inverse();

    // Compute the distances d_old(i) for i = 1, ... , n.
    for (int index = 0; index < indexArray.length; index++) {
        double d = this.mahalanobisDistance(data[indexArray[index]], mh);
        if (map.containsKey(d)) {
            LinkedList<Integer> hilf = map.get(d);
            hilf.push(index);
            map.put(d, hilf);
        } else {
            LinkedList<Integer> hilf = new LinkedList<Integer>();
            hilf.push(index);
            map.put(d, hilf);
        }
    }
    // Sort these distances
    ArrayList<Double> sortedList = new ArrayList<Double>();
    sortedList.addAll(map.keySet());
    Collections.sort(sortedList);

    // take the h smallest
    int count = 0;
    Iterator<Double> iter = sortedList.iterator();
    while (iter.hasNext()) {
        Double key = iter.next();
        for (Integer i : map.get(key)) {
            newMat[count] = data[indexArray[i]];
            count++;
            if (count >= h)
                break;
        }
        if (count >= h)
            break;
    }

    return new CovarianceMatrix(newMat, this.numberOfThreads);
}

From source file:com.clustercontrol.ws.agent.AgentEndpoint.java

/**
 * [Update] ???MD5????????//  w  ww.j a v a 2s  .  c o  m
 *
 * HinemosAgentAccess???
 *
 * TODO
 * ArrayList<String>??????HashMap<String, String>????
 * ?
 *
 * @param filenameMd5
 * @param agentInto
 * @throws HinemosUnknown
 * @throws InvalidRole
 * @throws InvalidUserPass
 */
public void setAgentLibMd5(ArrayList<String> filenameMd5, AgentInfo agentInfo)
        throws InvalidUserPass, InvalidRole, HinemosUnknown {
    ArrayList<SystemPrivilegeInfo> systemPrivilegeList = new ArrayList<SystemPrivilegeInfo>();
    systemPrivilegeList
            .add(new SystemPrivilegeInfo(FunctionConstant.HINEMOS_AGENT, SystemPrivilegeMode.MODIFY));
    HttpAuthenticator.authCheck(wsctx, systemPrivilegeList);

    HashMap<String, String> map = new HashMap<String, String>();
    Iterator<String> itr = filenameMd5.iterator();
    while (itr.hasNext()) {
        map.put(itr.next(), itr.next());
    }

    ArrayList<String> facilityIdList = getFacilityId(agentInfo);
    for (String facilityId : facilityIdList) {
        m_log.debug("setAgentLibMd5() : facilityId=" + facilityId);
        AgentConnectUtil.setAngetLibMd5(facilityId, map);
    }
}

From source file:com.ct.speech.HintReceiver.java

private void speechResults(int requestCode, ArrayList<String> matches) {
    String emmaBoilerplate = "<emma:emma xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:emma='http://www.w3.org/2003/04/emma' xsi:schemaLocation='http://www.w3.org/2003/04/emma http://www.w3.org/TR/2007/CR-emma-20071211/emma.xsd' version='1.0'>";
    StringBuilder sb = new StringBuilder();
    sb.append(emmaBoilerplate);/*from  w  w w.j  av a  2s . c om*/
    String startString = "emma:start=\"" + speechStart + "\"";
    String endString = "emma:end=" + "\"" + speechEnd + "\"";
    sb.append("<emma:one-of id=" + "\"" + "request" + requestCode
            + "\" emma:medium='acoustic' emma:mode='voice' emma:process=\"googleASR\"" + " " + startString + " "
            + endString + ">");
    Iterator<String> iterator = matches.iterator();
    int matchCounter = 0;
    while (iterator.hasNext()) {
        matchCounter++;
        String match = iterator.next();
        String id = "id= \"result" + matchCounter + "\"";
        String tokenIntro = " emma:tokens=";
        String confidenceString = " emma:confidence=\"0.0\"";
        sb.append("<emma:interpretation " + id + tokenIntro + "\"" + match + "\"" + confidenceString + ">");
        sb.append("<emma:literal>" + match + "</emma:literal></emma:interpretation>");
    }
    sb.append("</emma:one-of>");
    sb.append("</emma:emma>");
    String finalEmma = sb.toString();
    PluginResult result = new PluginResult(PluginResult.Status.OK, finalEmma);
    result.setKeepCallback(false);
    this.success(result, this.callbackId);
    this.callbackId = "";
}

From source file:net.sf.ufsc.ServiceLoader.java

private Iterator<String> parse(Class<?> service, URL u) throws ServiceConfigurationError {
    InputStream in = null;//from  ww w .  ja v a2 s .  c o  m
    BufferedReader r = null;
    ArrayList<String> names = new ArrayList<String>();
    try {
        in = u.openStream();
        r = new BufferedReader(new InputStreamReader(in, "utf-8"));
        int lc = 1;
        while ((lc = parseLine(service, u, r, lc, names)) >= 0)
            ;
    } catch (IOException x) {
        fail(service, "Error reading configuration file", x);
    } finally {
        try {
            if (r != null)
                r.close();
            if (in != null)
                in.close();
        } catch (IOException y) {
            fail(service, "Error closing configuration file", y);
        }
    }
    return names.iterator();
}

From source file:com.peter.mavenrunner.MavenRunnerTopComponent.java

private void deleteGoalMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deleteGoalMenuItemActionPerformed
    TreePath path = projectTree.getSelectionPath();
    if (path == null) {
        return;//from   w w w. j  a  v  a2 s . c  o  m
    }
    MyTreeNode node = (MyTreeNode) ((MyTreeNode) path.getLastPathComponent());
    if (node.type.equals("goal") || isDebug) {
        MyTreeNode parentNode = (MyTreeNode) node.getParent();
        parentNode.remove(node);
        projectTree.updateUI();

        String key = node.projectInformation.getDisplayName();
        ArrayList<PersistData> list = data.get(key);
        if (list == null) {
            list = new ArrayList<PersistData>();
            data.put(key, list);
        }
        log("before delete " + list.size() + ", key=" + key);
        try {
            Iterator i = list.iterator();
            while (i.hasNext()) {
                PersistData p = (PersistData) i.next();
                if (p.name.equals(node.name)) {
                    list.remove(p);
                }
            }
        } catch (Exception ex) {
            log(ExceptionUtils.getStackTrace(ex));
        }
        log("after delete " + list.size());
        NbPreferences.forModule(this.getClass()).put("data", toString(data));
    }
}

From source file:com.peter.mavenrunner.MavenRunnerTopComponent.java

private void editGoalMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_editGoalMenuItemActionPerformed
    TreePath path = projectTree.getSelectionPath();
    if (path == null) {
        return;/* w  w w  . ja v  a 2 s .c  om*/
    }
    MyTreeNode node = (MyTreeNode) ((MyTreeNode) path.getLastPathComponent());
    if (node.type.equals("goal")) {
        MavenGoalDialog dialog = new MavenGoalDialog(null, true);
        dialog.setTitle("Edit goals");
        dialog.setLocationRelativeTo(addGoalMenuItem);
        dialog.nameTextField.setText(node.name);
        dialog.goalsTextField.setText(node.goals);
        dialog.profileTextField.setText(node.profile);
        dialog.propertiesTextArea.setText(StringUtils.join(node.properties, "\n"));
        dialog.skipTestsCheckBox.setSelected(node.skipTests);
        dialog.setVisible(true);

        if (!dialog.isCancel) {
            String name = dialog.nameTextField.getText();
            if (name.trim().equals("")) {
                return;
            }
            String key = node.projectInformation.getDisplayName();
            ArrayList<PersistData> list = data.get(key);
            if (list == null) {
                list = new ArrayList<PersistData>();
                data.put(key, list);
            }

            int index = 0;
            Iterator<PersistData> i = list.iterator();
            while (i.hasNext()) {
                PersistData p = i.next();
                if (p.name.equals(node.name)) {
                    break;
                }
                index++;
            }

            String goals = dialog.goalsTextField.getText();
            String profile = dialog.profileTextField.getText();
            List<String> properties = Arrays.asList(dialog.propertiesTextArea.getText().split("\n"));
            boolean skipTests = dialog.skipTestsCheckBox.isSelected();

            log("index=" + index);
            list.remove(index);
            list.add(index, new PersistData(node.type, node.projectInformation.getDisplayName(), name, goals,
                    profile, properties, skipTests));

            node.name = name;
            node.goals = goals;
            node.profile = profile;
            node.properties = properties;
            node.skipTests = skipTests;

            projectTree.updateUI();
            NbPreferences.forModule(this.getClass()).put("data", toString(data));
        }
    }
}

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

private String filterOutDots(String s) throws Exception {
    try {//  ww w  .  j  ava  2s.co m
        String sStageOne = s.replace("h.", "").replace("t.", "").replace("r.", "").replace("q.", "")
                .replace("o.", "");

        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();
    } catch (Exception e) {
        log.error(e);
        log.error(e.getStackTrace());
        throw (e);
    }
}

From source file:analysers.ExportValidated.java

/**
 * Make JSON Object for a lineage//ww  w .j a  v  a 2s .  c  o  m
 * @param a the ancestral cell of the lineage
 * @param nlin the lineage number
 * @return
 */
@SuppressWarnings("unchecked")
private JSONObject makeLineageJSON(Cell a, int nlin) {
    double dt = exp.getFrameInterval();
    JSONArray cs = new JSONArray();
    JSONObject l = new JSONObject();

    l.put("dt", dt);
    // also remember the intensity value type
    l.put("mean_intensities", Prefs.getInt(".TrackApp.FilterValidatedDialog.exportMean", 1));

    ArrayList<Cell> cells = new ArrayList<Cell>();
    HashMap<Integer, String> cellNames = new HashMap<Integer, String>();
    JSONArray divns = new JSONArray();
    cells.add(a);
    getAllDaughters(a, cells, cellNames, null, divns);

    l.put("divisions", divns);

    int cellid = 1;
    HashMap<String, Integer> cellsToCellsInLin = new HashMap<String, Integer>();

    int minframe = -1;
    int maxframe = -1;

    for (Iterator<Cell> i = cells.iterator(); i.hasNext();) {
        Cell cell = (Cell) i.next();

        if (minframe < 0 || cell.getFrame() < minframe) {
            minframe = cell.getFrame();
        }
        int clf = findLastFrame(cell);
        if (maxframe < 0 || clf > maxframe) {
            maxframe = clf;
        }

        cellsToCellsInLin.put("" + cell.getCellID(), new Integer(cellid));
        ++cellid;
    }

    // make lineage time axis (minframe -> maxframe)
    JSONArray lintime = new JSONArray();
    for (int f = minframe; f <= maxframe; ++f) {
        lintime.add(new Double((f - 1) * dt));
    }
    l.put("time", lintime);

    cellid = 1;
    for (Iterator<Cell> i = cells.iterator(); i.hasNext();) {
        Cell cell = (Cell) i.next();
        JSONObject co = makeCellJSON(cell);
        co.put("lineage", new Integer(nlin));

        int parent = 0;
        // parent is first cell back for which we have an id, or 0
        Cell pcell = cell.getPreviousCell();
        Cell ppcell = pcell;
        int f = 0;
        while (pcell != null) {
            int id = pcell.getCellID();
            Integer pi = cellsToCellsInLin.get("" + id);
            if (pi != null) {
                parent = pi.intValue();
                break;
            }
            ppcell = pcell;
            pcell = pcell.getPreviousCell();
            if (f++ > maxframe) {
                IJ.log("Failed to find parent for cell " + cell.getCellID());
                break;
            }
        }
        if (cellid != 1 && parent == 0) {
            IJ.log("Error: parent is null within lineage!" + ppcell.toString());
        }

        co.put("parent", new Integer(parent));
        co.put("parent_in_lineage", new Integer(parent));

        co.put("lineage_id", new Integer(cellid));
        co.put("name", cellNames.get(cell.getCellID()));

        cs.add(co);
        ++cellid;
    }

    JSONObject o = new JSONObject();
    o.put("lin", l);
    o.put("cells", cs);

    return o;
}