List of usage examples for java.util ArrayList iterator
public Iterator<E> iterator()
From source file:com.qspin.qtaste.ui.reporter.TestCaseReportTable.java
protected void updateTestCaseRow(TestResult tr) { int rowNum = ((Integer) testCases.get(tr)).intValue(); if (rowNum == -1) { // means that testcases has not been emptied .. // TO DO/*www . ja v a2 s . co m*/ return; } tcModel.setValueAt(convertToUniqueTc(tr), rowNum, TEST_CASE); tcModel.setValueAt(tr.getFormattedElapsedTime(false), rowNum, EXEC_TIME); tcModel.setValueAt(tr.getExtraResultDetails(), rowNum, DETAILS); if (tr.getReturnValue() != null) { tcModel.setValueAt(tr.getReturnValue(), rowNum, RESULT); } TestResult.Status testCaseStatus = tr.getStatus(); ImageIcon statusImg = getImage(testCaseStatus); tcModel.setValueAt(statusImg, rowNum, STATUS); TestBedConfiguration testbed = TestBedConfiguration.getInstance(); tcModel.setValueAt( testbed.getFile().getName().replace("." + StaticConfiguration.CAMPAIGN_FILE_EXTENSION, ""), rowNum, TESTBED); if ((testCaseStatus == TestResult.Status.FAIL) || ((testCaseStatus == TestResult.Status.NOT_AVAILABLE))) { int selectedRow = tcTable.getSelectedRow(); // update the failedReason if the current selected testcase is // the one to be updated if (selectedRow == rowNum) { if (tcReasonModel != null) { // clear while (tcReasonModel.getRowCount() > 0) { tcReasonModel.removeRow(0); } ArrayList<StackTraceElement> stack = tr.getStack(); Iterator<StackTraceElement> it = stack.iterator(); while (it.hasNext()) { StackTraceElement stackElement = it.next(); if (stackElement.getFileName().equals("embedded_jython")) { continue; } Object[] row = new Object[6]; row[TCResultsSelectionListeners.LINE] = stackElement.getLineNumber(); row[TCResultsSelectionListeners.FILE_NAME] = stackElement.getFileName(); String methodName = stackElement.getMethodName(); if (methodName.equals("f$0")) { methodName = "main"; } else { // remove $i suffix from method name int dollarIndex = methodName.indexOf("$"); if (dollarIndex > 0) { methodName = methodName.substring(0, dollarIndex); } } row[TCResultsSelectionListeners.FUNCTION_ID] = methodName; //row[TCResultsSelectionListeners.ERR_MSG] = tr.getExtraResultDetails(); row[TCResultsSelectionListeners.OBJECT] = stackElement; //row[TCResultsSelectionListeners.ROW] = tr.getTestData() != null ? tr.getTestData().getRowId() : null;; tcReasonModel.addRow(row); } } if (stackTrace != null) { stackTrace.setText(tr.getStackTrace()); } } } }
From source file:com.nubits.nubot.trading.wrappers.BitcoinCoIDWrapper.java
private ApiResponse getBalanceImpl(Currency currency, CurrencyPair pair) { ApiResponse apiResponse = new ApiResponse(); boolean isGet = false; String url = API_BASE_URL; String method = API_GET_INFO; HashMap<String, String> query_args = new HashMap<>(); ApiResponse response = getQuery(url, method, query_args, true, isGet); if (response.isPositive()) { JSONObject httpAnswerJson = (JSONObject) response.getResponseObject(); JSONObject data = (JSONObject) httpAnswerJson.get("return"); JSONObject balances = (JSONObject) data.get("balance"); if (currency == null) { //get the balances for the pair double pegAvail = Double .parseDouble(balances.get(pair.getPaymentCurrency().getCode().toLowerCase()).toString()); Amount PEGAvail = new Amount(pegAvail, pair.getPaymentCurrency()); double nbtAvail = Double .parseDouble(balances.get(pair.getOrderCurrency().getCode().toLowerCase()).toString()); Amount NBTAvail = new Amount(nbtAvail, pair.getOrderCurrency()); double pegOnOrder = 0; double nbtOnOrder = 0; ArrayList<Order> orders = (ArrayList) getActiveOrdersToCountLockedBalance(pair).getResponseObject(); if (orders == null) { apiResponse.setError(errors.nullReturnError); return apiResponse; }/*from w w w . ja v a 2s . c om*/ for (Iterator<Order> order = orders.iterator(); order.hasNext();) { Order thisOrder = order.next(); if (thisOrder.getType().equals(Constant.SELL)) { nbtOnOrder += thisOrder.getAmount().getQuantity(); } else { pegOnOrder += Utils.round(thisOrder.getAmount().getQuantity(), Settings.DEFAULT_PRECISION); } } Amount PEGonOrder = new Amount(pegOnOrder, pair.getPaymentCurrency()); Amount NBTonOrder = new Amount(nbtOnOrder, pair.getOrderCurrency()); PairBalance balance = new PairBalance(PEGAvail, NBTAvail, PEGonOrder, NBTonOrder); apiResponse.setResponseObject(balance); } else { double balance = Double.parseDouble(balances.get(currency.getCode().toLowerCase()).toString()); Amount total = new Amount(balance, currency); apiResponse.setResponseObject(total); } } else { apiResponse = response; } return apiResponse; }
From source file:org.ambraproject.article.action.EmailArticleAction.java
private boolean checkEmails(String emailList) { if (StringUtils.isBlank(emailList)) { addFieldError("emailTo", "To e-mail address cannot be empty"); return false; } else {// w w w .j a v a 2s. com final StringTokenizer emailTokens = new StringTokenizer(emailList, " \t\n\r\f,"); if (emailTokens.countTokens() > MAX_TO_EMAIL) { addFieldError("emailTo", "Maximum of " + MAX_TO_EMAIL + " email addresses"); return false; } EmailValidator validator = EmailValidator.getInstance(); ArrayList<String> invalidEmails = new ArrayList<String>(); while (emailTokens.hasMoreTokens()) { String email = emailTokens.nextToken(); if (!validator.isValid(email)) { invalidEmails.add(email); } } final int numInvalid = invalidEmails.size(); if (numInvalid != 0) { StringBuilder errorMsg = new StringBuilder("Invalid e-mail address"); if (numInvalid > 1) { errorMsg.append("es: "); } else { errorMsg.append(": "); } Iterator<String> iter = invalidEmails.iterator(); while (iter.hasNext()) { errorMsg.append(iter.next()); if (iter.hasNext()) { errorMsg.append(", "); } } addFieldError("emailTo", errorMsg.toString()); } return (numInvalid == 0); } }
From source file:com.nubits.nubot.trading.wrappers.CcedkWrapper.java
@Override public ApiResponse clearOrders(CurrencyPair pair) { //Since there is no API entry point for that, this call will iterate over active ApiResponse apiResponse = new ApiResponse(); ArrayList<String> errorIds = new ArrayList<>(); ApiResponse activeOrdersResponse = getActiveOrders(); if (activeOrdersResponse.isPositive()) { apiResponse.setResponseObject(true); ArrayList<Order> orderList = (ArrayList) activeOrdersResponse.getResponseObject(); String errorString = ""; boolean ok = true; for (Iterator<Order> order = orderList.iterator(); order.hasNext();) { Order thisOrder = order.next(); if (!pair.equals(thisOrder.getPair())) { continue; }/*from www .ja v a 2s. c o m*/ ApiResponse deleteOrderResponse = cancelOrder(thisOrder.getId(), null); if (deleteOrderResponse.isPositive()) { continue; } else { errorIds.add(thisOrder.getId()); } } if (!errorIds.isEmpty()) { ApiError error = errors.genericError; error.setDescription(errorIds.toString()); apiResponse.setError(error); apiResponse.setResponseObject(false); } } else { apiResponse = activeOrdersResponse; } return apiResponse; }
From source file:com.cyberway.issue.crawler.util.BdbUriUniqFilterTest.java
protected void runTestWriting(long max) throws DatabaseException, URIException { long start = System.currentTimeMillis(); ArrayList<UURI> list = new ArrayList<UURI>(1000); int count = 0; for (; count < max; count++) { UURI u = UURIFactory.getInstance("http://www" + count + ".archive.org/" + count + "/index.html"); this.filter.add(u.toString(), new CandidateURI(u)); if (count > 0 && ((count % 100) == 0)) { list.add(u);/* w ww . j a va 2s. c o m*/ } if (count > 0 && ((count % 100000) == 0)) { this.logger.info("Added " + count + " in " + (System.currentTimeMillis() - start) + " misses " + ((BdbUriUniqFilter) this.filter).getCacheMisses() + " diff of misses " + ((BdbUriUniqFilter) this.filter).getLastCacheMissDiff()); } } this.logger.info("Added " + count + " in " + (System.currentTimeMillis() - start)); start = System.currentTimeMillis(); for (Iterator i = list.iterator(); i.hasNext();) { UURI uuri = (UURI) i.next(); this.filter.add(uuri.toString(), new CandidateURI(uuri)); } this.logger.info("Added random " + list.size() + " in " + (System.currentTimeMillis() - start)); start = System.currentTimeMillis(); for (Iterator i = list.iterator(); i.hasNext();) { UURI uuri = (UURI) i.next(); this.filter.add(uuri.toString(), new CandidateURI(uuri)); } this.logger.info("Deleted random " + list.size() + " in " + (System.currentTimeMillis() - start)); // Looks like delete doesn't work. assertTrue("Count is off: " + this.filter.count(), this.filter.count() == max); }
From source file:BwaSingleAlignment.java
/** * Code to run in each one of the mappers. This is, the alignment with the corresponding entry data * The entry data has to be written into the local filesystem */// w ww. j ava 2s . c o m @Override public Iterator<String> call(Integer arg0, Iterator<String> arg1) throws Exception { LOG.info("JMAbuin:: Tmp dir: " + this.tmpDir); String fastqFileName1 = this.tmpDir + this.appId + "-RDD" + arg0 + "_1"; LOG.info("JMAbuin:: Writing file: " + fastqFileName1); File FastqFile1 = new File(fastqFileName1); FileOutputStream fos1; BufferedWriter bw1; ArrayList<String> returnedValues = new ArrayList<String>(); try { fos1 = new FileOutputStream(FastqFile1); bw1 = new BufferedWriter(new OutputStreamWriter(fos1)); String newFastqRead; while (arg1.hasNext()) { newFastqRead = arg1.next(); bw1.write(newFastqRead.toString()); bw1.newLine(); } bw1.close(); //We do not need the input data anymore, as it is written in a local file arg1 = null; returnedValues = this.runAlignmentProcess(arg0, fastqFileName1, null); // Delete the temporary file, as is have now been copied to the // output directory FastqFile1.delete(); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); LOG.error(e.toString()); } return returnedValues.iterator(); }
From source file:com.splicemachine.derby.stream.function.RowAndIndexGenerator.java
@Override public Iterator<Tuple2<Long, Tuple2<byte[], byte[]>>> call(LocatedRow locatedRow) throws Exception { ExecRow execRow = locatedRow.getRow(); if (!initialized) { encoder = new PairEncoder(getKeyEncoder(), getRowHash(), dataType); int i = 0; indexTransformFunctions = new IndexTransformFunction[tentativeIndices.size()]; for (DDLMessage.TentativeIndex index : tentativeIndices) { indexTransformFunctions[i] = new IndexTransformFunction(index); i++;/*from w w w .j a v a2 s. c o m*/ } initialized = true; } try { ArrayList<Tuple2<Long, Tuple2<byte[], byte[]>>> list = new ArrayList(); KVPair mainRow = encoder.encode(execRow); locatedRow.setRowLocation(new HBaseRowLocation(mainRow.rowKeySlice())); list.add(new Tuple2<>(heapConglom, new Tuple2<>(mainRow.getRowKey(), mainRow.getValue()))); for (int i = 0; i < indexTransformFunctions.length; i++) { LocatedRow indexRow = getIndexRow(indexTransformFunctions[i], locatedRow); Long indexConglomerate = indexTransformFunctions[i].getIndexConglomerateId(); KVPair indexKVPair = indexTransformFunctions[i].call(indexRow); list.add(new Tuple2<>(indexConglomerate, new Tuple2<>(indexKVPair.getRowKey(), indexKVPair.getValue()))); } return list.iterator(); } catch (Exception e) { if (operationContext != null && operationContext.isPermissive()) { operationContext.recordBadRecord(e.getLocalizedMessage() + execRow.toString(), e); return EmptyListIterator.INSTANCE; } throw Exceptions.parseException(e); } }
From source file:br.gov.lexml.oaicat.LexMLOAICatalog.java
/** * <b>LEXML ready</b>//w w w .ja va 2 s.c om * * @return */ private HashMap getNativeHeader(final RegistroItem ri) { HashMap recordMap = null; ArrayList setSpecs = new ArrayList(); recordMap = new HashMap(); recordMap.put(NI.localIdentifier, ri.getIdRegistroItem()); recordMap.put(NI.lastModified, dateToString(ri.getTsRegistroGmt())); ConjuntoItem ci = ri.getConjuntoItem(); if (null != ci) { setSpecs.add(ci.getIdConjuntoItem()); recordMap.put(NI.setSpecs, setSpecs.iterator()); } if ("D".equalsIgnoreCase(ri.getCdStatus().substring(0, 1))) { recordMap.put(NI.status, "deleted"); } return recordMap; }
From source file:de.nec.nle.siafu.model.World.java
/** * Create the people to simulate by asking the AgentModel to do so. * /* w w w. j a va2 s. c om*/ */ private void createPeople() { people = new HashMap<String, Agent>(); try { agentModel = (BaseAgentModel) simData.getAgentModelClass() .getConstructor(new Class[] { this.getClass() }).newInstance(new Object[] { this }); } catch (Exception e) { throw new RuntimeException("Can't instantiate the agent model", e); } Agent.initialize(this); Controller.getProgress().reportCreatingAgents(); ArrayList<Agent> peopleList = agentModel.createAgents(); Iterator<Agent> peopleIt = peopleList.iterator(); while (peopleIt.hasNext()) { Agent p = peopleIt.next(); people.put(p.getName(), p); } }
From source file:logdruid.ui.chart.GraphPanel.java
public void loadGroupCheckbox(final JPanel panel_2) { panel_1.removeAll();//from w w w .j av a 2 s . co m //Iterator mineResultSetIterator = mineResultSet.mineResults.entrySet().iterator(); Map<Source, Map<String, MineResult>> treeMap = new TreeMap<Source, Map<String, MineResult>>( mineResultSet.mineResults); Iterator mineResultSetIterator = treeMap.entrySet().iterator(); logger.debug("mineResultSet size: " + mineResultSet.mineResults.size()); while (mineResultSetIterator.hasNext()) { int groupCount = 0; int totalGroupCount = 0; Map.Entry pairs = (Map.Entry) mineResultSetIterator.next(); Map mrArrayList = (Map<String, MineResult>) pairs.getValue(); ArrayList<String> mineResultGroup = new ArrayList<String>(); Set<String> mrss = mrArrayList.keySet(); mineResultGroup.addAll(mrss); Collections.sort(mineResultGroup, new AlphanumComparator()); Iterator mrArrayListIterator = mineResultGroup.iterator(); while (mrArrayListIterator.hasNext()) { String key = (String) mrArrayListIterator.next(); final MineResult mr = (MineResult) mrArrayList.get(key); Map<String, ExtendedTimeSeries> statMap = mr.getStatTimeseriesMap(); Map<String, ExtendedTimeSeries> eventMap = mr.getEventTimeseriesMap(); if (!statMap.entrySet().isEmpty() || !eventMap.entrySet().isEmpty()) { if (mr.getStartDate() != null && mr.getEndDate() != null) { if ((mr.getStartDate().before((Date) endDateJSPinner.getValue())) && (mr.getEndDate().after((Date) startDateJSpinner.getValue()))) { groupCount++; } } } } Iterator mrArrayListIterator2 = mineResultGroup.iterator(); while (mrArrayListIterator2.hasNext()) { String key = (String) mrArrayListIterator2.next(); final MineResult mr = (MineResult) mrArrayList.get(key); Map<String, ExtendedTimeSeries> statMap = mr.getStatTimeseriesMap(); Map<String, ExtendedTimeSeries> eventMap = mr.getEventTimeseriesMap(); if (!statMap.entrySet().isEmpty() || !eventMap.entrySet().isEmpty()) { if (mr.getStartDate() != null && mr.getEndDate() != null) { if ((mr.getStartDate().before((Date) maximumDate)) && (mr.getEndDate().after((Date) minimumDate))) { totalGroupCount++; } } } } boolean selected = true; if (groupCheckBox.containsKey(((Source) pairs.getKey()).getSourceName())) { selected = groupCheckBox.get(((Source) pairs.getKey()).getSourceName()); } else { groupCheckBox.put(((Source) pairs.getKey()).getSourceName(), selected); } JCheckBox chckbxGroup = new JCheckBox( ((Source) pairs.getKey()).getSourceName() + "(" + groupCount + "/" + totalGroupCount + ")"); chckbxGroup.setFont(new Font("Dialog", Font.BOLD, 11)); chckbxGroup.setSelected(selected); panel_1.add(chckbxGroup); chckbxGroup.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JCheckBox chkBox = ((JCheckBox) e.getSource()); groupCheckBox.put( (String) chkBox.getText().substring(0, ((String) chkBox.getText()).indexOf("(")), !groupCheckBox.get((String) chkBox.getText().substring(0, ((String) chkBox.getText()).indexOf("(")))); loadGroupCheckbox(panel_2); load(panel_2); //logger.info("checkBox:"+ chkBox.getText()+","+chkBox.isSelected()+","+groupCheckBox); //logger.info("checkBox2:"+((String)chkBox.getText())+", "+((String)chkBox.getText()).indexOf("(")+", "+groupCheckBox.get((String)chkBox.getText().substring(0, ((String)chkBox.getText()).indexOf("(")))); } }); } }