List of usage examples for java.util ArrayList iterator
public Iterator<E> iterator()
From source file:it.cnr.icar.eric.server.common.Utility.java
/** * Return ArrayList of ExternalLink that points to unresolvable Http URLs. Any * non-Http URLs will not be checked. Any non-Http URLs and other types * of URIs will not be checked. If the http response code is smaller than 200 * or bigger than 299, the http URL is considered invalid. */// w w w .j a v a 2s. com public ArrayList<Object> validateURIs(ArrayList<?> sourceRegistryObjects) throws RegistryException { ArrayList<Object> invalidURLROs = new ArrayList<Object>(); Iterator<?> iter = sourceRegistryObjects.iterator(); while (iter.hasNext()) { Object ro = iter.next(); String uRI = null; if (ro instanceof ExternalLinkType) { uRI = ((ExternalLinkType) ro).getExternalURI(); } else if (ro instanceof ServiceBindingType) { uRI = ((ServiceBindingType) ro).getAccessURI(); } else { throw new RegistryException( ServerResourceBundle.getInstance().getString("message.unknownRegistryObjectType")); } if (!it.cnr.icar.eric.common.Utility.getInstance().isValidURI(uRI)) { invalidURLROs.add(ro); } } return invalidURLROs; }
From source file:com.dtolabs.rundeck.core.cli.acl.AclTool.java
/** * Create the map structure corresponding to yaml * * @param authRequest request//from ww w. ja v a 2 s .c om * * @return data map */ public static Map<String, ?> toDataMap(final AuthRequest authRequest) { HashMap<String, Object> stringHashMap = new HashMap<>(); //context Map<String, Object> ruleMap = new HashMap<>(); if (authRequest.environment.equals(createAppEnv())) { //app context HashMap<String, String> s = new HashMap<>(); s.put("application", "rundeck"); stringHashMap.put(CONTEXT_LONG_OPT, s); } else { String project = authRequest.environment.iterator().next().value; HashMap<String, String> s = new HashMap<>(); s.put("project", project); stringHashMap.put(CONTEXT_LONG_OPT, s); } //subject Set<Username> principals = authRequest.subject.getPrincipals(Username.class); if (principals.iterator().next().getName().equals("user")) { //use groups HashMap<String, Object> s = new HashMap<>(); ArrayList<String> strings = new ArrayList<>(); for (Group group : authRequest.subject.getPrincipals(Group.class)) { strings.add(group.getName()); } s.put("group", strings.size() > 1 ? strings : strings.iterator().next()); stringHashMap.put("by", s); } else { HashMap<String, String> s = new HashMap<>(); s.put("username", principals.iterator().next().getName()); stringHashMap.put("by", s); } Map<String, Object> resource = new HashMap<>(); //resource String type = authRequest.resourceMap.get("type").toString(); resource.putAll(authRequest.resourceMap); resource.remove("type"); //project context type HashMap<String, Object> s = new HashMap<>(); ArrayList<Map<String, Object>> maps = new ArrayList<>(); s.put(type, maps); HashMap<String, Object> r = new HashMap<>(); if (resource.size() > 0) { r.put(authRequest.regexMatch ? "match" : authRequest.containsMatch ? "contains" : "equals", resource); } if (authRequest.actions != null && authRequest.actions.size() > 0) { r.put("allow", authRequest.actions.size() > 1 ? new ArrayList<>(authRequest.actions) : authRequest.actions.iterator().next()); } if (authRequest.denyActions != null && authRequest.denyActions.size() > 0) { r.put("deny", authRequest.denyActions.size() > 1 ? new ArrayList<>(authRequest.denyActions) : authRequest.denyActions.iterator().next()); } maps.add(r); ruleMap.putAll(s); stringHashMap.put("for", ruleMap); stringHashMap.put("description", authRequest.description != null ? authRequest.description : "generated"); return stringHashMap; }
From source file:com.polyvi.xface.extension.XMessagingExt.java
/** * PendingIntent//from w w w . j a v a 2s. co m * * @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(); Context ctx = getContext(); while (itor.hasNext()) { smsSendPendingIntentList.add(PendingIntent.getBroadcast(ctx, 0, smsSendIntent, 0)); itor.next(); } return smsSendPendingIntentList; }
From source file:com.runwaysdk.controller.URLConfigurationManager.java
public void readController(String uri, String controllerClassName, Element el) { ControllerMapping controllerMapping = new ControllerMapping(uri, controllerClassName); ArrayList<Method> methods = null; try {/*from www. j av a 2s.c o m*/ Class<?> clazz = LoaderDecorator.load(controllerClassName); Class<?> clazzBase = LoaderDecorator.load(controllerClassName + "Base"); methods = new ArrayList<Method>(Arrays.asList(clazz.getMethods())); Iterator<Method> it = methods.iterator(); while (it.hasNext()) { Method m = it.next(); if (!m.getDeclaringClass().equals(clazz) && !m.getDeclaringClass().equals(clazzBase)) { it.remove(); } } } catch (Throwable t) { String exMsg = "Exception loading controller class [" + controllerClassName + "]."; throw new RunwayConfigurationException(exMsg, t); } NodeList actions = el.getChildNodes(); for (int iAction = 0; iAction < actions.getLength(); ++iAction) { Node nodeAct = actions.item(iAction); if (nodeAct.getNodeType() == Node.ELEMENT_NODE) { Element elAction = (Element) nodeAct; String method = elAction.getAttribute("method"); String actionUrl = elAction.getAttribute("uri"); boolean didMatch = false; for (Method m : methods) { if (m.getName().matches(method)) { controllerMapping.add(m.getName(), actionUrl); didMatch = true; } } if (!didMatch) { String exMsg = "The method regex [" + method + "] for action [" + actionUrl + "] did not match any methods on the controller class definition [" + controllerClassName + "]."; throw new RunwayConfigurationException(exMsg); } } } mappings.add(controllerMapping); }
From source file:com.nubits.nubot.trading.wrappers.AltsTradeWrapper.java
@Override public ApiResponse isOrderActive(String id) { ApiResponse apiResponse = new ApiResponse(); ApiResponse getActiveOrders = getActiveOrders(); if (getActiveOrders.isPositive()) { ArrayList<Order> orders = (ArrayList) getActiveOrders.getResponseObject(); boolean isActive = false; for (Iterator<Order> order = orders.iterator(); order.hasNext();) { if (order.next().getId().equals(id)) { isActive = true;/*from ww w.j a v a 2s. com*/ } } apiResponse.setResponseObject(isActive); } else { apiResponse = getActiveOrders; } return apiResponse; }
From source file:com.nubits.nubot.trading.wrappers.BitcoinCoIDWrapper.java
@Override public ApiResponse clearOrders(CurrencyPair pair) { ApiResponse apiResponse = new ApiResponse(); apiResponse.setResponseObject(true); ApiResponse getOrders = getActiveOrders(); if (getOrders.isPositive()) { ArrayList<Order> orders = (ArrayList) getOrders.getResponseObject(); for (Iterator<Order> order = orders.iterator(); order.hasNext();) { Order o = order.next();//w ww . j av a2s . c o m String id = o.getId(); ApiResponse r = cancelOrder(id, pair); boolean posi = r.isPositive(); if (!posi) { apiResponse.setResponseObject(false); } else { apiResponse.setResponseObject(r.getResponseObject()); } } } else { apiResponse = getOrders; } return apiResponse; }
From source file:ca.sfu.federation.model.Assembly.java
/** * Update the state of the AbstractContext. * @return True if updated successfully, false otherwise. *///from w w w . j av a 2 s.c om public boolean update() { ArrayList childelements = new ArrayList(); try { childelements = getElementsInTopologicalOrder(); } catch (GraphCycleException ex) { String stack = ExceptionUtils.getFullStackTrace(ex); logger.log(Level.WARNING, "Could not get elements in topological order\n\n{0}", stack); } // print out the update order for debugging Iterator it = childelements.iterator(); StringBuilder sb = new StringBuilder(); sb.append(this.name); while (it.hasNext()) { INamed named = (INamed) it.next(); sb.append(named.getName()); sb.append(" "); } logger.log(Level.FINE, "{0} update event. Update sequence is: ", new Object[] { this.name, sb.toString() }); // update nodes boolean updateSuccessful = true; Iterator it2 = childelements.iterator(); while (it2.hasNext() && updateSuccessful) { Object object = it2.next(); if (object instanceof IUpdateable) { IUpdateable updateable = (IUpdateable) object; updateSuccessful = updateable.update(); } } // if update was successful, notify all observers if (updateSuccessful) { this.setChanged(); this.notifyObservers(); } // return result return updateSuccessful; }
From source file:com.addthis.hydra.data.query.QueryElementNode.java
public Iterator<DataTreeNode> getNodes(LinkedList<DataTreeNode> stack) { List<DataTreeNode> ret = null; if (up()) {// ww w. j a v a 2 s .c om ret = new ArrayList<>(1); ret.add(stack.get(1)); return ret.iterator(); } DataTreeNode parent = stack.peek(); DataTreeNode defaultNode = null; if (defaultValue != null) { defaultNode = new VirtualTreeNode(defaultValue, defaultHits); } try { DataTreeNode tmp; if (path != null) { DataTreeNode refnode = followPath(parent.getTreeRoot(), path); return refnode != null ? new ReferencePathIterator(refnode, parent) : null; } if (trap != null) { for (String name : trap) { for (ClosableIterator<DataTreeNode> iter = parent.getIterator(); iter.hasNext();) { tmp = iter.next(); if (regex()) { if (tmp.getName().matches(name)) { iter.close(); return null; } } else { if (tmp.getName().equals(name)) { iter.close(); return null; } } } } } if ((match == null) && (regex == null) && (data == null)) { Iterator<DataTreeNode> result = parent.getIterator(); if (result.hasNext() || (defaultNode == null)) { return result; } else { return Iterators.singletonIterator(defaultNode); } } ret = new LinkedList<>(); if (match != null) { if (regex()) { if (regexPatterns == null) { regexPatterns = new Pattern[match.length]; for (int i = 0; i < match.length; i++) { regexPatterns[i] = Pattern.compile(match[i]); } } for (Iterator<DataTreeNode> iter = parent.getIterator(); iter.hasNext();) { tmp = iter.next(); for (Pattern name : regexPatterns) { if (name.matcher(tmp.getName()).matches() ^ not()) { ret.add(tmp); } } } } else if (range()) { if (match.length == 0) { return parent.getIterator(); } else if (match.length == 1) { return parent.getIterator(match[0]); } else { ArrayList<Iterator<DataTreeNode>> metaIterator = new ArrayList<>(); for (String name : match) { metaIterator.add(parent.getIterator(name)); } return Iterators.concat(metaIterator.iterator()); } } else if (rangeStrict()) { return parent.getIterator(match.length > 0 ? match[0] : null, match.length > 1 ? match[1] : null); } else if (data == null) { return new LazyNodeMatch(parent, match, defaultNode); } else { for (String name : match) { DataTreeNode find = parent.getNode(name); if (find != null) { ret.add(find); } } } } if (data != null) { if (regex()) { if (parent.getDataMap() != null) { for (Map.Entry<String, TreeNodeData> actor : parent.getDataMap().entrySet()) { int memSize = CodecBin2.encodeBytes(actor.getValue()).length; ReadTreeNode memNode = new ReadTreeNode(actor.getKey(), memSize); ret.add(memNode); } } } else { DataTreeNodeActor actor = parent.getData(data); if (actor != null) { Collection<DataTreeNode> nodes = actor.onNodeQuery(dataKey); if (nodes != null) { ret.addAll(nodes); } } } } } catch (RuntimeException ex) { throw ex; } catch (Exception ex) { ex.printStackTrace(); } if ((ret.size() == 0) && (defaultNode != null)) { return Iterators.singletonIterator(defaultNode); } else { return ret.iterator(); } }
From source file:com.nubits.nubot.tasks.SubmitLiquidityinfoTask.java
private String reportTier1() { String toReturn = ""; Global.orderManager.fetchOrders();//from w ww . ja va 2s . co m ArrayList<Order> orderList = Global.orderManager.getOrderList(); if (SessionManager.sessionInterrupted()) return ""; //external interruption LOG.debug("Active orders : " + orderList.size()); Iterator<Order> it = orderList.iterator(); while (it.hasNext()) { Order o = it.next(); LOG.debug("order: " + o.getDigest()); } if (SessionManager.sessionInterrupted()) return ""; //external interruption if (verbose) { LOG.info(Global.exchange.getName() + "OLD NBTonbuy : " + Utils.formatNumber(Global.exchange.getLiveData().getNBTonbuy(), Settings.DEFAULT_PRECISION)); LOG.info(Global.exchange.getName() + "OLD NBTonsell : " + Utils.formatNumber(Global.exchange.getLiveData().getNBTonsell(), Settings.DEFAULT_PRECISION)); } double nbt_onsell = 0; double nbt_onbuy = 0; int sells = 0; int buys = 0; String digest = ""; for (int i = 0; i < orderList.size(); i++) { Order tempOrder = orderList.get(i); digest = digest + tempOrder.getDigest(); double toAdd = tempOrder.getAmount().getQuantity(); if (verbose) { LOG.info(tempOrder.toString()); } if (tempOrder.getType().equalsIgnoreCase(Constant.SELL)) { //Start summing up amounts of NBT nbt_onsell += toAdd; sells++; } else if (tempOrder.getType().equalsIgnoreCase(Constant.BUY)) { //Start summing up amounts of NBT nbt_onbuy += toAdd; buys++; } } //Update the order Global.exchange.getLiveData().setOrdersList(orderList); if (Global.conversion != 1 && Global.swappedPair) { //For swapped pair, need to convert the amounts to NBT nbt_onbuy = nbt_onbuy * Global.conversion; nbt_onsell = nbt_onsell * Global.conversion; } Global.exchange.getLiveData().setNBTonbuy(nbt_onbuy); Global.exchange.getLiveData().setNBTonsell(nbt_onsell); //Write to file timestamp,activeOrders, sells,buys, digest Date timeStamp = new Date(); String timeStampString = timeStamp.toString(); Long timeStampLong = Utils.getTimestampLong(); String toWrite = timeStampString + " , " + orderList.size() + " , " + sells + " , " + buys + " , " + digest; logOrderCSV(toWrite); if (SessionManager.sessionInterrupted()) return ""; //external interruption //Also update a json version of the output file //build the latest data into a JSONObject JSONObject latestOrders = new JSONObject(); latestOrders.put("time_stamp", timeStampLong); latestOrders.put("active_orders", orderList.size()); JSONArray jsonDigest = new JSONArray(); for (Iterator<Order> order = orderList.iterator(); order.hasNext();) { JSONObject thisOrder = new JSONObject(); Order _order = order.next(); //issue 160 - convert all amounts in NBT double amount = _order.getAmount().getQuantity(); //special case: swapped pair if (Global.conversion != 1) { if (Global.swappedPair)//For swapped pair, need to convert the amounts to NBT { amount = _order.getAmount().getQuantity() * Global.conversion; } } thisOrder.put("order_id", _order.getId()); thisOrder.put("time", _order.getInsertedDate().getTime()); thisOrder.put("order_type", _order.getType()); thisOrder.put("order_currency", _order.getPair().getOrderCurrency().getCode()); thisOrder.put("amount", amount); thisOrder.put("payment_currency", _order.getPair().getPaymentCurrency().getCode()); thisOrder.put("price", _order.getPrice().getQuantity()); jsonDigest.add(thisOrder); } latestOrders.put("digest", jsonDigest); if (SessionManager.sessionInterrupted()) return ""; //external interruption //now read the existing object if one exists JSONParser parser = new JSONParser(); JSONObject orderHistory = new JSONObject(); JSONArray orders = new JSONArray(); try { //object already exists in file orderHistory = (JSONObject) parser.parse(FilesystemUtils.readFromFile(this.jsonFile_orders)); orders = (JSONArray) orderHistory.get("orders"); } catch (ParseException pe) { LOG.error("Unable to parse " + this.jsonFile_orders); } //add the latest orders to the orders array orders.add(latestOrders); //then save logOrderJSON(orderHistory); if (verbose) { LOG.info(Global.exchange.getName() + "Updated NBTonbuy : " + Utils.formatNumber(nbt_onbuy, Settings.DEFAULT_PRECISION)); LOG.info(Global.exchange.getName() + "Updated NBTonsell : " + Utils.formatNumber(nbt_onsell, Settings.DEFAULT_PRECISION)); } if (SessionManager.sessionInterrupted()) return ""; //external interruption if (Global.options.isSubmitliquidity()) { //Call RPC double buySide; double sellSide; if (!Global.swappedPair) { buySide = Global.exchange.getLiveData().getNBTonbuy(); sellSide = Global.exchange.getLiveData().getNBTonsell(); } else { buySide = Global.exchange.getLiveData().getNBTonsell(); sellSide = Global.exchange.getLiveData().getNBTonbuy(); } toReturn = sendLiquidityInfoImpl(buySide, sellSide, 1); } return toReturn; }
From source file:geva.Operator.Operations.StatisticsCollectionOperation.java
/** * Print the StatCatcher to file// ww w .j a va2 s . c o m **/ @SuppressWarnings({ "IOResourceOpenedButNotSafelyClosed" }) public void printStats() { try { this.fileName = fileName + System.currentTimeMillis(); FileWriter fw = new FileWriter(fileName + ".dat"); BufferedWriter bw = new BufferedWriter(fw); ArrayList<Double> m, b, aUG, aV, aL, aD; ArrayList<Long> t; ArrayList<Integer> inv; b = stats.getBestFitness(); m = stats.getMeanFitness(); aUG = stats.getMeanUsedGenes(); t = stats.getTime(); inv = stats.getInvalids(); aV = stats.getVarFitness(); aL = stats.getAveLength(); aD = stats.getMeanDerivationTreeDepth(); Iterator<Double> ib = b.iterator(); Iterator<Double> im = m.iterator(); Iterator<Double> iAV = aV.iterator(); Iterator<Double> iAUG = aUG.iterator(); Iterator<Double> iAD = aD.iterator(); Iterator<Long> iT = t.iterator(); Iterator<Integer> iInv = inv.iterator(); Iterator<Double> iAL = aL.iterator(); Long start = iT.next(); Long diff, stop; bw.write(StatisticsCollectionOperation.OUTPUT_COLUMNS); bw.newLine(); while (ib.hasNext() && im.hasNext() && iAUG.hasNext() && iT.hasNext() && iInv.hasNext() && iAV.hasNext() && iAL.hasNext() && iAD.hasNext()) { stop = iT.next(); diff = stop - start; start = stop; bw.write(ib.next() + " " + im.next() + " " + iAUG.next() + " " + diff + " " + iInv.next() + " " + iAV.next() + " " + iAL.next() + " " + iAD.next()); bw.newLine(); } bw.close(); fw.close(); } catch (IOException e) { e.printStackTrace(); } }