List of usage examples for java.util ListIterator hasNext
boolean hasNext();
From source file:com.projity.pm.assignment.HasAssignmentsImpl.java
public void forEachInterval(Closure visitor, Object type, WorkCalendar workCalendar) { NonGroupedCalculatedValues calculatedValues = new NonGroupedCalculatedValues(false, 0); ListIterator i = assignments.listIterator(); Assignment assignment = null;// w w w . j a v a 2s . c o m while (i.hasNext()) { // add in all child groups assignment = (Assignment) i.next(); barCallback.setWorkCalendar(assignment.getEffectiveWorkCalendar()); // use this assignments cal because it might work on off calendar time assignment.calcDataBetween(type, null, calculatedValues); } calculatedValues.makeContiguousNonZero(barCallback, workCalendar); //calculatedValues.dump(); }
From source file:at.pagu.soldockr.core.query.Criteria.java
/** * get the QueryString used for executing query * //w ww. j a va 2 s. c o m * @return */ public String createQueryString() { StringBuilder query = new StringBuilder(StringUtils.EMPTY); ListIterator<Criteria> chainIterator = this.criteriaChain.listIterator(); while (chainIterator.hasNext()) { Criteria chainedCriteria = chainIterator.next(); query.append(createQueryFragmentForCriteria(chainedCriteria)); if (chainIterator.hasNext()) { query.append(chainIterator.next().getConjunctionOperator()); chainIterator.previous(); } } return query.toString(); }
From source file:edu.cuny.cat.market.matching.LazyMaxVolumeShoutEngine.java
/** * <p>/*www .java2 s .com*/ * Return a list of matched bids and asks. The list is of the form * </p> * <br> * ( b0, a0, b1, a1 .. bn, an )<br> * * <p> * where bi is the ith bid and a0 is the ith ask. A typical auctioneer would * clear by matching bi with ai for all i at some price. * </p> */ @Override public List<Shout> getMatchedShouts() { final ArrayList<Shout> result = new ArrayList<Shout>(sIn.size() + bIn.size()); // prettyPrint("sIn: ", sIn); // prettyPrint("bIn: ", bIn); // // prettyPrint("asks", asks); // prettyPrint("bid", bids); Shout sInTop = null; Shout bInTop = null; final ListIterator<Shout> sItor = sIn.listIterator(); final ListIterator<Shout> bItor = bIn.listIterator(); while (true) { if (sInTop == null) { if (sItor.hasNext()) { sInTop = sItor.next(); if (!asks.remove(sInTop)) { LazyMaxVolumeShoutEngine.logger.fatal("Failed to remove the matched ask !"); LazyMaxVolumeShoutEngine.logger.fatal(sInTop); } // logger.info(sInTop); } else { break; } } if (bInTop == null) { if (bItor.hasNext()) { bInTop = bItor.next(); if (!bids.remove(bInTop)) { LazyMaxVolumeShoutEngine.logger.fatal("Failed to remove the matched bid !"); LazyMaxVolumeShoutEngine.logger.fatal(bInTop); } // logger.info(bInTop); } else { LazyMaxVolumeShoutEngine.logger.fatal("Unempty bInTop expected !"); } } result.add(bInTop); result.add(sInTop); if (bInTop.getPrice() < sInTop.getPrice()) { LazyMaxVolumeShoutEngine.logger.fatal("Wrong match between ask and bid !"); LazyMaxVolumeShoutEngine.logger.fatal(bInTop); LazyMaxVolumeShoutEngine.logger.fatal(sInTop); } final int nS = sInTop.getQuantity(); final int nB = bInTop.getQuantity(); if (nS < nB) { // split the bid bInTop = bInTop.split(nB - nS); sInTop = null; } else if (nB < nS) { // split the ask sInTop = sInTop.split(nS - nB); bInTop = null; } else { bInTop = null; sInTop = null; } } if (bItor.hasNext()) { LazyMaxVolumeShoutEngine.logger .fatal("Inconsistent state of bIn in " + this + ". Empty bItor expected !"); } sIn.clear(); bIn.clear(); // randomize the matching pairs Shout bid, ask; int index; for (int i = result.size() / 2 - 1; i > 0; i--) { // pick a pair to be at the i(th) // TODO: check whether this can lead to mutual access or not. index = uniform.nextIntFromTo(0, i); bid = result.get(i * 2); ask = result.get(i * 2 + 1); result.set(i * 2, result.get(index * 2)); result.set(i * 2 + 1, result.get(index * 2 + 1)); result.set(index * 2, bid); result.set(index * 2 + 1, ask); } return result; }
From source file:com.smi.travel.monitor.MonitorGalileo.java
@Override void buildBookingPassenger(BookingAirline bAir) { String passengerTypes = new String(""); int costRefIndex = 0; String section = galileoMap.get("passenger name").getSection(); MGalileo airNo = galileoMap.get("airline number"); int lineNo = Integer.parseInt(airNo.getLine()); String line = lineData.get(lineNo); String ticketNoS1 = line.substring(airNo.getStartlength() - 1, airNo.getStartlength() - 1 + airNo.getLength()); MGalileo type = galileoMap.get("ticket type"); lineNo = Integer.parseInt(type.getLine()); line = lineData.get(lineNo);/* w w w.j a v a 2s . c o m*/ String ticketType = line.substring(type.getStartlength() - 1, type.getStartlength() - 1 + type.getLength()); ArrayList<String> lines = (ArrayList<String>) sectionData.get(section); // System.out.println("Passenger " + lines.size()); ListIterator<String> iterator = lines.listIterator(); BookingPassenger bp = null; while (iterator.hasNext()) { line = iterator.next(); System.out.println("line-> " + line); String passengerName = getField("passenger name", line).trim(); String passengerType = getField("passenger type", line); if (StringUtils.isEmpty(passengerType) || (!("ADT".equalsIgnoreCase(passengerType)) && !("CHD".equalsIgnoreCase(passengerType)) && !("INF".equalsIgnoreCase(passengerType)))) { passengerType = "NON"; } String[] splitName = passengerName.split("/"); String lastName = splitName[0]; String firstName = splitName[1].substring(0, splitName[1].length() - 2); String initial = splitName[1].substring(splitName[1].length() - 2); String ticketSerial2 = getField("ticket serial2", line); String ticketSerial3 = getField("ticket serial3", line); String fareNo = getField("fare reference", line); String fareSection = galileoMap.get("ticket fare").getSection(); ArrayList<String> fareLines = (ArrayList<String>) sectionData.get(fareSection); String fareLine = fareLines.get(Integer.parseInt(fareNo) - 1); String currency = getField("currency", fareLine); String ticketFare = getTicketFare(currency, fareLine); String ticketTotalS = getField("ticket total", fareLine); ticketTotalS = stripNumberDecimalString(ticketTotalS); ticketFare = stripNumberDecimalString(ticketFare); int tax = Integer.parseInt(ticketTotalS.trim()) - Integer.parseInt(ticketFare.trim()); bp = new BookingPassenger(); bp.setFirstName(firstName); bp.setLastName(lastName); bp.setInitialName(initial); bp.setPassengerType(passengerType); bp.setTicketType(ticketType); bp.setTicketnoS1(ticketNoS1); bp.setTicketnoS2(ticketSerial2); bp.setTicketnoS3(ticketSerial3); bp.setTicketFare(Integer.valueOf(ticketFare.trim())); bp.setTicketTax(Integer.valueOf(tax)); bAir.getBookingPassengers().add(bp); bp.setBookingAirline(bAir); if (!passengerTypes.contains(passengerType)) { passengerTypes = passengerTypes + "," + passengerType; String costS = getField("cost", costRefIndex).trim(); String priceS = getField("price", costRefIndex).trim(); Integer cost = Integer.valueOf(costS); Integer price = Integer.valueOf(priceS); costRefIndex++; //Update cost,price,tax according to passengertype BookingFlight bf = this.getMostEarlyFlight(bAir.getBookingPnr()); if ("ADT".equalsIgnoreCase(passengerType)) { bf.setAdCost(cost); bf.setAdPrice(price); bf.setAdTax(tax); } else if ("CHD".equalsIgnoreCase(passengerType)) { bf.setChCost(cost); bf.setChPrice(price); bf.setChTax(tax); } else if ("INF".equalsIgnoreCase(passengerType)) { bf.setInCost(cost); bf.setInPrice(price); bf.setInTax(tax); } else { bf.setAdCost(cost); bf.setAdPrice(price); bf.setAdTax(tax); } // } } } return; }
From source file:com.smi.travel.monitor.MonitorAmadeus.java
private void buildMap() { listAmadeus = mAmadeusService.getAmadeusList(); ListIterator<MAmadeus> iterator = listAmadeus.listIterator(); amadeusMap = new HashMap(); while (iterator.hasNext()) { MAmadeus ama = iterator.next();// ww w . ja v a 2 s .c o m // System.out.println("Listing " + ama.getName()); amadeusMap.put(ama.getName(), ama); } }
From source file:eu.europa.esig.dss.asic.validation.ASiCContainerValidator.java
private void analyseEntries() throws DSSException { ZipInputStream asicsInputStream = null; try {/*from w w w .j a v a 2s .c o m*/ MimeType asicEntryMimeType = null; asicsInputStream = new ZipInputStream(asicContainer.openStream()); // The underlying stream is closed by the parent (asicsInputStream). for (ZipEntry entry = asicsInputStream.getNextEntry(); entry != null; entry = asicsInputStream .getNextEntry()) { String entryName = entry.getName(); if (isCAdES(entryName)) { if (xadesSigned) { throw new DSSNotETSICompliantException( DSSNotETSICompliantException.MSG.DIFFERENT_SIGNATURE_FORMATS); } addEntryElement(entryName, signatures, asicsInputStream); cadesSigned = true; } else if (isXAdES(entryName)) { if (cadesSigned) { throw new DSSNotETSICompliantException( DSSNotETSICompliantException.MSG.DIFFERENT_SIGNATURE_FORMATS); } addEntryElement(entryName, signatures, asicsInputStream); xadesSigned = true; } else if (isTimestamp(entryName)) { addEntryElement(entryName, signatures, asicsInputStream); timestamped = true; } else if (isASiCManifest(entryName)) { addAsicManifestEntryElement(entryName, detachedContents, asicsInputStream); } else if (isManifest(entryName)) { addEntryElement(entryName, detachedContents, asicsInputStream); } else if (isContainer(entryName)) { addEntryElement(entryName, detachedContents, asicsInputStream); } else if (isMetadata(entryName)) { addEntryElement(entryName, detachedContents, asicsInputStream); } else if (isMimetype(entryName)) { final DSSDocument mimeType = addEntryElement(entryName, detachedContents, asicsInputStream); asicEntryMimeType = getMimeType(mimeType); } else if (entryName.indexOf("/") == -1) { addEntryElement(entryName, detachedContents, asicsInputStream); } else if (entryName.endsWith("/")) { // Folder continue; } else { addEntryElement(entryName, detachedContents, asicsInputStream); } } asicMimeType = determinateAsicMimeType(asicContainer.getMimeType(), asicEntryMimeType); if (MimeType.ASICS == asicMimeType) { final ListIterator<DSSDocument> dssDocumentListIterator = detachedContents.listIterator(); while (dssDocumentListIterator.hasNext()) { final DSSDocument dssDocument = dssDocumentListIterator.next(); final String detachedContentName = dssDocument.getName(); if ("mimetype".equals(detachedContentName)) { dssDocumentListIterator.remove(); } else if (detachedContentName.indexOf('/') != -1) { dssDocumentListIterator.remove(); } } } } catch (Exception e) { if (e instanceof DSSException) { throw (DSSException) e; } throw new DSSException(e); } finally { IOUtils.closeQuietly(asicsInputStream); } }
From source file:org.sakaiproject.gradebookng.tool.panels.SettingsGradingSchemaPanel.java
/** * Build the data for the chart/*from ww w .jav a2 s. c o m*/ * * @return */ private JFreeChart getChartData() { // just need the list final List<CourseGrade> courseGrades = this.courseGradeMap.values().stream().collect(Collectors.toList()); // get current grading schema (from model so that it reflects current state) final List<GbGradingSchemaEntry> gradingSchemaEntries = this.model.getObject().getGradingSchemaEntries(); final DefaultCategoryDataset data = new DefaultCategoryDataset(); final Map<String, Integer> counts = new LinkedHashMap<>(); // must retain order so graph can be printed correctly // add all schema entries (these will be sorted according to {@link LetterGradeComparator}) gradingSchemaEntries.forEach(e -> { counts.put(e.getGrade(), 0); }); // now add the count of each course grade for those schema entries this.total = 0; for (final CourseGrade g : courseGrades) { // course grade may not be released so we have to skip it if (StringUtils.isBlank(g.getMappedGrade())) { continue; } counts.put(g.getMappedGrade(), counts.get(g.getMappedGrade()) + 1); this.total++; } // build the data final ListIterator<String> iter = new ArrayList<>(counts.keySet()).listIterator(0); while (iter.hasNext()) { final String c = iter.next(); data.addValue(counts.get(c), "count", c); } final JFreeChart chart = ChartFactory.createBarChart(null, // the chart title getString("settingspage.gradingschema.chart.xaxis"), // the label for the category (x) axis getString("label.statistics.chart.yaxis"), // the label for the value (y) axis data, // the dataset for the chart PlotOrientation.HORIZONTAL, // the plot orientation false, // show legend true, // show tooltips false); // show urls chart.getCategoryPlot().setRangeAxisLocation(AxisLocation.BOTTOM_OR_RIGHT); chart.setBorderVisible(false); chart.setAntiAlias(false); final CategoryPlot plot = chart.getCategoryPlot(); final BarRenderer br = (BarRenderer) plot.getRenderer(); br.setItemMargin(0); br.setMinimumBarLength(0.05); br.setMaximumBarWidth(0.1); br.setSeriesPaint(0, new Color(51, 122, 183)); br.setBarPainter(new StandardBarPainter()); br.setShadowPaint(new Color(220, 220, 220)); BarRenderer.setDefaultShadowsVisible(true); br.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator(getString("label.statistics.chart.tooltip"), NumberFormat.getInstance())); plot.setRenderer(br); // show only integers in the count axis plot.getRangeAxis().setStandardTickUnits(new NumberTickUnitSource(true)); // make x-axis wide enough so we don't get ... suffix plot.getDomainAxis().setMaximumCategoryLabelWidthRatio(2.0f); plot.setBackgroundPaint(Color.white); chart.setTitle(getString("settingspage.gradingschema.chart.heading")); return chart; }
From source file:umontreal.iro.lecuyer.charts.HistogramChart.java
/** * Synchronizes <SPAN CLASS="MATH"><I>x</I></SPAN>-axis ticks to the <SPAN CLASS="MATH"><I>s</I></SPAN>-th histogram bins. * //from w w w.jav a 2 s . co m * @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 { XAxis.setLabels(((CustomHistogramDataset) this.dataset.getSeriesCollection()).getBinWidth(s)); } }
From source file:edu.iu.daal_nn.NNDaalCollectiveMapper.java
private Tensor getTensorHDFS(DaalContext daal_Context, Configuration conf, String inputFiles, int vectorSize, int numRows) throws IOException { Path inputFilePaths = new Path(inputFiles); List<String> inputFileList = new LinkedList<>(); try {/*www . j a va2s . c om*/ 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 < lineData.length; 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]); Tensor predictionData = new HomogenTensor(daal_Context, dims, data); return predictionData; }
From source file:com.smi.travel.monitor.MonitorAmadeus.java
@Override void buildBookingFlight(BookingAirline bAir) { MAmadeus flightNumber = amadeusMap.get("flight number"); String ticketDateS = getField("ticket date"); String year = "20" + ticketDateS.substring(0, 2); //Check how many rows there is. ArrayList<String> lines = (ArrayList<String>) sectionData.get(flightNumber.getSection()); // System.out.println("Flight " + lines.size()); ListIterator<String> iterator = lines.listIterator(); BookingFlight bf = null;/*from w w w .ja va 2 s . c o m*/ while (iterator.hasNext()) { String line = iterator.next(); if (isVoidFlight(line)) { System.out.println("Skipping - " + line); continue; } // System.out.println("Line " + line); String flightNo = getField("flight number", line); flightNo = bAir.getAirlineCode() + flightNo.replaceAll("\\s+", ""); String sourceCode = getField("source", line); String desCode = getField("destination", line); String deptDateS = getField("departure date", line); String arrivalDateS = getField("arrive date", line); Date deptDate = null; if (!deptDateS.isEmpty()) { deptDate = convertStringToDate(deptDateS + year); } Date arrvDate = null; if (!arrivalDateS.isEmpty()) { arrvDate = convertStringToDate(arrivalDateS + year); } String deptTime = getField("departure time", line); String arrvTime = getField("arrive time", line); String flightClass = getField("flight class", line); bf = new BookingFlight(flightNo, sourceCode, desCode, deptDate, arrvDate, flightClass); bf.setDepartTime(deptTime); bf.setArriveTime(arrvTime); bf.setAdCost(0); bf.setAdPrice(0); bf.setAdTax(0); bf.setChCost(0); bf.setChPrice(0); bf.setChTax(0); bf.setInCost(0); bf.setInPrice(0); bf.setInTax(0); bf.setOtCost(0); bf.setOtPrice(0); bf.setOtTax(0); bAir.getBookingFlights().add(bf); bf.setBookingAirline(bAir); } }