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:com.polyvi.xface.extension.messaging.XMessagingExt.java

/**
 * PendingIntent/*  w ww  .j  ava2s  . c  om*/
 *
 * @param textList
 *            
 * @return ??pendingIntent
 * */
private ArrayList<PendingIntent> genSMSPendingIntentList(ArrayList<String> textList) {
    Intent smsSendIntent = new Intent(SMS_SENT);

    int count = (null == textList) ? 0 : textList.size();
    ArrayList<PendingIntent> smsSendPendingIntentList = new ArrayList<PendingIntent>(count);

    Iterator<String> itor = textList.iterator();
    while (itor.hasNext()) {
        smsSendPendingIntentList.add(PendingIntent.getBroadcast(mContext, 0, smsSendIntent, 0));
        itor.next();
    }
    return smsSendPendingIntentList;
}

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

@Override
public ApiResponse isOrderActive(String id) {
    ApiResponse apiResponse = new ApiResponse();

    ApiResponse getOrders = getActiveOrders();
    if (getOrders.isPositive()) {
        apiResponse.setResponseObject(false);
        ArrayList<Order> orderList = (ArrayList) getOrders.getResponseObject();
        for (Iterator<Order> order = orderList.iterator(); order.hasNext();) {
            Order thisOrder = order.next();
            if (thisOrder.getId().equals(id)) {
                apiResponse.setResponseObject(!thisOrder.isCompleted());
            }//  w  ww. ja  v a2s  .  c om
        }
    } else {
        apiResponse = getOrders;
    }

    return apiResponse;
}

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

@Override
public ApiResponse clearOrders(CurrencyPair pair) {
    ApiResponse apiResponse = new ApiResponse();

    ApiResponse getOrders = getActiveOrders(pair);
    if (getOrders.isPositive()) {
        apiResponse.setResponseObject(true);
        ArrayList<Order> orderList = (ArrayList) getOrders.getResponseObject();
        for (Iterator<Order> order = orderList.iterator(); order.hasNext();) {
            Order thisOrder = order.next();
            ApiResponse cancel = cancelOrder(thisOrder.getId(), thisOrder.getPair());
            if (!cancel.isPositive()) {
                apiResponse.setResponseObject(false);
            }/*  w  ww.  j  av  a  2  s  .  co m*/
        }
    } else {
        apiResponse = getOrders;
    }

    return apiResponse;
}

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

@Override
public ApiResponse getOrderDetail(String orderID) {
    ApiResponse apiResponse = new ApiResponse();
    ApiResponse getOrders = getActiveOrders();
    boolean found = false;

    if (getOrders.isPositive()) {
        ArrayList<Order> orderList = (ArrayList) getOrders.getResponseObject();
        for (Iterator<Order> order = orderList.iterator(); order.hasNext();) {
            Order thisOrder = order.next();
            if (thisOrder.getId().equals(orderID)) {
                apiResponse.setResponseObject(thisOrder);
                found = true;/*  w ww  .j av a 2 s .  c om*/
                break;
            }
        }
    } else {
        return getOrders;
    }
    if (!found) {
        String message = "The order " + orderID + " does not exist";
        ApiError err = errors.apiReturnError;
        err.setDescription(message);
        apiResponse.setError(err);
    }

    return apiResponse;
}

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

@Override
public ApiResponse isOrderActive(String id) {
    ApiResponse apiRespone = new ApiResponse();
    ApiResponse activeOrders = getActiveOrders();
    if (activeOrders.isPositive()) {
        ArrayList<Order> orderList = (ArrayList) activeOrders.getResponseObject();
        apiRespone.setResponseObject(false);
        for (Iterator<Order> order = orderList.iterator(); order.hasNext();) {
            Order thisOrder = order.next();
            if (thisOrder.getId().equals(id)) {
                apiRespone.setResponseObject(true);
            }//  w  ww.  j a  v  a 2 s  .  com
        }
    } else {
        apiRespone = activeOrders;
    }
    return apiRespone;
}

From source file:info.ajaxplorer.client.model.Node.java

public int deleteProperty(String name, RuntimeExceptionDao<Property, Integer> propDao) {
    if (properties == null)
        return 0;
    int count = 0;
    try {/*from  w ww.jav a 2s . c  om*/
        ArrayList<Property> removed = new ArrayList<Property>();
        CloseableIterator<Property> it = properties.closeableIterator();
        while (it.hasNext()) {
            Property current = it.next();
            if (current.getName().equals(name)) {
                propDao.delete(current);
                removed.add(current);
                count++;
            }
        }
        it.close();
        Iterator<Property> i = removed.iterator();
        while (i.hasNext())
            properties.remove(i.next());
    } catch (SQLException e) {
        e.printStackTrace();
    }
    return count;
}

From source file:msgclient.MsgClient.java

