List of usage examples for java.util ListIterator next
E next();
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 . j a v a 2s .c om 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.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); }// ww w.j av a2s . 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:mediathek.controller.IoXmlSchreiben.java
private void xmlSchreibenPset(DatenPset[] psetArray) { ListIterator<DatenProg> it; for (DatenPset pset : psetArray) { xmlSchreibenDaten(DatenPset.PROGRAMMSET, DatenPset.COLUMN_NAMES_, pset.arr, false); it = pset.getListeProg().listIterator(); while (it.hasNext()) { xmlSchreibenDaten(DatenProg.PROGRAMM, DatenProg.COLUMN_NAMES_, it.next().arr, false); }// w ww .j av a 2s .c o m } }
From source file:org.wikipedia.nirvana.statistics.Rating.java
public void putFromDb(ArchiveDatabase2 db) throws IllegalStateException { totalUserStat.clear();//from w ww. j ava 2 s. com ListIterator<ArchiveItem> it = null; if (this.year == 0) it = db.getIterator(); else it = db.getYearIterator(year); ArchiveItem item = null; if (it.hasNext()) { item = it.next(); if (this.year != 0 && item.year != this.year) throw new IllegalStateException("year processing: " + this.year + ", item's year: " + item.year + ", item: " + item.article); if (!(this.filterBySize && item.size < this.minSize)) this.totalUserStat.put(item.user, 1); } while (it.hasNext()) { item = it.next(); if (this.year != 0 && item.year != this.year) throw new IllegalStateException("year processing: " + this.year + ", item's year: " + item.year + ", item: " + item.article); if (this.filterBySize && item.size < this.minSize) continue; Integer n = totalUserStat.get(item.user); if (n == null) this.totalUserStat.put(item.user, 1); else this.totalUserStat.put(item.user, n + 1); } }
From source file:io.bibleget.BibleGetFrame.java
/** * * @throws ClassNotFoundException//from ww w. ja va 2s . co m */ private void prepareDynamicInformation() throws ClassNotFoundException { biblegetDB = BibleGetDB.getInstance(); String bibleVersionsStr = biblegetDB.getMetaData("VERSIONS"); JsonReader jsonReader = Json.createReader(new StringReader(bibleVersionsStr)); JsonObject bibleVersionsObj = jsonReader.readObject(); Set<String> versionsabbrev = bibleVersionsObj.keySet(); bibleVersions = new BasicEventList<>(); if (!versionsabbrev.isEmpty()) { for (String s : versionsabbrev) { String versionStr = bibleVersionsObj.getString(s); //store these in an array String[] array; array = versionStr.split("\\|"); bibleVersions.add(new BibleVersion(s, array[0], array[1], StringUtils.capitalize(new Locale(array[2]).getDisplayLanguage()))); } } List<String> preferredVersions = new ArrayList<>(); String retVal = (String) biblegetDB.getOption("PREFERREDVERSIONS"); if (null == retVal) { //System.out.println("Attempt to retrieve PREFERREDVERSIONS from the Database resulted in null value"); } else { //System.out.println("Retrieved PREFERREDVERSIONS from the Database. Value is:"+retVal); String[] favoriteVersions = StringUtils.split(retVal, ','); preferredVersions = Arrays.asList(favoriteVersions); } if (preferredVersions.isEmpty()) { preferredVersions.add("NVBSE"); } List<Integer> preferredVersionsIndices = new ArrayList<>(); versionsByLang = new SeparatorList<>(bibleVersions, new VersionComparator(), 1, 1000); int listLength = versionsByLang.size(); enabledFlags = new boolean[listLength]; ListIterator itr = versionsByLang.listIterator(); while (itr.hasNext()) { int idx = itr.nextIndex(); Object next = itr.next(); enabledFlags[idx] = !(next.getClass().getSimpleName().equals("GroupSeparator")); if (next.getClass().getSimpleName().equals("BibleVersion")) { BibleVersion thisBibleVersion = (BibleVersion) next; if (preferredVersions.contains(thisBibleVersion.getAbbrev())) { preferredVersionsIndices.add(idx); } } } indices = ArrayUtils .toPrimitive(preferredVersionsIndices.toArray(new Integer[preferredVersionsIndices.size()])); //System.out.println("value of indices array: "+Arrays.toString(indices)); }
From source file:com.vizury.videocache.product.ProductDetail.java
private ProductDetail[] getProductDataFromList(CacheConnect cache, String productList, HashMap<String, ProductDetail> recommendedProductDetail, int numberOfRecommendedProducts) { String[] productIdArray = productList.replace("\"", "").split(","); List<ProductDetail> productDetailList = new ArrayList<>(); List<ProductDetail> requestProductDetailList = new ArrayList<>(); for (String pid : productIdArray) { if (!pid.equals(productId)) { if (!recommendedProductDetail.containsKey(namespace + "_1_" + pid)) { requestProductDetailList.add(new ProductDetail(pid, namespace)); }//from w w w . j a va 2s. c o m productDetailList.add(new ProductDetail(pid, namespace)); } } Map<String, Object> productDetailMap = cache.getBulk(requestProductDetailList, "_1_"); if (productDetailMap != null) { ListIterator iterator = productDetailList.listIterator(); while (iterator.hasNext()) { ProductDetail productDetail = (ProductDetail) iterator.next(); if (productDetailMap.containsKey(namespace + "_1_" + productDetail.getProductId())) { productDetail.jsonToProductDetail( (String) productDetailMap.get(namespace + "_1_" + productDetail.getProductId())); recommendedProductDetail.put(namespace + "_1_" + productDetail.getProductId(), productDetail); } else { iterator.set(recommendedProductDetail.get(namespace + "_1_" + productDetail.getProductId())); } } } else { return null; } if (productDetailList.size() <= numberOfRecommendedProducts) { return productDetailList.toArray(new ProductDetail[productDetailList.size()]); } else { Random rand = new Random(); int randomIndex; int index; ProductDetail[] productDetail = new ProductDetail[numberOfRecommendedProducts]; for (index = 0; index < numberOfRecommendedProducts; index++) { randomIndex = rand.nextInt(productDetailList.size()); productDetail[index] = productDetailList.get(randomIndex); productDetailList.remove(randomIndex); } return productDetail; } }
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 {/*from ww w . j a va2s. 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:adapters.HistogramChartAdapter.java
/** * Synchronizes <SPAN CLASS="MATH"><I>x</I></SPAN>-axis ticks to the <SPAN CLASS="MATH"><I>s</I></SPAN>-th histogram bins if the number * of bins is not larger than 10;//from w w w. j ava 2s.c o m * otherwise, choose approximately 10 ticks. * * @param s selects histogram used to define ticks. * * */ public void setTicksSynchro(int s) { if (((CustomHistogramDataset) this.dataset.getSeriesCollection()).getBinWidth(s) == -1) { DoubleArrayList newTicks = new DoubleArrayList(); ListIterator binsIter = ((HistogramSeriesCollection) this.dataset).getBins(s).listIterator(); int i = 0; HistogramBin prec = (HistogramBin) binsIter.next(); double var; newTicks.add(prec.getStartBoundary()); newTicks.add(var = prec.getEndBoundary()); HistogramBin temp; while (binsIter.hasNext()) { temp = (HistogramBin) binsIter.next(); if (temp.getStartBoundary() != var) { newTicks.add(var = temp.getStartBoundary()); } else if (temp.getEndBoundary() != var) { newTicks.add(var = temp.getEndBoundary()); } } XAxis.setLabels(newTicks.elements()); } else { // set a label-tick for each bin, if num bins is <= 10 int n = ((HistogramSeriesCollection) this.dataset).getBins(s).size(); if (n > 10) { // number of bins is too large, set ~10 labels-ticks for histogram n = 10; double[] B = ((HistogramSeriesCollection) this.dataset).getDomainBounds(); double w = (B[1] - B[0]) / n; XAxis.setLabels(w); } else { XAxis.setLabels(((CustomHistogramDataset) this.dataset.getSeriesCollection()).getBinWidth(s)); } } }
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 ww w.j ava 2 s .c om*/ 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"; }