List of usage examples for java.util ListIterator next
E next();
From source file:com.bt.aloha.dialog.state.DialogInfo.java
public void setRouteList(ListIterator<?> recordRouteHeaderIterator, boolean backwards) { routeList = new RouteList(); if (recordRouteHeaderIterator == null) return;// w w w. j av a 2 s .c o m if (backwards) while (recordRouteHeaderIterator.hasNext()) recordRouteHeaderIterator.next(); while (backwards ? recordRouteHeaderIterator.hasPrevious() : recordRouteHeaderIterator.hasNext()) { RecordRouteHeader recordRouteHeader = backwards ? (RecordRouteHeader) recordRouteHeaderIterator.previous() : (RecordRouteHeader) recordRouteHeaderIterator.next(); Route route = new Route(); AddressImpl address = (AddressImpl) ((AddressImpl) recordRouteHeader.getAddress()).clone(); route.setAddress(address); NameValueList nameValueList = new NameValueList(); Iterator<?> paramIterator = recordRouteHeader.getParameterNames(); while (paramIterator.hasNext()) { String paramName = (String) paramIterator.next(); nameValueList.set(paramName, recordRouteHeader.getParameter(paramName)); } route.setParameters(nameValueList); log.debug(String.format("Added route address %s, params %s to route set for dialog %s", address, nameValueList.toString(), getId())); routeList.add(route); } }
From source file:javazoom.jlgui.player.amp.playlist.ui.PlaylistUI.java
/** * Process Drag&Drop//from w ww . j a v a 2 s . c o m * @param data */ public void processDnD(Object data) { log.debug("Playlist DnD"); // Looking for files to drop. if (data instanceof List) { List al = (List) data; if ((al != null) && (al.size() > 0)) { ArrayList fileList = new ArrayList(); ArrayList folderList = new ArrayList(); ListIterator li = al.listIterator(); while (li.hasNext()) { File f = (File) li.next(); if ((f.exists()) && (f.canRead())) { if (f.isFile()) fileList.add(f); else if (f.isDirectory()) folderList.add(f); } } addFiles(fileList); addDirs(folderList); } } else if (data instanceof String) { String files = (String) data; if ((files.length() > 0)) { ArrayList fileList = new ArrayList(); ArrayList folderList = new ArrayList(); StringTokenizer st = new StringTokenizer(files, System.getProperty("line.separator")); // Transfer files dropped. while (st.hasMoreTokens()) { String path = st.nextToken(); if (path.startsWith("file://")) { path = path.substring(7, path.length()); if (path.endsWith("\r")) path = path.substring(0, (path.length() - 1)); } File f = new File(path); if ((f.exists()) && (f.canRead())) { if (f.isFile()) fileList.add(f); else if (f.isDirectory()) folderList.add(f); } } addFiles(fileList); addDirs(folderList); } } else { log.info("Unknown dropped objects"); } }
From source file:vteaexploration.plottools.panels.XYExplorationPanel.java
@Override public XYChartPanel getPanel(int x, int y, int l, int size, String xText, String yText, String lText) { String key = x + "_" + y + "_" + l; if (isMade(x, y, l, size)) { ListIterator<ArrayList> itr = ExplorationItems.listIterator(); String test;/*from w w w . ja v a2s .com*/ while (itr.hasNext()) { test = itr.next().get(0).toString(); if (key.equals(test)) { return (XYChartPanel) itr.next().get(1); } } } return createChartPanel(x, y, l, xText, yText, lText, pointsize, impoverlay, imageGate, imageGateColor); }
From source file:vteaexploration.plottools.panels.XYExplorationPanel.java
@Override public Gate getGates(int x, int y, int l, int size) { String key = x + "_" + y; if (isMade(x, y, l, size)) { ListIterator<ArrayList> itr = ExplorationItems.listIterator(); String test;/*from w w w . j a v a2s . c o m*/ while (itr.hasNext()) { test = itr.next().get(0).toString(); if (key.equals(test)) { return (Gate) itr.next().get(1); } } } return null; }
From source file:at.ofai.music.util.WormFileParseException.java
public void insert(Event newEvent, boolean uniqueTimes) { ListIterator<Event> li = l.listIterator(); while (li.hasNext()) { int sgn = newEvent.compareTo(li.next()); if (sgn < 0) { li.previous();// w w w .j a va 2s . co m break; } else if (uniqueTimes && (sgn == 0)) { li.remove(); break; } } li.add(newEvent); }
From source file:vteaexploration.plottools.panels.XYExplorationPanel.java
@Override public int getGatedSelected(ImagePlus ip) { ArrayList<MicroObject> ImageGatedObjects = new ArrayList<MicroObject>(); ArrayList<MicroObject> volumes = (ArrayList) plotvalues.get(1); try {//from www. ja v a2 s . c om ListIterator<MicroObject> itr = volumes.listIterator(); while (itr.hasNext()) { MicroObject m = itr.next(); int[] c = new int[2]; c = m.getBoundsCenter(); if (ip.getRoi().contains(c[0], c[1])) { ImageGatedObjects.add(m); } } } catch (NullPointerException e) { return 0; } Gate gate; ListIterator<Gate> gate_itr = gates.listIterator(); ArrayList<MicroObject> result = new ArrayList<MicroObject>(); while (gate_itr.hasNext()) { gate = gate_itr.next(); if (gate.getSelected()) { Path2D path = gate.createPath2DInChartSpace(); MicroObjectModel volume; double xValue = 0; double yValue = 0; ListIterator<MicroObject> it = ImageGatedObjects.listIterator(); try { while (it.hasNext()) { volume = it.next(); if (volume != null) { xValue = ((Number) processPosition(currentX, (MicroObject) volume)).doubleValue(); yValue = ((Number) processPosition(currentY, (MicroObject) volume)).doubleValue(); if (path.contains(xValue, yValue)) { result.add((MicroObject) volume); } } } } catch (NullPointerException e) { return 0; } } } return result.size(); }
From source file:chat.viska.commons.pipelines.Pipeline.java
private void processObject(final Object obj, final boolean isReading) { final ListIterator<Map.Entry<String, Pipe>> iterator = isReading ? pipes.listIterator() : pipes.listIterator(pipes.size()); final List<Object> cache = new ArrayList<>(); cache.add(obj);/*w ww . ja va2s .c o m*/ while (isReading ? iterator.hasNext() : iterator.hasPrevious()) { final Pipe pipe = isReading ? iterator.next().getValue() : iterator.previous().getValue(); final List<Object> toForward = new ArrayList<>(); for (Object it : cache) { final List<Object> out = new ArrayList<>(); try { if (isReading) { pipe.onReading(this, it, out); } else { pipe.onWriting(this, it, out); } } catch (Exception cause) { processException(iterator, cause, isReading); return; } toForward.addAll(out); } if (toForward.size() == 0) { return; } else { cache.clear(); cache.addAll(toForward); } } for (Object it : cache) { try { if (isReading) { inboundStream.onNext((I) it); } else { outboundStream.onNext((O) it); } } catch (ClassCastException ex) { continue; } } }
From source file:com.smi.travel.monitor.MonitorAmadeus.java
@Override void buildBookingPassenger(BookingAirline bAir) { String passengerTypes = new String(""); int costRefIndex = 0; MAmadeus pName = amadeusMap.get("passenger name"); ArrayList<String> lines = (ArrayList<String>) sectionData.get(pName.getSection()); // System.out.println("Passenger " + lines.size()); String ticketType = getField("ticket type"); ListIterator<String> iterator = lines.listIterator(); String line = null;//from w ww. j a v a 2s .c o m BookingPassenger bp = null; while (iterator.hasNext()) { line = iterator.next(); // System.out.println("line-> " + line); String[] mline = line.split("\\r?\\n"); String passengerName = getField("passenger name", mline[0]).trim(); // String passengerType = getField("passenger type", mline[0]); // if (StringUtils.isEmpty(passengerType) // || !("ADT".equalsIgnoreCase(passengerType)) // || !("CHD".equalsIgnoreCase(passengerType)) // || !("INF".equalsIgnoreCase(passengerType))) { // passengerType = "NON"; // } MAmadeus ticketNo1Ama = amadeusMap.get("ticket serial1"); String section = ticketNo1Ama.getSection(); String ticketLine = null; for (int i = 1; i < mline.length; i++) { if (mline[i].startsWith(section)) { ticketLine = mline[i]; break; } } // System.out.println("Ticket ->" + ticketLine); String ticketNo1 = getField("ticket serial1", ticketLine); String ticketNo2 = getField("ticket serial2", ticketLine); String ticketNo3 = getField("ticket serial3", ticketLine); // System.out.println("passengerName " + passengerName); String[] splitName = passengerName.split("/"); String lastName = splitName[0]; String[] splitName2 = splitName[1].split(" "); // Using nameSeparatorIndex to handle case of blank space in first name. int nameSeparatorIndex = splitName[1].lastIndexOf(" "); String firstName = splitName[1].substring(0, nameSeparatorIndex); // String firstName = splitName[1].substring(0, splitName[1].length() - 2); // String initial = splitName[1].substring(splitName[1].length() - 2); String initial; String passengerType; if (!splitName2[1].contains("(")) { // plus 1 to exclude blankspace index. initial = splitName[1].substring(nameSeparatorIndex + 1); passengerType = "ADT"; } else { int indexLess = splitName2[1].indexOf("("); int indexMore = splitName2[1].indexOf(")"); initial = splitName2[1].substring(0, indexLess); passengerType = splitName2[1].substring(indexLess + 1, indexMore); } MAmadeus fareComAma = amadeusMap.get("fare commission"); String fareSection = fareComAma.getSection(); String fareLine = null; for (int i = 1; i < mline.length; i++) { if (mline[i].startsWith(fareSection)) { fareLine = mline[i]; break; } } String fareCommission; if (fareLine == null) { fareCommission = "0"; } else { fareCommission = getField("fare commission", fareLine).trim(); fareCommission = fareCommission.replace("A", ""); } String currency = getField("currency").trim(); String ticket_fare = getTicketFare(currency); // String ticket_fare = getField("ticket fare").trim(); ticket_fare = stripNumberDecimalString(ticket_fare); String total_amount = getField("ticket total").trim(); int tax = Integer.valueOf(total_amount) - Integer.valueOf(ticket_fare); if (tax < 0) { tax = tax * (-1); } // System.out.println("lastname [" + lastName + "] ,firstname[" + firstName + "] ,initial[" + initial + "] passengerType[" + passengerType + "]"); bp = new BookingPassenger(); bp.setFirstName(firstName); bp.setLastName(lastName); bp.setInitialName(initial); bp.setPassengerType(passengerType); bp.setTicketType(ticketType); bp.setTicketnoS1(ticketNo1);//ticketNoS1); bp.setTicketnoS2(ticketNo2); bp.setTicketnoS3(ticketNo3); bp.setTicketFare(Integer.valueOf(ticket_fare)); bp.setTicketTax(tax); bAir.getBookingPassengers().add(bp); bp.setBookingAirline(bAir); if (!passengerTypes.contains(passengerType)) { passengerTypes = passengerTypes + "," + passengerType; Integer cost; Integer price; if (isInternationalTicket(ticketType)) { String costS = getField("cost").trim(); // No cost line. Set to ticket_fare. if ("0".equalsIgnoreCase(costS)) { costS = ticket_fare; } cost = Integer.valueOf(costS); System.out.println("cost [" + cost + "]"); price = cost + Integer.valueOf(fareCommission); } else { price = Integer.valueOf(ticket_fare); cost = (price * 95) / 100; } costRefIndex++; //Update cost,price,tax according to passengertype // Only first flight BookingFlight bf = (BookingFlight) bAir.getBookingFlights().iterator().next(); // 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); } // } } } }
From source file:com.net2plan.cli.tools.CLITrafficDesign.java
@Override public void executeFromCommandLine(String[] args) throws ParseException { long init = System.nanoTime(); final CommandLineParser parser = new CommandLineParser(); final CommandLine cli = parser.parse(OPTIONS, args); int numNodes; NetPlan netPlan;/*w ww. j a va2s. co m*/ if (cli.hasOption("num-nodes") && cli.hasOption("input-file")) throw new ParseException("'num-nodes' and 'input-file' are mutually exclusive"); if (cli.hasOption("num-nodes")) { numNodes = ((Number) cli.getParsedOptionValue("num-nodes")).intValue(); if (numNodes < 2) throw new Net2PlanException("Traffic matrix requires at least 2 nodes"); netPlan = new NetPlan(); for (int n = 0; n < numNodes; n++) netPlan.addNode(0, 0, null, null); } else { netPlan = new NetPlan((File) cli.getParsedOptionValue("input-file")); numNodes = netPlan.getNumberOfNodes(); } int numMatrices = 1; String trafficPattern = null; DoubleMatrix2D[] trafficMatrices; if (cli.hasOption("variation-pattern")) { if (!cli.hasOption("num-matrices")) throw new Net2PlanException("'num-matrices' parameters must be specified"); numMatrices = ((Number) cli.getParsedOptionValue("num-matrices")).intValue(); if (numMatrices < 1) throw new Net2PlanException("Number of traffic matrices must be positive"); DoubleMatrix2D trafficMatrix = netPlan.getMatrixNode2NodeOfferedTraffic(); List<DoubleMatrix2D> newMatrices; String variationPattern = (String) cli.getParsedOptionValue("variation-pattern"); switch (variationPattern) { case "cagr": { double cagr = ((Number) cli.getParsedOptionValue("variation-pattern-cagr")).doubleValue(); if (cagr <= 0) throw new Net2PlanException("Compound annual growth rate must be greater than zero"); newMatrices = TrafficMatrixGenerationModels.computeMatricesCAGR(trafficMatrix, cagr, numMatrices); break; } case "randomGaussian": { double cv = ((Number) cli.getParsedOptionValue("variation-pattern-cv")).doubleValue(); double maxRelativeVariation = ((Number) cli .getParsedOptionValue("variation-pattern-maxRelativeVariation")).doubleValue(); if (cv <= 0) throw new Net2PlanException("Coefficient of variation must be greater than zero"); if (maxRelativeVariation <= 0) throw new Net2PlanException("Maximum relative variation must be greater than zero"); newMatrices = TrafficMatrixGenerationModels.computeMatricesRandomGaussianVariation(trafficMatrix, cv, maxRelativeVariation, numMatrices); break; } case "randomUniform": { double maxRelativeVariation = ((Number) cli .getParsedOptionValue("variation-pattern-maxRelativeVariation")).doubleValue(); if (maxRelativeVariation <= 0) throw new Net2PlanException("Maximum relative variation must be greater than zero"); newMatrices = TrafficMatrixGenerationModels.computeMatricesRandomUniformVariation(trafficMatrix, maxRelativeVariation, numMatrices); break; } default: throw new RuntimeException("Bad - Unknown variation pattern '" + variationPattern + "'"); } trafficMatrices = new DoubleMatrix2D[numMatrices]; int i = 0; for (DoubleMatrix2D trafficMatrix1 : newMatrices) trafficMatrices[i++] = trafficMatrix1; } else { if (cli.hasOption("traffic-pattern")) { trafficPattern = cli.getOptionValue("traffic-pattern"); if (!TRAFFIC_PATTERNS.containsKey(trafficPattern)) throw new Net2PlanException("Unknown traffic pattern"); if (cli.hasOption("num-matrices")) { numMatrices = ((Number) cli.getParsedOptionValue("num-matrices")).intValue(); if (numMatrices < 1) throw new Net2PlanException("Number of traffic matrices must be positive"); } } trafficMatrices = new DoubleMatrix2D[numMatrices]; if (trafficPattern != null) { switch (trafficPattern) { case "uniform-random-10": for (int tmId = 0; tmId < numMatrices; tmId++) trafficMatrices[tmId] = TrafficMatrixGenerationModels.uniformRandom(numNodes, 0, 10); break; case "uniform-random-100": for (int tmId = 0; tmId < numMatrices; tmId++) trafficMatrices[tmId] = TrafficMatrixGenerationModels.uniformRandom(numNodes, 0, 100); break; case "uniform-random-bimodal-50-50": for (int tmId = 0; tmId < numMatrices; tmId++) trafficMatrices[tmId] = TrafficMatrixGenerationModels.bimodalUniformRandom(numNodes, 0.5, 0, 100, 0, 10); break; case "uniform-random-bimodal-25-75": for (int tmId = 0; tmId < numMatrices; tmId++) trafficMatrices[tmId] = TrafficMatrixGenerationModels.bimodalUniformRandom(numNodes, 0.25, 0, 100, 0, 10); break; case "population-distance-model": double randomFactor = 0; double populationOffset = 0; double populationPower = 1; double distanceOffset = 0; double distancePower = 1; boolean normalizePopulation = true; boolean normalizeDistance = true; if (cli.hasOption("random-factor")) randomFactor = ((Number) cli.getParsedOptionValue("random-factor")).doubleValue(); if (cli.hasOption("population-offset")) populationOffset = ((Number) cli.getParsedOptionValue("population-offset")).doubleValue(); if (cli.hasOption("population-power")) populationPower = ((Number) cli.getParsedOptionValue("population-power")).doubleValue(); if (cli.hasOption("distance-offset")) distanceOffset = ((Number) cli.getParsedOptionValue("distance-offset")).doubleValue(); if (cli.hasOption("distance-power")) distancePower = ((Number) cli.getParsedOptionValue("distance-power")).doubleValue(); if (cli.hasOption("normalize-population")) normalizePopulation = Boolean.parseBoolean(cli.getOptionValue("normalize-population")); if (cli.hasOption("normalize-distance")) normalizeDistance = Boolean.parseBoolean(cli.getOptionValue("normalize-distance")); if (!cli.hasOption("level-matrix-file")) throw new Net2PlanException("The level-matrix file is required"); DoubleMatrix2D levelMatrix = DoubleUtils .read2DMatrixFromFile((File) cli.getParsedOptionValue("level-matrix-file")); DoubleMatrix2D distanceMatrix = netPlan.getMatrixNode2NodeEuclideanDistance(); int[] populationVector = StringUtils .toIntArray(netPlan.getAttributes(netPlan.getNodes(), "population").values(), 0); int[] levelVector = StringUtils .toIntArray(netPlan.getAttributes(netPlan.getNodes(), "level").values(), 1); for (int tmId = 0; tmId < numMatrices; tmId++) trafficMatrices[tmId] = TrafficMatrixGenerationModels.populationDistanceModel( distanceMatrix, populationVector, levelVector, levelMatrix, randomFactor, populationOffset, populationPower, distanceOffset, distancePower, normalizePopulation, normalizeDistance); break; case "gravity-model": if (cli.hasOption("gravity-model-file")) { File gravityModelFile = (File) cli.getParsedOptionValue("gravity-model-file"); DoubleMatrix2D gravityModelMatrix = DoubleUtils.read2DMatrixFromFile(gravityModelFile); if (gravityModelMatrix.rows() != numNodes || gravityModelMatrix.columns() != 2) throw new Net2PlanException( "'gravity-model-file' requires " + numNodes + " rows and two columns"); numMatrices = 1; trafficMatrices[0] = TrafficMatrixGenerationModels.gravityModel( gravityModelMatrix.viewColumn(0).toArray(), gravityModelMatrix.viewColumn(1).toArray()); } else { throw new Net2PlanException("Parameter 'gravity-model-file' should be specified"); } break; default: throw new RuntimeException("Bad - Unknown traffic pattern '" + trafficPattern + "'"); } } else { trafficMatrices[0] = netPlan.getMatrixNode2NodeOfferedTraffic(); } if (cli.hasOption("normalization-pattern")) { String normalizationPattern = (String) cli.getParsedOptionValue("normalization-pattern"); switch (normalizationPattern) { case "total-normalization": case "row-normalization": case "column-normalization": if (cli.hasOption("normalization-pattern-file")) { double[] normalizationPatternVector; int patternId; File normalizationPatternFile = (File) cli .getParsedOptionValue("normalization-pattern-file"); DoubleMatrix2D normalizationPatternMatrix = DoubleUtils .read2DMatrixFromFile(normalizationPatternFile); if (normalizationPatternMatrix.rows() == 1 && normalizationPatternMatrix.columns() == 1) { patternId = 0; normalizationPatternVector = new double[] { normalizationPatternMatrix.getQuick(0, 0) }; } else if (normalizationPatternMatrix.rows() == 1 && normalizationPatternMatrix.columns() > 1) { patternId = 1; normalizationPatternVector = normalizationPatternMatrix.viewRow(0).toArray(); } else if (normalizationPatternMatrix.rows() > 1 && normalizationPatternMatrix.columns() == 1) { patternId = 2; normalizationPatternVector = normalizationPatternMatrix.viewColumn(0).toArray(); } else { throw new Net2PlanException( "Bad normalization pattern - Neither a scalar (for total normalization), nor row vector (for row normalization) nor a column vector (for column normalization) was provided"); } for (int tmId = 0; tmId < numMatrices; tmId++) { switch (patternId) { case 0: trafficMatrices[tmId] = TrafficMatrixGenerationModels .normalizationPattern_totalTraffic(trafficMatrices[tmId], normalizationPatternVector[0]); break; case 1: trafficMatrices[tmId] = TrafficMatrixGenerationModels .normalizationPattern_incomingTraffic(trafficMatrices[tmId], normalizationPatternVector); break; case 2: trafficMatrices[tmId] = TrafficMatrixGenerationModels .normalizationPattern_outgoingTraffic(trafficMatrices[tmId], normalizationPatternVector); break; default: throw new RuntimeException("Bad"); } } } else { throw new Net2PlanException("Parameter 'normalization-pattern-file' should be specified"); } break; case "max-traffic-estimated-minHop": for (int tmId = 0; tmId < numMatrices; tmId++) { netPlan.setTrafficMatrix(trafficMatrices[tmId]); netPlan.setVectorDemandOfferedTraffic( TrafficMatrixGenerationModels.normalizeTraffic_networkCapacity(netPlan)); trafficMatrices[tmId] = netPlan.getMatrixNode2NodeOfferedTraffic(); } break; case "max-traffic-exact": String solverName = Configuration.getOption("defaultILPSolver"); String solverLibraryName = Configuration.getDefaultSolverLibraryName(solverName); // if (solverName.equalsIgnoreCase("glpk")) solverLibraryName = Configuration.getOption("glpkSolverLibraryName"); // else if (solverName.equalsIgnoreCase("ipopt")) solverLibraryName = Configuration.getOption("ipoptSolverLibraryName"); // else if (solverName.equalsIgnoreCase("cplex")) solverLibraryName = Configuration.getOption("cplexSolverLibraryName"); // else if (solverName.equalsIgnoreCase("xpress")) solverLibraryName = Configuration.getOption("xpressSolverLicenseFileName"); // for (int tmId = 0; tmId < numMatrices; tmId++) { netPlan.setTrafficMatrix(trafficMatrices[tmId]); netPlan.setVectorDemandOfferedTraffic(TrafficMatrixGenerationModels .normalizeTraffic_linkCapacity_xde(netPlan, solverName, solverLibraryName)); trafficMatrices[tmId] = netPlan.getMatrixNode2NodeOfferedTraffic(); } break; default: throw new RuntimeException( "Bad - Unknown normalization pattern '" + normalizationPattern + "'"); } } } List<NetPlan> outputDemandSets = new LinkedList<NetPlan>(); for (int tmId = 0; tmId < numMatrices; tmId++) { NetPlan aux = new NetPlan(); aux.setTrafficMatrix(trafficMatrices[tmId]); outputDemandSets.add(aux); trafficMatrices[tmId] = null; } File outputFile = (File) cli.getParsedOptionValue("output-file"); if (outputDemandSets.size() == 1) { outputDemandSets.get(0).saveToFile(outputFile); } else { String templateFileName = outputFile.getAbsoluteFile().toString(); if (templateFileName.endsWith(".n2p")) templateFileName = templateFileName.substring(0, templateFileName.lastIndexOf('.')); ListIterator<NetPlan> netPlanIt = outputDemandSets.listIterator(); while (netPlanIt.hasNext()) netPlanIt.next().saveToFile(new File(templateFileName + "_tm" + netPlanIt.nextIndex() + ".n2p")); } long end = System.nanoTime(); System.out.println(String.format("%n%nTraffic matrix generation finished successfully in %f seconds", (end - init) / 1e9)); }