List of usage examples for java.util ArrayList iterator
public Iterator<E> iterator()
From source file:com.nubits.nubot.trading.wrappers.AltsTradeWrapper.java
private ApiResponse enterOrder(String type, CurrencyPair pair, double amount, double rate) { ApiResponse apiResponse = new ApiResponse(); String url = API_BASE_URL + "/" + API_ORDERS; HashMap<String, String> args = new HashMap<>(); boolean isGet = false; args.put("amount", Objects.toString(amount)); args.put("market", pair.toStringSepSpecial("/").toUpperCase()); args.put("price", Objects.toString(rate)); args.put("action", type); ApiResponse response = getQuery(url, args, true, isGet); if (response.isPositive()) { ApiResponse getOpenOrders = getActiveOrders(pair); if (getOpenOrders.isPositive()) { ArrayList<Order> orders = (ArrayList) getOpenOrders.getResponseObject(); Date checkDate = null; String order_id = null; for (Iterator<Order> order = orders.iterator(); order.hasNext();) { Order thisOrder = order.next(); if (checkDate == null || thisOrder.getInsertedDate().getTime() > checkDate.getTime()) { checkDate = thisOrder.getInsertedDate(); order_id = thisOrder.getId(); }/* ww w .j av a2 s . c o m*/ } apiResponse.setResponseObject(order_id); } else { apiResponse = getOpenOrders; } } else { apiResponse = response; } return apiResponse; }
From source file:ca.sfu.federation.model.ParametricModel.java
/** * Update the state of the context./*from w w w . j a v a 2s .com*/ * @return True if updated successfully, false otherwise. */ public boolean update() { ArrayList<INamed> elementsInOrder = null; try { elementsInOrder = getElementsInTopologicalOrder(); } catch (GraphCycleException ex) { String stack = ExceptionUtils.getFullStackTrace(ex); logger.log(Level.WARNING, "{0}", stack); } // print out the update order for debugging IContextUtils.logUpdateOrder(this, elementsInOrder); // update nodes boolean success = false; if (elementsInOrder != null) { Iterator e = elementsInOrder.iterator(); while (e.hasNext() && success) { Object object = e.next(); if (object instanceof IUpdateable) { IUpdateable updateable = (IUpdateable) object; success = updateable.update(); } } } // if update was successful, notify all observers if (success) { this.setChanged(); this.notifyObservers(); } // return result return success; }
From source file:edu.umd.cfar.lamp.viper.geometry.BoundingBox.java
/** * The getPolys iterator returns a set of non-overlapping polygons that, * together, cover the same region as this set of boxes. * /* w w w . jav a 2s. c o m*/ * @return a set of convex polygons that tile this region */ public Iterator getPolys() { if (composed) { return pieces.iterator(); } else { ArrayList temp = new ArrayList(1); temp.add(this); return temp.iterator(); } }
From source file:net.lightbody.bmp.proxy.jetty.jetty.servlet.AbstractSessionManager.java
public void stop() { // Invalidate all sessions to cause unbind events ArrayList sessions = new ArrayList(_sessions.values()); for (Iterator i = sessions.iterator(); i.hasNext();) { Session session = (Session) i.next(); session.invalidate();/*w w w . j a va 2s . c om*/ } _sessions.clear(); // stop the scavenger SessionScavenger scavenger = _scavenger; _scavenger = null; if (scavenger != null) scavenger.interrupt(); }
From source file:it.cnr.icar.eric.client.ui.swing.BusinessQueryPanel.java
/** * Process a ConceptsTreeDialog.PROPERTY_SELECTED_CONCEPTS change event. *//*from w w w . j a v a 2 s . co m*/ private void processSelectedConceptsChange(PropertyChangeEvent ev) { try { Connection connection = RegistryBrowser.client.getConnection(); RegistryService service = connection.getRegistryService(); LifeCycleManager lcm = service.getBusinessLifeCycleManager(); ArrayList<?> selectedConcepts = (ArrayList<?>) ev.getNewValue(); ArrayList<Classification> classifications = new ArrayList<Classification>(); Iterator<?> iter = selectedConcepts.iterator(); while (iter.hasNext()) { Concept concept = (Concept) iter.next(); Classification classification = lcm.createClassification(concept); classifications.add(classification); } ((ClassificationsListModel) (classificationsList.getModel())).setModels(classifications); } catch (JAXRException e) { RegistryBrowser.displayError(e); } }
From source file:com.nubits.nubot.trading.wrappers.BitcoinCoIDWrapper.java
@Override public ApiResponse getOrderDetail(String orderID) { ApiResponse apiResponse = new ApiResponse(); ApiResponse getActiveOrdersResponse = getActiveOrders(); if (getActiveOrdersResponse.isPositive()) { ArrayList<Order> activeOrders = (ArrayList<Order>) getActiveOrdersResponse.getResponseObject(); boolean found = false; for (Iterator<Order> order = activeOrders.iterator(); order.hasNext();) { Order thisOrder = order.next(); if (thisOrder.getId().equals(orderID)) { found = true;/*ww w.j ava2 s . c om*/ apiResponse.setResponseObject(thisOrder); break; } } if (!found) { ApiError err = errors.apiReturnError; err.setDescription("Order " + orderID + " does not exists"); apiResponse.setError(err); } } else { apiResponse = getActiveOrdersResponse; } return apiResponse; }
From source file:com.cyberway.issue.crawler.extractor.ExtractorPDF.java
protected void extract(CrawlURI curi) { if (!isHttpTransactionContentToProcess(curi) || !isExpectedMimeType(curi.getContentType(), "application/pdf")) { return;//from w w w.ja va2s. co m } numberOfCURIsHandled++; File tempFile; if (curi.getHttpRecorder().getRecordedInput().getSize() > maxSizeToParse) { return; } int sn = ((ToeThread) Thread.currentThread()).getSerialNumber(); tempFile = new File(getController().getScratchDisk(), "tt" + sn + "tmp.pdf"); PDFParser parser; ArrayList uris; try { curi.getHttpRecorder().getRecordedInput().copyContentBodyTo(tempFile); parser = new PDFParser(tempFile.getAbsolutePath()); uris = parser.extractURIs(); } catch (IOException e) { curi.addLocalizedError(getName(), e, "ExtractorPDF IOException"); return; } catch (RuntimeException e) { // Truncated/corrupt PDFs may generate ClassCast exceptions, or // other problems curi.addLocalizedError(getName(), e, "ExtractorPDF RuntimeException"); return; } finally { tempFile.delete(); } if (uris != null && uris.size() > 0) { Iterator iter = uris.iterator(); while (iter.hasNext()) { String uri = (String) iter.next(); try { curi.createAndAddLink(uri, Link.NAVLINK_MISC, Link.NAVLINK_HOP); } catch (URIException e1) { // There may not be a controller (e.g. If we're being run // by the extractor tool). if (getController() != null) { getController().logUriError(e1, curi.getUURI(), uri); } else { LOGGER.info(curi + ", " + uri + ": " + e1.getMessage()); } } } numberOfLinksExtracted += uris.size(); } LOGGER.fine(curi + " has " + uris.size() + " links."); // Set flag to indicate that link extraction is completed. curi.linkExtractorFinished(); }
From source file:com.attentec.AttentecService.java
/** * Fetches contacts from server.// w ww .j av a 2 s . c o m * @return true if successful, false otherwise */ public final boolean getContacts() { //get login data for server contact SharedPreferences sp = getSharedPreferences("attentec_preferences", MODE_PRIVATE); String username = sp.getString("username", ""); Hashtable<String, List<NameValuePair>> postdata = ServerContact.getLogin(username, sp.getString("phone_key", "")); JSONObject js = null; try { js = ServerContact.postJSON(postdata, "/app/contactlist.json", ctx); } catch (LoginException e) { //wrong login, close application endAllActivities(); return false; } if (js == null) { /** * the contact with server failed for one of the following reasons: * * Could not encode the posted data * * HTTP request failed (IOException) * * Could not decode the response */ return false; } //fetch the users object from the response JSONArray users = null; try { users = js.getJSONArray("users"); } catch (JSONException e) { Log.e(TAG, "Error in JSON decode of users array"); return false; } //update all users in database ArrayList<String> updated = new ArrayList<String>(); for (int i = 0; i < users.length(); i++) { JSONObject user; try { user = users.getJSONObject(i).getJSONObject("user"); } catch (JSONException e) { Log.e(TAG, "JSONException on decoding user object"); return false; } String updatedId = null; try { updatedId = parseJSONUser(user, username); } catch (JSONException e) { //Failed to parse a user Log.e(TAG, "Failed to parse a user."); return false; } if (updatedId != null) { updated.add(updatedId); } } //remove all entries in the database that were not updated (people quitting) ArrayList<String> existing = dbh.getUserIds(); Iterator<String> it = existing.iterator(); while (it.hasNext()) { String key = it.next(); if (key != null && !updated.contains(key)) { dbh.deleteUser(Long.parseLong(key)); } } //call callback in main thread to refresh the list if (contactsUIUpdateListener != null) { contactsUIUpdateListener.updateUI(); } return true; }
From source file:com.codesourcery.installer.actions.EnvironmentAction.java
/** * Handles Windows environment variables. * /* w w w .j a v a2s .c om*/ * @param mode Install mode * @param monitor Progress monitor * @throws CoreException on failure */ private void runWindows(IInstallMode mode, IProgressMonitor monitor) throws CoreException { for (EnvironmentVariable environmentVariable : environmentVariables) { String existingValue = null; // Get existing value if ((environmentVariable.getOperation() != EnvironmentOperation.REPLACE)) { try { existingValue = readWindowsEnvironmentVariable(environmentVariable.getName()); } catch (CoreException e) { // Ignore } } StringBuffer valuesBuffer = new StringBuffer(); // Install - prefix, append, or replace exiting value if (mode.isInstall()) { // Prepend or replace variable value if ((environmentVariable.getOperation() == EnvironmentOperation.PREPEND) || (environmentVariable.getOperation() == EnvironmentOperation.REPLACE)) { appendValues(valuesBuffer, environmentVariable.getValue(), environmentVariable.getDelimiter()); } // Add existing variable value if (environmentVariable.getOperation() != EnvironmentOperation.REPLACE) { if (existingValue != null) { if (valuesBuffer.length() > 0) { valuesBuffer.append(environmentVariable.getDelimiter()); } valuesBuffer.append(existingValue); } } // Append variable value if (environmentVariable.getOperation() == EnvironmentOperation.APPEND) { appendValues(valuesBuffer, environmentVariable.getValue(), environmentVariable.getDelimiter()); } // Set new variable value Installer.getDefault().getInstallPlatform().setWindowsRegistryValue(REG_USER_ENVIRONMENT, environmentVariable.getName(), valuesBuffer.toString()); } // Uninstall - remove variable value (prefix,append) or remove variable (replace) else { // Remove values if (existingValue != null) { String[] parts = InstallUtils.getArrayFromString(existingValue, environmentVariable.getDelimiter()); ArrayList<String> existingValues = new ArrayList<String>(Arrays.asList(parts)); String[] removeValues = InstallUtils.getArrayFromString(environmentVariable.getValue(), environmentVariable.getDelimiter()); Iterator<String> iter = existingValues.iterator(); while (iter.hasNext()) { String value = iter.next(); for (String removeValue : removeValues) { if (removeValue.equals(value)) { iter.remove(); break; } } } for (String value : existingValues) { appendValues(valuesBuffer, value, environmentVariable.getDelimiter()); } // Set new variable value Installer.getDefault().getInstallPlatform().setWindowsRegistryValue(REG_USER_ENVIRONMENT, environmentVariable.getName(), valuesBuffer.toString()); } // Remove variable else { Installer.getDefault().getInstallPlatform().deleteWindowsRegistryValue(REG_USER_ENVIRONMENT, environmentVariable.getName()); } } } }
From source file:com.clavain.munin.MuninNode.java
/** * fill insertion queue with current graph values for each plugin *//*from w ww .j a v a 2 s. c o m*/ public void queuePluginFetch(ArrayList<MuninGraph> p_almg, String p_strPluginName, int p_iCustomId) { Iterator<MuninGraph> it = p_almg.iterator(); while (it.hasNext()) { MuninGraph mg = it.next(); // prepare document object BasicDBObject doc = new BasicDBObject(); doc.put("hostname", this.getHostname()); doc.put("plugin", p_strPluginName); doc.put("graph", mg.getGraphName()); doc.put("value", mg.getGraphValue().toString()); doc.put("recv", mg.getLastGraphTime()); doc.put("user_id", this.getUser_id()); doc.put("nodeid", this.getNode_id()); if (p_iCustomId > 0) { doc.put("customId", p_iCustomId); } // only queue if plugin is initialized or it is a if_err plugin if (mg.isInit() || p_strPluginName.startsWith("if_err") || p_strPluginName.equals("swap")) { com.clavain.muninmxcd.mongo_queue.add(doc); mg.setLastQueued(getUnixtime()); logger.debug("Queued: " + this.getHostname() + " (" + p_strPluginName + " / " + mg.getGraphName() + ") Value: " + mg.getGraphValue()); if (logMore) { logger.info("Queued: " + this.getHostname() + " (" + p_strPluginName + " / " + mg.getGraphName() + ") Value: " + mg.getGraphValue()); } } } }