List of usage examples for java.util ArrayList iterator
public Iterator<E> iterator()
From source file:com.parse.ParseRemoveOperation.java
@Override public Object apply(Object oldValue, String key) { if (oldValue == null) { return new ArrayList<>(); } else if (oldValue instanceof JSONArray) { ArrayList<Object> old = ParseFieldOperations.jsonArrayAsArrayList((JSONArray) oldValue); @SuppressWarnings("unchecked") ArrayList<Object> newValue = (ArrayList<Object>) this.apply(old, key); return new JSONArray(newValue); } else if (oldValue instanceof List) { ArrayList<Object> result = new ArrayList<>((List<?>) oldValue); result.removeAll(objects);//from w w w . j a v a 2 s . c o m // Remove the removed objects from "objects" -- the items remaining // should be ones that weren't removed by object equality. ArrayList<Object> objectsToBeRemoved = new ArrayList<>(objects); objectsToBeRemoved.removeAll(result); // Build up set of object IDs for any ParseObjects in the remaining objects-to-be-removed HashSet<String> objectIds = new HashSet<>(); for (Object obj : objectsToBeRemoved) { if (obj instanceof ParseObject) { objectIds.add(((ParseObject) obj).getObjectId()); } } // And iterate over "result" to see if any other ParseObjects need to be removed Iterator<Object> resultIterator = result.iterator(); while (resultIterator.hasNext()) { Object obj = resultIterator.next(); if (obj instanceof ParseObject && objectIds.contains(((ParseObject) obj).getObjectId())) { resultIterator.remove(); } } return result; } else { throw new IllegalArgumentException("Operation is invalid after previous operation."); } }
From source file:com.nubits.nubot.trading.wrappers.AllCoinWrapper.java
@Override public ApiResponse isOrderActive(String id) { ApiResponse apiResponse = new ApiResponse(); ApiResponse activeOrdersResponse = getActiveOrders(); apiResponse.setResponseObject(false); if (activeOrdersResponse.isPositive()) { ArrayList<Order> orderList = (ArrayList<Order>) activeOrdersResponse.getResponseObject(); for (Iterator<Order> order = orderList.iterator(); order.hasNext();) { Order thisOrder = order.next(); if (thisOrder.getId().equals(id)) { apiResponse.setResponseObject(true); }/*from ww w .j a v a 2 s . com*/ } } return apiResponse; }
From source file:de.ifsr.adam.ImageGenerator.java
/** * Puts the charts in chartList into GridPanes as specified by chartsPerColumn and chartsPerRow. * * @param chartList The ArrayList with the charts. * @param chartsPerColumn Number of charts that are in one column. * @param chartsPerRow Number of charts that are in one row. * @return The list of GridPanes that were generated. *//*from w ww .ja v a2 s. com*/ private ArrayList<GridPane> makeLayout(ArrayList<Chart> chartList, Integer chartsPerColumn, Integer chartsPerRow) { ArrayList<GridPane> gridPaneList = new ArrayList<>(); GridPane gridPane = new GridPane(); int rowIndex = 0, columnIndex = 0; Iterator<Chart> iter = chartList.iterator(); //int i = 0;//TODO: Remove while (iter.hasNext()) { //System.out.println("Run: "+ i + " columnIndex: " + columnIndex + " rowIndex: " + rowIndex);//TODO: Remove //i++;//TODO: Remove Chart chart = iter.next(); calculateChartSize(chart, chartsPerColumn, chartsPerRow); gridPane.add(chart, columnIndex, rowIndex); columnIndex++; //Case: Row is full go to next row if (columnIndex >= chartsPerRow) { columnIndex = 0; rowIndex++; } //Case: Page is full start a new GridPane if (rowIndex >= chartsPerColumn) { //The Layout for the gridPane gridPane.setHgap(imageWidth * 0.10); gridPane.setAlignment(Pos.CENTER); gridPane.setPrefWidth(imageWidth); gridPane.setPrefHeight(imageHeight); gridPaneList.add(gridPane); gridPane = new GridPane(); rowIndex = 0; } } //This needs to be check, or the last page can be empty if (rowIndex != 0 || columnIndex != 0) { gridPaneList.add(gridPane); } return gridPaneList; }
From source file:javaapplication3.ObjetDialog.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()); String comments = comment.getText(); //hideErrorFields(); //now dealing with buildCost try {/* w w w . j av a2s. c om*/ buildCost = (double) Calculations.ObjetCost(BuildConsumed, material.getSelectedItem().toString()); } 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 ObjetMain.calc.BuildtoProjectCost(buildName, "Objet", buildCost); ResultSet res2 = ObjetMain.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 = ObjetMain.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(ObjetMain.getInstance().getObjetPrinted()); FileUtils.moveFileToDirectory( new File(ObjetMain.getInstance().getObjetToPrint() + 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")); ObjetMain.dba.insertIntoCompletedJobs(ID, Printer, firstName, lastName, course, section, fileName, filePath, dateStarted, Status, Email, Comment, nameOfBuild, volume, cost); ObjetMain.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 ObjetMain.dba.insertIntoObjet(buildName, BuildConsumed, SupportConsumed, modelAmount, materialType, Resolution, comments, buildCost); } catch (IOException ex) { Logger.getLogger(ObjetDialog.class.getName()).log(Level.SEVERE, null, ex); } catch (SQLException ex) { Logger.getLogger(ObjetDialog.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:com.willwinder.universalgcodesender.GrblController.java
@Override public void returnToHome() throws Exception { if (this.isCommOpen()) { ArrayList<String> commands = GrblUtils.getReturnToHomeCommands(this.grblVersion, this.grblVersionLetter, this.controllerStatus.getWorkCoord().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); }// w w w . j a v a 2s. c o m return; } restoreParserModalState(); } // Throw exception super.returnToHome(); }
From source file:gr.iit.demokritos.cru.cps.api.CreateGroup.java
public JSONObject processRequest() throws IOException, Exception { String response_code = "e0"; long user_id = 0; String[] users = users_list.split(";"); ArrayList<Long> users_id = new ArrayList<Long>(); for (int i = 0; i < users.length; i++) { users_id.add(Long.parseLong(users[i])); }//from w w w. ja va 2s . co m // String filename = "/WEB-INF/configuration.properties"; String location = (String) properties.get("location"); String database_name = (String) properties.get("database_name"); String username = (String) properties.get("username"); String password = (String) properties.get("password"); MySQLConnector mysql = new MySQLConnector(location, database_name, username, password); try { UserManager um = new UserManager(Long.parseLong(application_key), users_id); boolean isvalid = false; isvalid = um.validateClientApplication(mysql); if (isvalid == true) { Iterator it = users_id.iterator(); while (it.hasNext()) { um.setUser_id((Long) it.next()); isvalid = um.validateUser(mysql); if (isvalid == false) { break; } } if (isvalid == true) { um.setUser_id(user_id); um.createGroup(mysql); user_id = um.getUser_id(); response_code = "OK"; } else { response_code = "e102"; } } else { response_code = "e101"; } } catch (NumberFormatException ex) { response_code = "e101"; Logger.getLogger(CreateUser.class.getName()).log(Level.SEVERE, null, ex); } JSONArray list = new JSONArray(); for (Long temp_user : users_id) { list.add(Long.toString(temp_user)); } JSONObject obj = new JSONObject(); obj.put("application_key", application_key); obj.put("group_id", Long.toString(user_id)); obj.put("users_id", list); obj.put("response_code", response_code); return obj; }
From source file:es.caib.zkib.jxpath.ri.JXPathContextReferenceImpl.java
/** * Remove all matching nodes./*from w w w . j a va 2s . c o m*/ * @param xpath expression * @param expr compiled Expression */ public void removeAll(String xpath, Expression expr) { try { ArrayList list = new ArrayList(); Iterator it = expr.iteratePointers(getEvalContext()); while (it.hasNext()) { list.add(it.next()); } Collections.sort(list, ReverseComparator.INSTANCE); it = list.iterator(); if (it.hasNext()) { NodePointer pointer = (NodePointer) it.next(); pointer.remove(); while (it.hasNext()) { removePath(((NodePointer) it.next()).asPath()); } } } catch (Throwable ex) { throw new JXPathException("Exception trying to remove all for xpath " + xpath, ex); } }
From source file:gr.iit.demokritos.cru.cps.api.DestroyGroup.java
public JSONObject processRequest() throws IOException, Exception { String response_code = "e0"; long user_id = 0; String[] groups = group_list.split(";"); ArrayList<Long> groups_id = new ArrayList<Long>(); for (int i = 0; i < groups.length; i++) { groups_id.add(Long.parseLong(groups[i])); }//from www . j av a 2 s . c om // String filename = "/WEB-INF/configuration.properties"; String location = (String) properties.get("location"); String database_name = (String) properties.get("database_name"); String username = (String) properties.get("username"); String password = (String) properties.get("password"); MySQLConnector mysql = new MySQLConnector(location, database_name, username, password); try { UserManager um = new UserManager(Long.parseLong(application_key), groups_id); boolean isvalid = false; isvalid = um.validateClientApplication(mysql); if (isvalid == true) { Iterator it = groups_id.iterator(); while (it.hasNext()) { um.setUser_id((Long) it.next()); isvalid = um.validateUser(mysql); if (isvalid == false) { break; } } if (isvalid == true) { um.setUser_id(user_id); um.createGroup(mysql); user_id = um.getUser_id(); response_code = "OK"; } else { response_code = "e102"; } } else { response_code = "e101"; } } catch (NumberFormatException ex) { response_code = "e101"; Logger.getLogger(CreateUser.class.getName()).log(Level.SEVERE, null, ex); } JSONArray list = new JSONArray(); for (Long temp_user : groups_id) { list.add(Long.toString(temp_user)); } JSONObject obj = new JSONObject(); obj.put("application_key", application_key); obj.put("group_id", Long.toString(user_id)); obj.put("users_id", list); obj.put("response_code", response_code); return obj; }
From source file:com.nubits.nubot.trading.wrappers.CcedkWrapper.java
@Override public ApiResponse isOrderActive(String orderID) { ApiResponse apiResponse = new ApiResponse(); ApiResponse getActiveOrders = getActiveOrders(); if (getActiveOrders.isPositive()) { ArrayList<Order> orderList = (ArrayList) getActiveOrders.getResponseObject(); apiResponse.setResponseObject(false); for (Iterator<Order> order = orderList.iterator(); order.hasNext();) { Order thisOrder = order.next(); if (thisOrder.getId().equals(orderID)) { apiResponse.setResponseObject(true); }/*from w w w . j av a 2 s .com*/ } } else { apiResponse = getActiveOrders; } return apiResponse; }
From source file:com.icesoft.applications.faces.address.MatchAddressDB.java
/** * Finds the closest cities to the provided city. * * @param checkCity the city to check/*from w w w .ja va2s . c o m*/ * @return list of cities */ public ArrayList getClosestCity(String checkCity) { String myCheckCity = AddressFormProcessor.fixCapitalization(checkCity); ArrayList cities = getCity(myCheckCity); if (cities != null) { //at least one exact match, so exit return cities; } //get closest city in each state Iterator itor = stateMap.values().iterator(); TreeMap closest = new TreeMap(); MatchCity city; while (itor.hasNext()) { MatchState state = (MatchState) itor.next(); city = state.getClosestCity(myCheckCity); closest.put((city.getCity()), city); } //get closest of the closest cities city = (MatchCity) getClosestMatch(myCheckCity, closest); //must return all cities with this name cities = getCity(city.getCity()); itor = cities.iterator(); while (itor.hasNext()) { ((MatchCity) itor.next()).setMatch(false); } return cities; }