List of usage examples for java.util Scanner hasNext
public boolean hasNext()
From source file:marytts.tools.dbselection.WikipediaMarkupCleaner.java
private StringBuffer removeSectionTable(Scanner s, StringBuffer lineIn, String iniTag, String endTag) { String next;/*from www.j ava 2s . c o m*/ int index1 = 0, index2 = -1, endTagLength = 0, numRef = 0, lastEndTag = 0, lastIniTag = 0; boolean closeRef = true; StringBuffer line = new StringBuffer(lineIn); StringBuffer nextLine; if (debug) System.out.println("Removing tag: " + iniTag + " LINE (BEFORE): " + line); while ((index1 = line.indexOf(iniTag)) >= 0) { // in one line can be more than one iniTag numRef++; if ((index2 = line.indexOf(endTag, index1)) >= 0) endTagLength = endTag.length() + index2; if (index2 == -1) {// the iniTag most be in the next lines, so get more lines until the endTag is found lastEndTag = 0; // start to look for the endTag in 0 while (s.hasNext() && numRef != 0) { lastIniTag = 0; nextLine = new StringBuffer(s.nextLine()); //if(debug) // System.out.println(" NEXTLINE: " + nextLine); while ((index1 = nextLine.indexOf(iniTag, lastIniTag)) >= 0) { numRef++; lastIniTag = iniTag.length() + index1; } // next time it will look for the endTag after the position of the last it found. //while( (index2 = line.indexOf(endTag, lastEndTag)) >= 0 ){ if (nextLine.toString().startsWith(endTag)) { numRef--; //index2 = line.length(); //lastEndTag = index2 + endTag.length(); // I need to remember where the last endTag was found endTagLength = line.length() + endTag.length(); } line.append(nextLine); //if(debug) // System.out.println("LINE (numRef=" + numRef + "): " + line); } } else // the endTag was found numRef--; if (numRef == 0) { index1 = line.indexOf(iniTag); // get again this because the position might change if (endTagLength > index1) { if (debug) { System.out.println(" FINAL LINE: " + line); System.out.print("iniTag: " + iniTag + " index1=" + index1); System.out.print(" endTagLength=" + endTagLength); System.out.println(" line.length=" + line.length() + " line: " + line); System.out.println(" line.length=" + line.length()); } line.delete(index1, endTagLength); } else { if (debug) { System.out.println("removeSection: WARNING endTagLength > length of line: "); System.out.print("iniTag: " + iniTag + " index1=" + index1); System.out.print(" endTagLength=" + endTagLength); System.out.println(" line.length=" + line.length() + " line: " + line); System.out.println("removeSection: WARNING endTagLength > length of line: " + line); } line = new StringBuffer(""); } //System.out.println("nextline="+line); } else { if (debug) System.out.println("removeSection: WARNING no " + endTag); line = new StringBuffer(""); } } // while this line contains iniTag-s if (debug) System.out.println(" LINE (AFTER): " + line); return line; }
From source file:unalcol.termites.boxplots.SucessfulRatesGlobal.java
private static CategoryDataset createDataset(ArrayList<Double> Pf) { DefaultCategoryDataset defaultcategorydataset = new DefaultCategoryDataset(); String sDirectorio = "..\\results\\"; File f = new File(sDirectorio); String extension;/*from w w w.j a va 2 s .c o m*/ File[] files = f.listFiles(); Hashtable<String, String> Pop = new Hashtable<>(); PrintWriter escribir; Scanner sc = null; double sucessfulExp = 0.0; Hashtable<String, List> info = new Hashtable(); //String[] aMode = {"levywalk", "lwphevap", "hybrid", "hybrid3", "hybrid4"}; info.put("levywalk", new ArrayList()); info.put("lwphevap", new ArrayList()); info.put("hybrid", new ArrayList()); //info.put("hybrid3", new ArrayList()); //info.put("hybrid4", new ArrayList()); info.put("sequential", new ArrayList()); for (File file : files) { extension = ""; int i = file.getName().lastIndexOf('.'); int p = Math.max(file.getName().lastIndexOf('/'), file.getName().lastIndexOf('\\')); if (i > p) { extension = file.getName().substring(i + 1); } // System.out.println(file.getName() + "extension" + extension); if (file.isFile() && extension.equals("csv") && file.getName().startsWith("dataCollected") && file.getName().contains("mazeon")) { System.out.println(file.getName()); System.out.println("get: " + file.getName()); String[] filenamep = file.getName().split(Pattern.quote("+")); System.out.println("file" + filenamep[8]); int popsize = Integer.valueOf(filenamep[3]); double pf = Double.valueOf(filenamep[5]); String mode = filenamep[7]; int maxIter = -1; //if (!filenamep[8].isEmpty()) { maxIter = Integer.valueOf(filenamep[9]); //} System.out.println("psize:" + popsize); System.out.println("pf:" + pf); System.out.println("mode:" + mode); System.out.println("maxIter:" + maxIter); //String[] aMode = {"random", "levywalk", "sandc", "sandclw"}; //String[] aMode = {"lwphclwevap", "lwsandc2", "lwsandc", "lwphevap2", "lwphevap"}; // String[] aMode = {"levywalk", "lwphevap", "hybrid"}; //String[] aMode = {"levywalk", "lwphevap", "hybrid", "hybrid3", "hybrid4", "sequential"}; String[] aMode = { "levywalk", "lwphevap", "hybrid", "sequential" }; if (isInMode(aMode, mode)) { final List list = new ArrayList(); try { sc = new Scanner(file); } catch (FileNotFoundException ex) { Logger.getLogger(DataCollectedLatexConsolidatorSASOMessagesSend1.class.getName()) .log(Level.SEVERE, null, ex); } int roundNumber = 0; double globalInfoCollected = 0; String[] data = null; while (sc.hasNext()) { String line = sc.nextLine(); data = line.split(","); //System.out.println("data"); roundNumber = Integer.valueOf(data[0]); globalInfoCollected = Double.valueOf(data[4]); if (globalInfoCollected >= 90 && Pf.contains(pf)) { info.get(mode).add(roundNumber); break; } } } } } for (String key : info.keySet()) { System.out.println(key + ":" + info.get(key).size() / 30 * 100.0); defaultcategorydataset.addValue(info.get(key).size() / 30.0 * 100.0, "", getTechniqueName(key)); } return defaultcategorydataset; }
From source file:com.flexive.core.storage.genericSQL.GenericTreeStorage.java
/** * {@inheritDoc}// w w w .j ava 2 s . co m */ @Override public long[] createNodes(Connection con, SequencerEngine seq, ContentEngine ce, FxTreeMode mode, long parentNodeId, String path, int position, boolean activateContent) throws FxApplicationException { if ("/".equals(path)) return new long[] { FxTreeNode.ROOT_NODE }; final List<Long> result = new ArrayList<Long>(); final Scanner scanner = new Scanner(path); long currentParent = parentNodeId; scanner.useDelimiter("/"); if (parentNodeId != -1) { acquireLocksForUpdate(con, getTreeNodeInfo(con, mode, parentNodeId), false); } while (scanner.hasNext()) { String name = scanner.next(); final FxString label = new FxString(true, name); name = FxFormatUtils.escapeTreePath(name); if (StringUtils.isEmpty(name)) continue; long nodeId = getIdByFQNPath(con, mode, currentParent, "/" + name); if (nodeId == -1) nodeId = createNode(con, seq, ce, mode, nodeId, currentParent, name, label, position, null, null, activateContent); result.add(nodeId); currentParent = nodeId; } return ArrayUtils.toPrimitive(result.toArray(new Long[result.size()])); }
From source file:ehospital.Principal.java
private void btn_cargar_ambuMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btn_cargar_ambuMouseClicked // TODO add your handling code here: Scanner sc = null; File archivo2;/*from w ww.j ava 2s . co m*/ try { archivo2 = new File("./Ambulancia.txt"); sc = new Scanner(archivo2); sc.useDelimiter(","); while (sc.hasNext()) { Ambulancias ambu = new Ambulancias(sc.next(), sc.nextInt(), sc.nextInt(), new Lugar(sc.next()), sc.nextBoolean()); lista_ambu.add(ambu); } JOptionPane.showMessageDialog(null, "Ambulancias Cargadas"); } catch (Exception e) { } finally { sc.close(); } System.out.println(lista_ambu.toString()); }
From source file:ehospital.Principal.java
private void btn_cargar_paramMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btn_cargar_paramMouseClicked // TODO add your handling code here: Scanner sc = null; File archivo2;/*from w w w . j a v a 2s . co m*/ try { archivo2 = new File("./Paramedicos.txt"); sc = new Scanner(archivo2); sc.useDelimiter(","); while (sc.hasNext()) { Paramedicos param = new Paramedicos(sc.next(), sc.nextInt(), sc.nextInt(), sc.next(), new Lugar(sc.next()), sc.nextBoolean()); lista_param.add(param); } JOptionPane.showMessageDialog(null, "Paramedicos Cargadas"); } catch (Exception e) { } finally { sc.close(); } System.out.println(lista_param.toString()); }
From source file:unalcol.termites.boxplots.SucessfulRates.java
private static CategoryDataset createDataset(ArrayList<Double> Pf) { DefaultCategoryDataset defaultcategorydataset = new DefaultCategoryDataset(); String sDirectorio = experimentsDir; File f = new File(sDirectorio); String extension;//www . j a v a2s . c om File[] files = f.listFiles(); Hashtable<String, String> Pop = new Hashtable<>(); PrintWriter escribir; Scanner sc = null; double sucessfulExp = 0.0; for (File file : files) { extension = ""; int i = file.getName().lastIndexOf('.'); int p = Math.max(file.getName().lastIndexOf('/'), file.getName().lastIndexOf('\\')); if (i > p) { extension = file.getName().substring(i + 1); } // System.out.println(file.getName() + "extension" + extension); if (file.isFile() && extension.equals("csv") && file.getName().startsWith("experiment") && file.getName().contains(mazeMode)) { System.out.println(file.getName()); System.out.println("get: " + file.getName()); String[] filenamep = file.getName().split(Pattern.quote("+")); System.out.println("file" + filenamep[8]); int popsize = Integer.valueOf(filenamep[2]); double pf = Double.valueOf(filenamep[4]); String mode = filenamep[6]; int maxIter = -1; //if (!filenamep[8].isEmpty()) { maxIter = Integer.valueOf(filenamep[8]); //} System.out.println("psize:" + popsize); System.out.println("pf:" + pf); System.out.println("mode:" + mode); System.out.println("maxIter:" + maxIter); //String[] aMode = {"random", "levywalk", "sandc", "sandclw"}; //String[] aMode = {"lwphclwevap", "lwsandc2", "lwsandc", "lwphevap2", "lwphevap"}; // String[] aMode = {"levywalk", "lwphevap", "hybrid"}; //String[] aMode = {"levywalk", "lwphevap", "hybrid", "hybrid3", "hybrid4", "sequential"}; if (isInMode(aMode, mode)) { final List list = new ArrayList(); try { sc = new Scanner(file); } catch (FileNotFoundException ex) { Logger.getLogger(DataCollectedLatexConsolidatorSASOMessagesSend1.class.getName()) .log(Level.SEVERE, null, ex); } int agentsCorrect = 0; int worldSize = 0; double averageExplored = 0.0; int bestRoundNumber = 0; double avgSend = 0; double avgRecv = 0; double avgdataExplInd = 0; ArrayList<Double> acSt = new ArrayList<>(); ArrayList<Double> avgExp = new ArrayList<>(); ArrayList<Double> bestR = new ArrayList<>(); ArrayList<Double> avSnd = new ArrayList<>(); ArrayList<Double> avRecv = new ArrayList<>(); ArrayList<Double> avIndExpl = new ArrayList<>(); String[] data = null; while (sc.hasNext()) { String line = sc.nextLine(); //System.out.println("line:" + line); data = line.split(","); agentsCorrect = Integer.valueOf(data[0]); //agentsIncorrect = Integer.valueOf(data[1]); // not used worldSize = Integer.valueOf(data[3]); averageExplored = Double.valueOf(data[4]); // data[3] stdavgExplored - not used bestRoundNumber = Integer.valueOf(data[6]); avgSend = Double.valueOf(data[7]); avgRecv = Double.valueOf(data[8]); avgdataExplInd = Double.valueOf(data[11]); //Add Data and generate statistics acSt.add((double) agentsCorrect); avgExp.add(averageExplored); avSnd.add(avgSend); avRecv.add(avgRecv); avIndExpl.add(avgdataExplInd); sucessfulExp = 0.0; for (int j = 0; j < acSt.size(); j++) { if (acSt.get(j) > 0) { sucessfulExp++; } } } if (Pf.contains(pf)) { defaultcategorydataset.addValue(((double) sucessfulExp) / acSt.size() * 100.0, "" + popsize, getTechniqueName(mode) + "\nPf:" + pf); /*pf == 1.0E-4 || pf == 3.0E-4*/ } } } } return defaultcategorydataset; }
From source file:unalcol.termites.boxplots.BestAgentsPercentageInfoCollected.java
private void AddDataFailingExperiments(String sDirectorio, ArrayList<Double> Pf, Hashtable<String, List> info) { File f = new File(sDirectorio); String extension;// w w w . j a va 2s.c o m File[] files = f.listFiles(); Hashtable<String, String> Pop = new Hashtable<>(); Scanner sc = null; ArrayList<Integer> aPops = new ArrayList<>(); ArrayList<Double> aPf = new ArrayList<>(); ArrayList<String> aTech = new ArrayList<>(); for (File file : files) { List list = new ArrayList(); extension = ""; int i = file.getName().lastIndexOf('.'); int p = Math.max(file.getName().lastIndexOf('/'), file.getName().lastIndexOf('\\')); if (i > p) { extension = file.getName().substring(i + 1); } // System.out.println(file.getName() + "extension" + extension); if (file.isFile() && extension.equals("csv") && file.getName().startsWith("failInfo") && file.getName().contains(mazeMode)) { //System.out.println(file.getName()); //System.out.println("get: " + file.getName()); String[] filenamep = file.getName().split(Pattern.quote("+")); //System.out.println("file" + filenamep[8]); int popsizef = Integer.valueOf(filenamep[3]); double pff = Double.valueOf(filenamep[5]); String modef = filenamep[7]; int worldSize = Integer.valueOf(filenamep[11]) * Integer.valueOf(filenamep[13]); /*System.out.println("psizef:" + popsizef); System.out.println("pff:" + pff); System.out.println("modef:" + modef); */ // String[] aMode = {"turnoncontact", "lwsandc2", "lwsandc", "lwphevap2", "lwphevap"}; try { sc = new Scanner(file); } catch (FileNotFoundException ex) { Logger.getLogger(DataCollectedLatexConsolidatorSASOMessagesSend1.class.getName()) .log(Level.SEVERE, null, ex); } int agentId = -1; int countLines = 0; int roundNumber = -1; int infoCollected = -1; String[] data = null; while (sc.hasNext()) { String line = sc.nextLine(); //System.out.println("line:" + line); data = line.split(","); agentId = Integer.valueOf(data[0]); roundNumber = Integer.valueOf(data[1]); if (infoCollected < Integer.valueOf(data[2])) { infoCollected = Integer.valueOf(data[2]); } countLines++; } //System.out.println("lines" + countLines); if (countLines == popsizef && infoCollected != -1 && (Pf.contains(pff))) { double datas = ((infoCollected * 1.0) / worldSize) * 100.0; if (info.get(modef + "+" + popsizef) == null) { info.put((modef + "+" + popsizef), new ArrayList<Integer>()); } info.get(modef + "+" + popsizef).add(datas); } LOGGER.debug("Adding series " + i); LOGGER.debug(list.toString()); } } System.out.println("info" + info); }
From source file:unalcol.termites.boxplots.BestAgentsRoundInfoCollected.java
private void AddDataFailingExperiments(String sDirectorio, ArrayList<Double> Pf, Hashtable<String, List> info) { File f = new File(sDirectorio); String extension;/*from w w w.j a v a 2 s.com*/ File[] files = f.listFiles(); Hashtable<String, String> Pop = new Hashtable<>(); PrintWriter escribir; Scanner sc = null; ArrayList<Integer> aPops = new ArrayList<>(); ArrayList<Double> aPf = new ArrayList<>(); ArrayList<String> aTech = new ArrayList<>(); for (File file : files) { List list = new ArrayList(); extension = ""; int i = file.getName().lastIndexOf('.'); int p = Math.max(file.getName().lastIndexOf('/'), file.getName().lastIndexOf('\\')); if (i > p) { extension = file.getName().substring(i + 1); } // System.out.println(file.getName() + "extension" + extension); if (file.isFile() && extension.equals("csv") && file.getName().startsWith("failInfo") && file.getName().contains(mazeMode)) { //System.out.println(file.getName()); //System.out.println("get: " + file.getName()); String[] filenamep = file.getName().split(Pattern.quote("+")); //System.out.println("file" + filenamep[8]); int popsizef = Integer.valueOf(filenamep[3]); double pff = Double.valueOf(filenamep[5]); String modef = filenamep[7]; int worldSize = Integer.valueOf(filenamep[11]) * Integer.valueOf(filenamep[13]); /*System.out.println("psizef:" + popsizef); System.out.println("pff:" + pff); System.out.println("modef:" + modef); */ // String[] aMode = {"turnoncontact", "lwsandc2", "lwsandc", "lwphevap2", "lwphevap"}; try { sc = new Scanner(file); } catch (FileNotFoundException ex) { Logger.getLogger(DataCollectedLatexConsolidatorSASOMessagesSend1.class.getName()) .log(Level.SEVERE, null, ex); } int agentId = -1; int countLines = 0; int roundNumber = -1; int infoCollected = -1; String[] data = null; while (sc.hasNext()) { String line = sc.nextLine(); //System.out.println("line:" + line); data = line.split(","); agentId = Integer.valueOf(data[0]); ///roundNumber = Integer.valueOf(data[1]); if (infoCollected < Integer.valueOf(data[2])) { infoCollected = Integer.valueOf(data[2]); roundNumber = Integer.valueOf(data[1]); } countLines++; } // System.out.println("lines" + countLines); if (countLines == popsizef && infoCollected != -1 && roundNumber != -1 && Pf.contains(pff)) { int datas = roundNumber; //list.add(datas); if (info.get(modef + "+" + popsizef) == null) { info.put((modef + "+" + popsizef), new ArrayList<Integer>()); } info.get(modef + "+" + popsizef).add(datas); } LOGGER.debug("Adding series " + i); LOGGER.debug(list.toString()); /*if (Pf.contains(pff)) { /*pf == 1.0E-4 || pf == 3.0E-4*/ /* if (Pf.size() == 1) { dataset.add(list, popsizef, getTechniqueName(modef)); } else { dataset.add(list, String.valueOf(popsizef) + "-" + pff, getTechniqueName(modef)); } }*/ } //if (Pf.contains(pff)) { /*pf == 1.0E-4 || pf == 3.0E-4*/ } }
From source file:net.emotivecloud.scheduler.drp4one.DRP4OVF.java
private String VMDescriptionNetwork(EmotiveOVF ovf) { StringBuilder buf = new StringBuilder(); String tmp;/*w w w . j av a 2 s . c om*/ // check for network attributes, if not available check the properties // file System.out.println("DRP4ONE - VMDescriptionNetwork()> ovf.getNetworks(): " + ovf.getNetworks()); if (!ovf.getNetworks().isEmpty()) { // added by smendoza // String netSection = String.format("NIC = [ NETWORK_ID = %s ] \n",props.getProperty("net.id")); // buf.append(netSection); // Network attributes netConnectNames = ovf4oneProperties(NET_CONNECTION_NAMES, false); for (OVFNetwork ovfNetwork : ovf.getNetworks().values()) { buf.append("NIC = [\n"); String nicName = ovfNetwork.getConnectionName(); // I am working on a new array, so I need to reset the separator String separator = ""; if (nicName == null || "".equals(nicName)) { // We supply IP and MAC for this NIC tmp = ovfNetwork.getIp(); if (tmp != null) { buf.append("IP = \""); buf.append(tmp); buf.append("\""); separator = ",\n"; } tmp = ovfNetwork.getMac(); if (tmp != null) { buf.append(separator); buf.append("MAC = \""); buf.append(tmp); buf.append("\""); } } else { // We ask OpenNebula to assign us IP and MAC System.out.println("DRP4ONE - VMDescriptionNetwork()> nicName: " + nicName); buf.append("NETWORK = \""); buf.append(nicName); buf.append("\" "); } buf.append("\n"); nicNames.add(nicName); buf.append("]\n"); System.out.println("DRP4ONE - VMDescriptionNetwork()> buf: " + buf); nicName = ""; } log.debug("adding the networks configured in props.."); log.debug("networks configured:" + netConnectNames); Scanner commaSperated = new Scanner(netConnectNames); commaSperated.useDelimiter(","); while (commaSperated.hasNext()) { String connectionName = commaSperated.next().trim(); log.debug("connection name " + connectionName); Iterator<String> nicNamesIter = nicNames.iterator(); while (nicNamesIter.hasNext()) { log.debug("nic names config in input:" + nicNamesIter.next()); } if (!nicNames.contains(connectionName)) { //addNic(buf, connectionName); } } } else { log.debug("no network configured in ovf input, hence checking the network config from properties file"); log.debug("networks configured:" + netConnectNames); Scanner commaSperated = new Scanner(netConnectNames); commaSperated.useDelimiter(","); while (commaSperated.hasNext()) { String connectionName = commaSperated.next().trim(); // addNic(buf, connectionName); // buf.append("NIC = [\n");buf.append("NETWORK = \""); // buf.append(connectionName); buf.append("\""); // buf.append("]\n\n\n"); } } return buf.toString(); }
From source file:net.emotivecloud.scheduler.drp4one.DRP4OVF.java
private String VMDescriptionContext(EmotiveOVF ovf) { StringBuilder buf = new StringBuilder(); // Context - requires again network attributes ////w w w. j a va2 s . co m // We list devices in order eth0, eth1, eth2... The context script will // get // them out and prepare the network configuration files. buf.append("CONTEXT = [\n"); String separator = ""; // buf.append("hostname = \"optimis2.leeds\","); int ethNumber = 0; if (!ovf.getNetworks().isEmpty()) { for (OVFNetwork ovfNetwork : ovf.getNetworks().values()) { String nicName = ovfNetwork.getConnectionName(); if (nicName == null || "".equals(nicName)) { String tmp = ovfNetwork.getIp(); if (tmp != null) { buf.append(separator); buf.append("IP_"); buf.append(ethNumber); buf.append(" = \""); buf.append(tmp); buf.append("\"\n"); separator = ",\n"; } tmp = ovfNetwork.getMac(); if (tmp != null) { buf.append(separator); buf.append("MAC_"); buf.append(ethNumber); buf.append(" = \""); buf.append(tmp); buf.append("\"\n"); separator = ",\n"; } } else { addNetworkConfigToContext(buf, separator, ethNumber, nicName); } ethNumber++; } log.debug("adding the networks configured in props.."); log.debug("networks configured:" + netConnectNames); Scanner commaSperated = new Scanner(netConnectNames); commaSperated.useDelimiter(","); while (commaSperated.hasNext()) { String connectionName = commaSperated.next().trim(); if (!nicNames.contains(connectionName)) { addNetworkConfigToContext(buf, separator, ethNumber, connectionName); log.debug("adding network config:" + connectionName); ethNumber++; } } } else { log.debug("no network configured in ovf input, hence checking the network config from properties file"); log.debug("networks configured:" + netConnectNames); Scanner commaSperated = new Scanner(netConnectNames); commaSperated.useDelimiter(","); while (commaSperated.hasNext()) { String connectionName = commaSperated.next().trim(); addNetworkConfigToContext(buf, separator, ethNumber, connectionName); ethNumber++; // buf.append("NIC = [\n");buf.append("NETWORK = \""); // buf.append(connectionName); buf.append("\""); // buf.append("]\n\n\n"); } } Iterator<String> home_iter = arg1.iterator(); Iterator<String> swap_iter = arg2.iterator(); buf.append("HOME = \""); while (home_iter.hasNext()) { buf.append(home_iter.next()); buf.append(" "); } buf.append("\",\n"); buf.append("SWAP = \""); while (swap_iter.hasNext()) { buf.append(swap_iter.next()); buf.append(" "); } buf.append("\"\n"); // buf.append("FILES=" + "\"" + scriptlocation + "/init.sh \""); buf.append("]\n"); return buf.toString(); }