List of usage examples for java.util ListIterator hasNext
boolean hasNext();
From source file:edu.iu.daal_linreg.LinRegDaalCollectiveMapper.java
private NumericTable getNumericTableHDFS(DaalContext daal_Context, Configuration conf, String inputFiles, int vectorSize, int numRows) throws IOException { Path inputFilePaths = new Path(inputFiles); List<String> inputFileList = new LinkedList<>(); try {/*from ww w . jav a 2 s.co m*/ FileSystem fs = inputFilePaths.getFileSystem(conf); RemoteIterator<LocatedFileStatus> iterator = fs.listFiles(inputFilePaths, true); while (iterator.hasNext()) { String name = iterator.next().getPath().toUri().toString(); inputFileList.add(name); } } catch (IOException e) { LOG.error("Fail to get test files", e); } int dataSize = vectorSize * numRows; // float[] data = new float[dataSize]; double[] data = new double[dataSize]; long[] dims = { numRows, vectorSize }; int index = 0; FSDataInputStream in = null; //loop over all the files in the list ListIterator<String> file_itr = inputFileList.listIterator(); while (file_itr.hasNext()) { String file_name = file_itr.next(); LOG.info("read in file name: " + file_name); Path file_path = new Path(file_name); try { FileSystem fs = file_path.getFileSystem(conf); in = fs.open(file_path); } catch (Exception e) { LOG.error("Fail to open file " + e.toString()); return null; } //read file content while (true) { String line = in.readLine(); if (line == null) break; String[] lineData = line.split(","); for (int t = 0; t < vectorSize; t++) { if (index < dataSize) { // data[index] = Float.parseFloat(lineData[t]); data[index] = Double.parseDouble(lineData[t]); index++; } else { LOG.error("Incorrect size of file: dataSize: " + dataSize + "; index val: " + index); return null; } } } in.close(); } if (index != dataSize) { LOG.error("Incorrect total size of file: dataSize: " + dataSize + "; index val: " + index); return null; } //debug check the vals of data // for(int p=0;p<60;p++) // LOG.info("data at: " + p + " is: " + data[p]); NumericTable predictionData = new HomogenNumericTable(daal_Context, data, vectorSize, numRows); return predictionData; }
From source file:vteaexploration.plottools.panels.XYChartPanel.java
private DefaultXYZDataset createXYZDataset(ArrayList alVolumes, int x, int y, int l) { //System.out.println("PROFILING: New dataset, for " + alVolumes.size() + " objects."); DefaultXYZDataset result = new DefaultXYZDataset(); int counter = 0; double[] xCorrected = new double[alVolumes.size()]; double[] yCorrected = new double[alVolumes.size()]; double[] lCorrected = new double[alVolumes.size()]; ListIterator litr = alVolumes.listIterator(); while (litr.hasNext()) { // try { MicroObjectModel volume = (MicroObjectModel) litr.next(); xCorrected[counter] = processPosition(x, volume).doubleValue(); yCorrected[counter] = processPosition(y, volume).doubleValue(); if (l > 0) { lCorrected[counter] = processPosition(l, volume).doubleValue(); } else {//from w w w. j a v a2s .co m lCorrected[counter] = 0; } counter++; // } // catch (NullPointerException e) { // System.out.println("EXCEPTION: Error building dataset."); // } } double[][] series = new double[][] { xCorrected, yCorrected, lCorrected }; result.addSeries("first", series); return result; }
From source file:com.caricah.iotracah.datastore.ignitecache.internal.impl.SubscriptionFilterHandler.java
public Observable<IotSubscriptionFilter> matchTopicFilterTree(String partitionId, List<String> topicNavigationRoute) { return Observable.create(observer -> { Set<IotSubscriptionFilterKey> topicFilterKeys = new HashSet<>(); ListIterator<String> pathIterator = topicNavigationRoute.listIterator(); List<String> growingTitles = new ArrayList<>(); while (pathIterator.hasNext()) { String name = pathIterator.next(); List<String> slWildCardList = new ArrayList<>(growingTitles); if (pathIterator.hasNext()) { //We deal with wildcard. slWildCardList.add(Constant.MULTI_LEVEL_WILDCARD); topicFilterKeys.add(keyFromList(partitionId, slWildCardList)); } else { slWildCardList.add(Constant.SINGLE_LEVEL_WILDCARD); topicFilterKeys.add(keyFromList(partitionId, slWildCardList)); slWildCardList.add(Constant.SINGLE_LEVEL_WILDCARD); topicFilterKeys.add(keyFromList(partitionId, slWildCardList)); slWildCardList.remove(slWildCardList.size() - 1); slWildCardList.remove(slWildCardList.size() - 1); //we deal with full topic slWildCardList.add(name); }/* w ww . j a v a2 s .co m*/ List<String> reverseSlWildCardList = new ArrayList<>(slWildCardList); growingTitles.add(name); int sizeOfTopic = slWildCardList.size() - 1; for (int i = 0; i <= sizeOfTopic; i++) { if (i < sizeOfTopic) { int reverseIndex = sizeOfTopic - i; slWildCardList.set(i, Constant.SINGLE_LEVEL_WILDCARD); reverseSlWildCardList.set(reverseIndex, Constant.SINGLE_LEVEL_WILDCARD); topicFilterKeys.add(keyFromList(partitionId, slWildCardList)); topicFilterKeys.add(keyFromList(partitionId, reverseSlWildCardList)); } else { if (!pathIterator.hasNext()) { slWildCardList.set(i, Constant.SINGLE_LEVEL_WILDCARD); topicFilterKeys.add(keyFromList(partitionId, slWildCardList)); slWildCardList.add(Constant.SINGLE_LEVEL_WILDCARD); topicFilterKeys.add(keyFromList(partitionId, slWildCardList)); slWildCardList.set(slWildCardList.size() - 1, Constant.MULTI_LEVEL_WILDCARD); topicFilterKeys.add(keyFromList(partitionId, slWildCardList)); } } } } topicFilterKeys.add(keyFromList(partitionId, growingTitles)); growingTitles.add(Constant.SINGLE_LEVEL_WILDCARD); topicFilterKeys.add(keyFromList(partitionId, growingTitles)); growingTitles.set(growingTitles.size() - 1, Constant.MULTI_LEVEL_WILDCARD); topicFilterKeys.add(keyFromList(partitionId, growingTitles)); growingTitles.remove(growingTitles.size() - 1); growingTitles.set(growingTitles.size() - 1, Constant.SINGLE_LEVEL_WILDCARD); topicFilterKeys.add(keyFromList(partitionId, growingTitles)); growingTitles.set(growingTitles.size() - 1, Constant.MULTI_LEVEL_WILDCARD); topicFilterKeys.add(keyFromList(partitionId, growingTitles)); //Add lost wildcard getBySet(topicFilterKeys).subscribe(observer::onNext, observer::onError, observer::onCompleted); }); }
From source file:com.caricah.iotracah.core.worker.DumbWorker.java
private Set<String> getMatchingSubscriptions(String partition, String topic) { Set<String> topicFilterKeys = new HashSet<>(); ListIterator<String> pathIterator = Arrays.asList(topic.split(Constant.PATH_SEPARATOR)).listIterator(); List<String> growingTitles = new ArrayList<>(); while (pathIterator.hasNext()) { String name = pathIterator.next(); List<String> slWildCardList = new ArrayList<>(growingTitles); if (pathIterator.hasNext()) { //We deal with wildcard. slWildCardList.add(Constant.SINGLE_LEVEL_WILDCARD); topicFilterKeys.add(quickCheckIdKey(partition, slWildCardList)); } else {/* w ww .jav a 2s . c o m*/ //we deal with full topic slWildCardList.add(name); } List<String> reverseSlWildCardList = new ArrayList<>(slWildCardList); growingTitles.add(name); int sizeOfTopic = slWildCardList.size(); if (sizeOfTopic > 1) { sizeOfTopic -= 1; for (int i = 0; i < sizeOfTopic; i++) { if (i >= 0) { slWildCardList.set(i, Constant.MULTI_LEVEL_WILDCARD); reverseSlWildCardList.set(sizeOfTopic - i, Constant.MULTI_LEVEL_WILDCARD); topicFilterKeys.add(quickCheckIdKey(partition, slWildCardList)); topicFilterKeys.add(quickCheckIdKey(partition, reverseSlWildCardList)); } } } } topicFilterKeys.add(quickCheckIdKey(partition, growingTitles)); return topicFilterKeys; }
From source file:org.openmrs.module.sdmxhddataexport.web.controller.dataelement.DataElementController.java
@RequestMapping(value = "/module/sdmxhddataexport/listDataElement.form", method = RequestMethod.POST) public String deleteDataElement(@RequestParam(value = "ids", required = false) String[] ids, @RequestParam(value = "files", required = false) MultipartFile uploadItem, HttpServletRequest request, @RequestParam(value = "upload", required = false) String upload, @RequestParam(value = "IncludeQueries", required = false) String IncludeQueries, Object command, SessionStatus status) {//from w w w . j av a 2 s.co m String temp = ""; HttpSession httpSession = request.getSession(); Integer dataElementId = null; System.out.println(" done " + upload); if (upload != null) { System.out.println("1st part truly done"); //FileUpload file = uploadItem; String fileName = ""; if (uploadItem != null) { fileName = uploadItem.getOriginalFilename(); System.out.println("2nd part truly done " + fileName); byte[] byteArray = null; try { byteArray = uploadItem.getBytes(); } catch (IOException e) { // TODO Auto-generated catch block System.out.println("Bad file name"); e.printStackTrace(); } String data = new String(byteArray); System.out.println("3rd part truly done " + data); XPath xpath = XPathFactory.newInstance().newXPath(); DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance(); domFactory.setNamespaceAware(true); DocumentBuilder builder = null; try { builder = domFactory.newDocumentBuilder(); } catch (ParserConfigurationException e) { e.printStackTrace(); } Document doc = null; try { doc = builder.parse(uploadItem.getInputStream()); } catch (SAXException e1) { httpSession.setAttribute(WebConstants.OPENMRS_MSG_ATTR, "Unsupported Document type is uploaded "); //or we can use httpSession.setAttribute(WebConstants.OPENMRS_MSG_ATTR, "sdmxhddataexport.UploadedFile.Wrong" ); return "redirect:/module/sdmxhddataexport/listDataElement.form"; } catch (IOException e1) { // TODO Auto-generated catch block httpSession.setAttribute(WebConstants.OPENMRS_MSG_ATTR, "error in reading Document type "); //e1.printStackTrace(); } XPathExpression expr = null; XPathExpression exprDesc = null; XPathExpression exprQuery = null; try { expr = xpath.compile( "//*[local-name(.)='CodeList' and @id='CL_DATAELEMENT']/*[local-name(.)='Code']"); exprDesc = xpath.compile("//[local-name(.)='Description']"); exprQuery = xpath.compile("//[local-name(.)='Query']"); } catch (XPathExpressionException e) { httpSession.setAttribute(WebConstants.OPENMRS_MSG_ATTR, "Error parsing document "); } Object result = null; try { result = expr.evaluate(doc, XPathConstants.NODESET); } catch (XPathExpressionException e) { httpSession.setAttribute(WebConstants.OPENMRS_MSG_ATTR, "Error parsing document "); // e.printStackTrace(); } NodeList nodes = (NodeList) result; ArrayList<DataElement> dataElements = new ArrayList<DataElement>(); for (int i = 0; i < nodes.getLength(); i++) { boolean putItIn = false; DataElement de = new DataElement(); System.out.println(nodes.item(i).getLocalName()); NamedNodeMap nmp = nodes.item(i).getAttributes(); System.out.println(nmp.getNamedItem("value").getNodeValue() + " hellooo.."); de.setCode(nmp.getNamedItem("value").getNodeValue()); //Node tempNode = (Node)nodes.item(i); NodeList innerNodeList = nodes.item(i).getChildNodes(); System.out.println("length: " + innerNodeList.getLength()); for (int j = 0; j < innerNodeList.getLength(); j++) { if (innerNodeList.item(j).getLocalName() != null) { System.out.println("hehe " + innerNodeList.item(j).getLocalName()); if (innerNodeList.item(j).getLocalName().equals(new String("Description"))) { System.out.println("Description: " + innerNodeList.item(j).getTextContent()); de.setName(innerNodeList.item(j).getTextContent()); putItIn = true; } if (innerNodeList.item(j).getLocalName().equals(new String("Query")) && IncludeQueries != null) { System.out.println("Query: " + innerNodeList.item(j).getTextContent()); de.setSqlQuery(innerNodeList.item(j).getTextContent()); } } } if (putItIn) { boolean bool; DataElementValidator valid = new DataElementValidator(); bool = valid.fileValidate(de); if (bool == true) dataElements.add(de); } } ListIterator<DataElement> li = dataElements.listIterator(); DataElement de; while (li.hasNext()) { de = (DataElement) li.next(); System.out.println("Element 1 = " + de.getName()); de.setCreatedOn(new java.util.Date()); de.setCreatedBy(Context.getAuthenticatedUser().getGivenName()); SDMXHDDataExportService sDMXHDDataExportService = Context .getService(SDMXHDDataExportService.class); sDMXHDDataExportService.saveDataElement(de); } status.setComplete(); } return "redirect:/module/sdmxhddataexport/listDataElement.form"; } try { SDMXHDDataExportService sDMXHDDataExportService = Context.getService(SDMXHDDataExportService.class); if (ids != null && ids.length > 0) { for (String sId : ids) { dataElementId = Integer.parseInt(sId); if (dataElementId != null && dataElementId > 0 && CollectionUtils.isEmpty( sDMXHDDataExportService.listReportDataElement(null, dataElementId, null, 0, 1))) { sDMXHDDataExportService .deleteDataElement(sDMXHDDataExportService.getDataElementById(dataElementId)); } else { //temp += "We can't delete store="+store.getName()+" because that store is using please check <br/>"; temp = "This dataElement cannot be deleted as it is in use"; } } } } catch (Exception e) { httpSession.setAttribute(WebConstants.OPENMRS_MSG_ATTR, "Can not delete dataElement "); log.error(e); } httpSession.setAttribute(WebConstants.OPENMRS_MSG_ATTR, StringUtils.isBlank(temp) ? "sdmxhddataexport.dataElement.deleted" : temp); return "redirect:/module/sdmxhddataexport/listDataElement.form"; }
From source file:com.danielme.muspyforandroid.services.MusicBrainzClient.java
/** * Label, country, format and mbid of the concrete release * @since 1.2//from ww w. j a va 2 s . c o m */ public void loadReleaseConcrete(Release release) { if (releases.get(release.getMbid()) != null) { Release temp = releases.get(release.getMbid()); release.setCountry(temp.getCountry()); release.setFormat(temp.getFormat()); release.setLabel(temp.getLabel()); release.setTrackCount(temp.getTrackCount()); release.setMbidConcreteRelease(temp.getMbidConcreteRelease()); } else { String url = String.format(Constants.MBRAINZ.URL_RELEASES, URLEncoder.encode(release.getMbid())); HttpGet httpGet = new HttpGet(url); httpGet.setHeader(Constants.CONTENT_TYPE, Constants.TYPE_JSON); try { HttpResponse response = httpClient.execute(httpGet); StatusLine statusLine = response.getStatusLine(); //sometimes we receive HTTP 504 if (statusLine != null && statusLine.getStatusCode() == MBGatewayTimeOutException.STATUS_CODE) { throw new MBGatewayTimeOutException(); } String responseString = EntityUtils.toString(response.getEntity()); JSONObject responseJSON = new JSONObject(responseString); JSONArray jsonArray = responseJSON.getJSONArray(Constants.MBRAINZ.RELEASES); String date = getReleaseDate(release); List<JSONObject> candidates = new LinkedList<JSONObject>(); for (int i = 0; i < jsonArray.length(); i++) { if (jsonArray.getJSONObject(i).getString("date").equals(date)) { candidates.add(jsonArray.getJSONObject(i)); } } ListIterator<JSONObject> listIterator = candidates.listIterator(); boolean found = false; JSONObject releaseJson = null; String country = null; //USA while (listIterator.hasNext() && !found) { releaseJson = listIterator.next(); country = releaseJson.getString("country"); if (country.equals("US")) { found = true; loadDetails(releaseJson, release); } } //UK if (!found) { listIterator = candidates.listIterator(); while (listIterator.hasNext() && !found) { releaseJson = listIterator.next(); country = releaseJson.getString("country"); if (country.equals("GB")) { found = true; loadDetails(releaseJson, release); } } } //the first release if (!found && !candidates.isEmpty()) { loadDetails(jsonArray.getJSONObject(0), release); } } catch (Exception ex) { //this feature is not critical Log.w(this.getClass().toString(), ex.getMessage()); } releases.put(release.getMbid(), release); } }
From source file:es.uvigo.ei.sing.adops.operations.running.ExecuteExperimentBySteps.java
private void replaceSequenceNamesAln(File inputFile, File outputFile) throws IOException { final Map<String, String> names = this.experiment.getNames(); final List<String> lines = FileUtils.readLines(inputFile); int maxLength = Integer.MIN_VALUE; for (Map.Entry<String, String> name : names.entrySet()) { maxLength = Math.max(maxLength, name.getValue().length()); }// w w w .ja va2 s. co m for (Map.Entry<String, String> name : names.entrySet()) { String newName = name.getValue(); while (newName.length() < maxLength) { newName += ' '; } name.setValue(newName); } final ListIterator<String> itLines = lines.listIterator(); if (itLines.hasNext()) itLines.next(); // TODO Review parsing while (itLines.hasNext()) { itLines.next(); // White line String line = null; // Sequences while (itLines.hasNext()) { line = itLines.next(); if (line.isEmpty()) break; final String[] lineSplit = line.split("\\s+"); final String name = lineSplit.length == 0 ? "" : lineSplit[0]; if (names.get(name) == null) break; itLines.set(names.get(name) + " " + lineSplit[1]); } // Marks line if (line != null && !line.isEmpty() && line.startsWith(" ")) { String newLine = line; if (maxLength < 13) newLine = newLine.substring(13 - maxLength); else for (int i = 16; i < maxLength + 3; i++) { newLine = ' ' + newLine; } itLines.set(newLine); } } FileUtils.writeLines(outputFile, lines); }
From source file:com.impetus.kundera.query.KunderaQueryParser.java
/** * @param selectExpression//from w w w.ja va 2s. co m * @return Count of aggregation required */ private int countAggregation(Expression selectExpression) { int count = 0; if (selectExpression instanceof CollectionExpression) { CollectionExpression selectColumnExpression = (CollectionExpression) selectExpression; ListIterator<Expression> selectColumnIter = selectColumnExpression.children().iterator(); while (selectColumnIter.hasNext()) { count = validateExpression(selectColumnIter.next()) ? ++count : count; } } else { if (validateExpression(selectExpression)) count = 1; } return count; }
From source file:com.taobao.gecko.service.impl.GeckoHandler.java
private boolean removeDisconnectedConnection(final String group) { // connection) final List<Connection> currentConnList = this.remotingController.getRemotingContext() .getConnectionsByGroup(group); Connection disconnectedConn = null; if (currentConnList != null) { synchronized (currentConnList) { final ListIterator<Connection> it = currentConnList.listIterator(); while (it.hasNext()) { final Connection currentConn = it.next(); if (!currentConn.isConnected()) { disconnectedConn = currentConn; break; } else { // // if (!((DefaultConnection) currentConn).isReady() && !currentConn.getGroupSet().isEmpty()) { this.notifyConnectionReady((DefaultConnection) currentConn); }//from www. ja va2 s .co m } } } } if (disconnectedConn != null) { return currentConnList.remove(disconnectedConn); } else { return false; } }
From source file:com.alibaba.napoli.gecko.service.impl.GeckoHandler.java
private boolean removeDisconnectedConnection(final String group) { // ???connection??) final List<Connection> currentConnList = this.remotingController.getRemotingContext() .getConnectionsByGroup(group); Connection disconnectedConn = null; if (currentConnList != null) { synchronized (currentConnList) { final ListIterator<Connection> it = currentConnList.listIterator(); while (it.hasNext()) { final Connection currentConn = it.next(); if (!currentConn.isConnected()) { disconnectedConn = currentConn; break; } else { // ????? // ??? if (!((DefaultConnection) currentConn).isReady() && !currentConn.getGroupSet().isEmpty()) { this.notifyConnectionReady((DefaultConnection) currentConn); }/*from w w w . j a v a 2s.c o m*/ } } } } if (disconnectedConn != null) { return currentConnList.remove(disconnectedConn); } else { return false; } }