public void getMessages() throws Exception {
    // Call the server to get recent mail
    ArrayList<EncryptedMessage> messages = mServerConnection.lookupMessages();

    if (messages == null) {
        System.out.println("Invalid response from server");
        return;// w ww .j  a v a 2  s .  c o  m
    }

    // Decrypt and process each message
    if (messages == null || messages.isEmpty()) {
        //System.out.println("No new messages.");
    } else {
        Iterator<EncryptedMessage> iterator = messages.iterator();
        while (iterator.hasNext()) {
            EncryptedMessage nextMessage = iterator.next();

            //System.out.println("Received an encrypted message");

            // We need to get the sender's public key
            MsgKeyPair senderKey = mServerConnection.lookupKey(nextMessage.getSenderID());
            if (senderKey != null) {
                String decryptedText = mEncryptor.decryptMessage(nextMessage.getMessageText(),
                        nextMessage.getSenderID(), senderKey);

                if (decryptedText != null) {
                    if (isReadReceipt(decryptedText) == false) {
                        // Add the decrypted message to our pending messages list
                        Message newMessage = new Message(nextMessage.getSenderID(), nextMessage.getReceiverID(),
                                decryptedText, nextMessage.getSentTime(), nextMessage.getMessageID());

                        // Make sure we don't mess with the object thread locks,
                        // since the mPendingMessages member can be accessed by
                        // a different thread.
                        synchronized (mPendingMessages) {
                            mPendingMessages.add(newMessage);
                            //System.out.println("Got a message!");
                        }

                        sendReadReceipt(nextMessage.getSenderID(), nextMessage.getMessageID());
                    }
                }
            } else {
                //System.out.println("Could not get keys for " + nextMessage.getSenderID());
            }
        }

    }
}

From source file:architecture.common.xml.XmlProperties.java

/**
 * Return all values who's path matches the given property name as a String
 * array, or an empty array if the if there are no children. This allows you
 * to retrieve several values with the same property name. For example,
 * consider the XML file entry:/*from ww w  . j  a v a  2  s  . co m*/
 * 
 * <pre>
 * &lt;foo&gt;
 *     &lt;bar&gt;
 *         &lt;prop&gt;some value&lt;/prop&gt;
 *         &lt;prop&gt;other value&lt;/prop&gt;
 *         &lt;prop&gt;last value&lt;/prop&gt;
 *     &lt;/bar&gt;
 * &lt;/foo&gt;
 * </pre>
 * 
 * If you call getProperties("foo.bar.prop") will return a string array
 * containing {"some value", "other value", "last value"}.
 *
 * @param name
 *            the name of the property to retrieve
 * @return all child property values for the given node name.
 */
public Iterator getChildProperties(String name) {
    String[] propName = parsePropertyName(name);
    // Search for this property by traversing down the XML heirarchy,
    // stopping one short.
    Element element = document.getRootElement();
    for (int i = 0; i < propName.length - 1; i++) {
        element = element.element(propName[i]);
        if (element == null) {
            // This node doesn't match this part of the property name which
            // indicates this property doesn't exist so return empty array.
            return Collections.EMPTY_LIST.iterator();
        }
    }
    // We found matching property, return values of the children.
    Iterator iter = element.elementIterator(propName[propName.length - 1]);
    ArrayList<String> props = new ArrayList<String>();
    while (iter.hasNext()) {
        props.add(((Element) iter.next()).getText());
    }
    return props.iterator();
}

From source file:com.massabot.codesender.GrblController.java

@Override
public void returnToHome() throws Exception {
    if (this.isCommOpen()) {
        // Not using max for now, it was causing issue for many people.
        double max = 0;
        if (this.maxZLocationMM != -1) {
            max = this.maxZLocationMM;
        }/*from   w  ww . ja  va2  s. c  om*/
        ArrayList<String> commands = GrblUtils.getReturnToHomeCommands(this.grblVersion, this.grblVersionLetter,
                this.workLocation.z);
        if (!commands.isEmpty()) {
            Iterator<String> iter = commands.iterator();
            // Perform the homing commands
            while (iter.hasNext()) {
                String gcode = iter.next();
                GcodeCommand command = createCommand(gcode);
                this.sendCommandImmediately(command);
            }
            return;
        }

        restoreParserModalState();
    }
    // Throw exception
    super.returnToHome();
}

From source file:javaapplication3.SolidscapeDialog.java

private void submitBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_submitBtnActionPerformed
    if (validateForm()) {
        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());
        String comments = comment.getText();
        //hideErrorFields();            

        //now dealing with buildCost
        try {//ww  w. ja  va  2s.co  m
            Integer d = Integer.parseInt(days.getSelectedItem().toString());
            Integer h = Integer.parseInt(hours.getSelectedItem().toString());
            Integer m = Integer.parseInt(minutes.getSelectedItem().toString());
            buildTime = d + ":" + h + ":" + m;
            buildCost = Calculations.SolidscapeCost(d, h, m);
        } catch (Exception e) {
            errFree = true;
            e.printStackTrace();
        }
        //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
                SolidscapeMain.calc.BuildtoProjectCost(buildName, "Solidscape", buildCost);

                ResultSet res2 = SolidscapeMain.dba.searchPendingByBuildName(buildName);
                ArrayList list = new ArrayList();
                try {
                    while (res2.next()) {
                        list.add(res2.getString("buildName"));
                    }
                } catch (SQLException ex) {
                }

                Iterator itr = list.iterator();
                //Date date = Calendar.getInstance().getTime();
                //SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");
                while (itr.hasNext()) {
                    ResultSet res3 = SolidscapeMain.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(SolidscapeMain.getInstance().getSolidscapePrinted());
                        FileUtils.moveFileToDirectory(
                                new File(SolidscapeMain.getInstance().getSolidscapeToPrint() + 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"));

                        SolidscapeMain.dba.insertIntoCompletedJobs(ID, Printer, firstName, lastName, course,
                                section, fileName, filePath, dateStarted, Status, Email, Comment, nameOfBuild,
                                volume, cost);
                        SolidscapeMain.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
                SolidscapeMain.dba.insertIntoSolidscape(buildName, modelAmount, ResolutionVar, buildTime,
                        comments, buildCost);
            } catch (IOException ex) {
                Logger.getLogger(SolidscapeDialog.class.getName()).log(Level.SEVERE, null, ex);
            } catch (SQLException ex) {
                Logger.getLogger(SolidscapeDialog.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.");
        }
    }
}