Example usage for java.util.regex Pattern quote

List of usage examples for java.util.regex Pattern quote

Introduction

In this page you can find the example usage for java.util.regex Pattern quote.

Prototype

public static String quote(String s) 

Source Link

Document

Returns a literal pattern String for the specified String .

Usage

From source file:dk.netarkivet.common.utils.batch.FileBatchJob.java

/** Helper method for only processing one file.  This will
 * override any previous setting of which files to process.
 *
 * @param specifiedFilename The name of the single file that should
 * be processed.  Should not include any path information.
 *///w w w.j av a  2s . c  om
public void processOnlyFileNamed(String specifiedFilename) {
    ArgumentNotValid.checkNotNullOrEmpty(specifiedFilename, "specificedFilename");
    processOnlyFilesMatching(Pattern.quote(specifiedFilename));
}

From source file:edu.mit.scratch.Scratch.java

public static ScratchSession createSession(final String username, String password)
        throws ScratchLoginException {
    try {/*from   w w w  .j ava2  s .  c  o  m*/
        final RequestConfig globalConfig = RequestConfig.custom().setCookieSpec(CookieSpecs.DEFAULT) // Changed due to deprecation
                .build();

        final CookieStore cookieStore = new BasicCookieStore();
        final BasicClientCookie lang = new BasicClientCookie("scratchlanguage", "en");
        lang.setDomain(".scratch.mit.edu");
        lang.setPath("/");
        cookieStore.addCookie(lang);

        final CloseableHttpClient httpClient = HttpClients.custom().setDefaultRequestConfig(globalConfig)
                .setUserAgent(Scratch.USER_AGENT).setDefaultCookieStore(cookieStore).build();
        CloseableHttpResponse resp;

        final HttpUriRequest csrf = RequestBuilder.get().setUri("https://scratch.mit.edu/csrf_token/")
                .addHeader("Accept", "*/*").addHeader("Referer", "https://scratch.mit.edu")
                .addHeader("X-Requested-With", "XMLHttpRequest").build();
        resp = httpClient.execute(csrf);
        resp.close();

        String csrfToken = null;
        for (final Cookie c : cookieStore.getCookies())
            if (c.getName().equals("scratchcsrftoken"))
                csrfToken = c.getValue();

        final JSONObject loginObj = new JSONObject();
        loginObj.put("username", username);
        loginObj.put("password", password);
        loginObj.put("captcha_challenge", "");
        loginObj.put("captcha_response", "");
        loginObj.put("embed_captcha", false);
        loginObj.put("timezone", "America/New_York");
        loginObj.put("csrfmiddlewaretoken", csrfToken);
        final HttpUriRequest login = RequestBuilder.post().setUri("https://scratch.mit.edu/accounts/login/")
                .addHeader("Accept", "application/json, text/javascript, */*; q=0.01")
                .addHeader("Referer", "https://scratch.mit.edu").addHeader("Origin", "https://scratch.mit.edu")
                .addHeader("Accept-Encoding", "gzip, deflate").addHeader("Accept-Language", "en-US,en;q=0.8")
                .addHeader("Content-Type", "application/json").addHeader("X-Requested-With", "XMLHttpRequest")
                .addHeader("X-CSRFToken", csrfToken).setEntity(new StringEntity(loginObj.toString())).build();
        resp = httpClient.execute(login);
        password = null;
        final BufferedReader rd = new BufferedReader(new InputStreamReader(resp.getEntity().getContent()));

        final StringBuffer result = new StringBuffer();
        String line = "";
        while ((line = rd.readLine()) != null)
            result.append(line);
        final JSONObject jsonOBJ = new JSONObject(
                result.toString().substring(1, result.toString().length() - 1));
        if ((int) jsonOBJ.get("success") != 1)
            throw new ScratchLoginException();
        String ssi = null;
        String sct = null;
        String e = null;
        final Header[] headers = resp.getAllHeaders();
        for (final Header header : headers)
            if (header.getName().equals("Set-Cookie")) {
                final String value = header.getValue();
                final String[] split = value.split(Pattern.quote("; "));
                for (final String s : split) {
                    if (s.contains("=")) {
                        final String[] split2 = s.split(Pattern.quote("="));
                        final String key = split2[0];
                        final String val = split2[1];
                        if (key.equals("scratchsessionsid"))
                            ssi = val;
                        else if (key.equals("scratchcsrftoken"))
                            sct = val;
                        else if (key.equals("expires"))
                            e = val;
                    }
                }
            }
        resp.close();

        return new ScratchSession(ssi, sct, e, username);
    } catch (final IOException e) {
        e.printStackTrace();
        throw new ScratchLoginException();
    }
}

From source file:com.uber.hoodie.hive.util.TestUtil.java

public static void generateParquetData(Path filePath, String schemaFile) throws IOException {
    MessageType schema = readSchema(schemaFile);
    CsvParquetWriter writer = new CsvParquetWriter(filePath, schema);

    BufferedReader br = new BufferedReader(
            new InputStreamReader(TestUtil.class.getResourceAsStream(getDataFile(schemaFile))));
    String line;//from  ww  w .j a va2 s  .  co  m
    try {
        while ((line = br.readLine()) != null) {
            String[] fields = line.split(Pattern.quote(CSV_DELIMITER));
            writer.write(Arrays.asList(fields));
        }
        writer.close();
    } finally {
        br.close();
    }

    InputStreamReader io = null;
    FSDataOutputStream hdfsPath = null;
    try {
        io = new FileReader(filePath.toString());
        hdfsPath = fileSystem.create(filePath);
        IOUtils.copy(io, hdfsPath);
    } finally {
        if (io != null) {
            io.close();
        }
        if (hdfsPath != null) {
            hdfsPath.close();
        }
    }
}

From source file:com.genentech.chemistry.openEye.apps.SdfRMSDSphereExclusion.java

private void run(String inFile) {
    oemolithread ifs = new oemolithread(inFile);
    long start = System.currentTimeMillis();
    int iCounter = 0; //Structures in the SD file.
    int oCounter = 0;
    String lastGroupByValue = "Gliberich not found in file";

    OEMolBase mol = new OEGraphMol();

    inLoop: while (oechem.OEReadMolecule(ifs, mol)) {
        iCounter++;//from  w w  w.  j  a v a 2  s .c  om
        //Output "." to show that the program is running.
        if (iCounter % 100 == 0)
            System.err.print(".");
        if (iCounter % 4000 == 0)
            System.err.printf(" %d %dsec\n", iCounter, (System.currentTimeMillis() - start) / 1000);

        double minRMSD = Double.MAX_VALUE;

        if (groupByTag != null) { // check if a new group starts here and clear sleected if that is the case
            String groupByVal = oechem.OEGetSDData(mol, groupByTag);
            if (!groupByVal.equals(lastGroupByValue))
                clearSelected();
            lastGroupByValue = groupByVal;
        }

        OEMolBase mirMol = null;
        if (doMirror && selected.size() == 0 && !isChiral(mol)) {
            mirMol = new OEGraphMol(mol);
            createMirror(mirMol);
        }

        for (int i = selected.size() - 1; i >= 0; i--) {
            double rmsd = oechem.OERMSD(mol, selected.get(i), true, true, doOptimize);
            if (rmsd < 0D)
                System.err.println("OERMSD returned -1 are you comparing two different structures?");

            if (mirMol != null) {
                double mirRmsd = oechem.OERMSD(mirMol, selected.get(i), true, true, doOptimize);
                if (mirRmsd < rmsd)
                    rmsd = mirRmsd;
            }

            if (rmsd < radius) {
                if (printAll) {
                    oechem.OESetSDData(mol, "sphereIdx", Integer.toString(i));
                    oechem.OESetSDData(mol, "centroidRMSD", DataFormat.formatNumber(rmsd, "si3"));
                    oechem.OEWriteMolecule(outputOEThread, mol);
                }
                continue inLoop;
            }

            if (rmsd < minRMSD)
                minRMSD = rmsd;
        }

        oechem.OESetSDData(mol, "sphereIdx", Integer.toString(selected.size()));
        oechem.OESetSDData(mol, "includeIdx", Integer.toString(selected.size()));
        oechem.OESetSDData(mol, "centroidRMSD", "0");

        selected.add(new OEGraphMol(mol));
        oechem.OEWriteMolecule(outputOEThread, mol);

        if (mirMol != null)
            mirMol.delete();

        oCounter++;
    }

    mol.delete();
    ifs.close();
    ifs.delete();
    inFile = inFile.replaceAll(".*" + Pattern.quote(File.separator), "");
    System.err.printf("%s: Read %d structures from %s. Written %d centroids in %d sec\n", MY_NAME, iCounter,
            inFile, oCounter, (System.currentTimeMillis() - start) / 1000);
}

From source file:unalcol.termites.boxplots.ECALAgentsRight.java

/**
 * Creates a sample dataset./*from   w ww  .ja  v  a  2 s. c o m*/
 *
 * @return A sample dataset.
 */
private BoxAndWhiskerCategoryDataset createSampleDataset(ArrayList<Double> Pf) {

    final int seriesCount = 5;
    final int categoryCount = 4;
    final int entityCount = 22;
    String sDirectorio = ".\\experiments\\ECAL CR";
    File f = new File(sDirectorio);
    String extension;
    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<>();

    final DefaultBoxAndWhiskerCategoryDataset dataset = new DefaultBoxAndWhiskerCategoryDataset();

    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")) {
            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" };
            //String[] aMode = {"turnoncontact", "lwsandc2", "lwsandc", "lwphevap2", "lwphevap"};

            if (/*Pf == pf && */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);
                    //if (bestRoundNumber != 0 && bestRoundNumber != -1) {
                    list.add(new Double(agentsCorrect));
                    //}
                }
                LOGGER.debug("Adding series " + i);
                LOGGER.debug(list.toString());
                if (Pf.contains(pf)) {
                    /*pf == 1.0E-4 || pf == 3.0E-4*/
                    if (Pf.size() == 1) {
                        dataset.add(list, popsize, getTechniqueName(mode));
                    } else {
                        dataset.add(list, String.valueOf(popsize) + "-" + pf, getTechniqueName(mode));
                    }
                }
            }
        }

    }

    /*for (int i = 0; i < seriesCount; i++) {
     for (int j = 0; j < categoryCount; j++) {
     final List list = new ArrayList();
     // add some values...
     for (int k = 0; k < entityCount; k++) {
     final double value1 = 10.0 + Math.random() * 3;
     list.add(new Double(value1));
     final double value2 = 11.25 + Math.random(); // concentrate values in the middle
     list.add(new Double(value2));
     }
     LOGGER.debug("Adding series " + i);
     LOGGER.debug(list.toString());
     dataset.add(list, "Series " + i, " Type " + j);
     }
            
     }*/
    return dataset;
}

From source file:com.c4om.autoconf.ulysses.configanalyzer.environmentchecker.XSDFriendlyValidatorBasedChecker.java

/**
 * This method takes an extracted XML file, looks for its related schema file(s) (if any) and validates it against them
 * @param extractedFile the extracted {@link File} pointing to the document to validate (if possible)
 * @param base the base path where the temporary local copy of the configuration is stored.
 * @param configurationAnalyzerSettings the configuration analyzer settings.
 * @return the {@link ValidationResults} produced when the given file is validated.
 * @throws EnvironmentCheckingException if there is an error that makes impossible to continue the validation
 *///from w ww.j a  v a  2s. c  o  m
private ValidationResults processSingleFile(File extractedFile, File base,
        Properties configurationAnalyzerSettings) throws EnvironmentCheckingException {
    try {
        List<InputStream> inputStreamsForXSDs = new ArrayList<>(xsdNames.size());
        XSDFriendlyValidator validator = new XSDFriendlyValidatorImpl();
        for (String xsdName : xsdNames) {
            String relativePath = extractedFile.getAbsolutePath().replaceAll(
                    "^" + Pattern.quote(base.getAbsolutePath()) + "(" + Pattern.quote(File.separator) + ")?",
                    "");
            String currentXsdSetPath = configurationAnalyzerSettings
                    .getProperty(PROPERTY_KEY_PREFFIX_XSD_SETS_LOCATIONS + xsdSetName);
            if (currentXsdSetPath == null) {
                throw new EnvironmentCheckingException("Property '" + PROPERTY_KEY_PREFFIX_XSD_SETS_LOCATIONS
                        + xsdSetName
                        + "' not found. Please check that it is correctly defined, so that the current xsd set can be found.");
            }
            String inputXSDPath = currentXsdSetPath + "/" + relativePath + "/" + xsdName;
            File inputXSDFile = new File(inputXSDPath);
            if (inputXSDFile.exists()) {
                InputStream inputStream = new FileInputStream(inputXSDFile);
                inputStreamsForXSDs.add(inputStream);
            }
        }
        Map<String, Document> schemas = new HashMap<>(inputStreamsForXSDs.size());
        if (inputStreamsForXSDs.isEmpty()) {
            return null; //There are no files to validate
        }
        for (InputStream is : inputStreamsForXSDs) {
            Document schemaDocument = loadW3CDocumentFromInputStream(is);
            String targetNamespace = schemaDocument.getDocumentElement().getAttribute("targetNamespace");
            if (schemas.containsKey(targetNamespace)) {
                throw new EnvironmentCheckingException(
                        "More than one schema is defined for target namespace '" + targetNamespace + "'");
            }
            schemas.put(targetNamespace, schemaDocument);
        }
        Document instanceDocument = loadW3CDocumentFromInputFile(extractedFile);
        ValidationResults validationResults = validator.validate(instanceDocument, schemas);
        return validationResults;
    } catch (ParserConfigurationException | SAXException | IOException | XSDFriendlyValidationException e) {
        throw new EnvironmentCheckingException(e);
    }

}

From source file:unalcol.termites.boxplots.RoundNumber1.java

/**
 * Creates a sample dataset./*  w ww .j  ava2s  . c o m*/
 *
 * @return A sample dataset.
 */
private BoxAndWhiskerCategoryDataset createSampleDataset(ArrayList<Double> Pf) {

    String sDirectorio = experimentsDir;
    File f = new File(sDirectorio);
    String extension;
    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<>();

    final DefaultBoxAndWhiskerCategoryDataset dataset = new DefaultBoxAndWhiskerCategoryDataset();

    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 = {"levywalk", "lwphevap", "hybrid", "hybrid3", "hybrid4", "sequential"};
            if (/*Pf == pf && */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);
                    if (bestRoundNumber != 0 && bestRoundNumber != -1) {
                        list.add(new Double(bestRoundNumber));
                    }
                }
                LOGGER.debug("Adding series " + i);
                LOGGER.debug(list.toString());
                if (Pf.contains(pf)) {
                    /*pf == 1.0E-4 || pf == 3.0E-4*/
                    if (Pf.size() == 1) {
                        dataset.add(list, popsize, getTechniqueName(mode));
                    } else {
                        dataset.add(list, String.valueOf(popsize) + "-" + pf, getTechniqueName(mode));
                    }
                }
            }
        }

    }

    /*for (int i = 0; i < seriesCount; i++) {
     for (int j = 0; j < categoryCount; j++) {
     final List list = new ArrayList();
     // add some values...
     for (int k = 0; k < entityCount; k++) {
     final double value1 = 10.0 + Math.random() * 3;
     list.add(new Double(value1));
     final double value2 = 11.25 + Math.random(); // concentrate values in the middle
     list.add(new Double(value2));
     }
     LOGGER.debug("Adding series " + i);
     LOGGER.debug(list.toString());
     dataset.add(list, "Series " + i, " Type " + j);
     }
            
     }*/
    return dataset;
}

From source file:unalcol.termites.boxplots.ECALRoundNumber.java

/**
 * Creates a sample dataset./*w ww. java  2  s  . c o  m*/
 *
 * @return A sample dataset.
 */
private BoxAndWhiskerCategoryDataset createSampleDataset(ArrayList<Double> Pf) {

    final int seriesCount = 5;
    final int categoryCount = 4;
    final int entityCount = 22;
    String sDirectorio = ".\\experiments\\ECAL CR";
    File f = new File(sDirectorio);
    String extension;
    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<>();

    final DefaultBoxAndWhiskerCategoryDataset dataset = new DefaultBoxAndWhiskerCategoryDataset();

    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")) {
            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" };
            //String[] aMode = {"turnoncontact", "lwsandc2", "lwsandc", "lwphevap2", "lwphevap"};

            if (/*Pf == pf && */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);
                    if (bestRoundNumber != 0 && bestRoundNumber != -1) {
                        list.add(new Double(bestRoundNumber));
                    }
                }
                LOGGER.debug("Adding series " + i);
                LOGGER.debug(list.toString());
                if (Pf.contains(pf)) {
                    /*pf == 1.0E-4 || pf == 3.0E-4*/
                    if (Pf.size() == 1) {
                        dataset.add(list, popsize, getTechniqueName(mode));
                    } else {
                        dataset.add(list, String.valueOf(popsize) + "-" + pf, getTechniqueName(mode));
                    }
                }
            }
        }

    }

    /*for (int i = 0; i < seriesCount; i++) {
     for (int j = 0; j < categoryCount; j++) {
     final List list = new ArrayList();
     // add some values...
     for (int k = 0; k < entityCount; k++) {
     final double value1 = 10.0 + Math.random() * 3;
     list.add(new Double(value1));
     final double value2 = 11.25 + Math.random(); // concentrate values in the middle
     list.add(new Double(value2));
     }
     LOGGER.debug("Adding series " + i);
     LOGGER.debug(list.toString());
     dataset.add(list, "Series " + i, " Type " + j);
     }
            
     }*/
    return dataset;
}

From source file:unalcol.termites.boxplots.RoundNumber2.java

/**
 * Creates a sample dataset./*from ww w .ja va 2s. c om*/
 *
 * @return A sample dataset.
 */
private BoxAndWhiskerCategoryDataset createSampleDataset(ArrayList<Double> Pf) {

    final int seriesCount = 5;
    final int categoryCount = 4;
    final int entityCount = 22;
    String sDirectorio = ".\\experiments\\2015-10-14-Maze\\results";
    File f = new File(sDirectorio);
    String extension;
    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<>();

    final DefaultBoxAndWhiskerCategoryDataset dataset = new DefaultBoxAndWhiskerCategoryDataset();

    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")) {
            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 = {"sandclw", "lwsandc2", "lwsandc", "lwphevap2", "lwphevap"};
            //String[] aMode = {"turnoncontact", "lwsandc2", "lwsandc", "lwphevap2", "lwphevap"};
            String[] aMode = { "levywalk", "lwphevap", "hybrid" };

            if (/*Pf == pf && */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);
                    if (bestRoundNumber != 0 && bestRoundNumber != -1) {
                        list.add(new Double(bestRoundNumber));
                    }
                }
                LOGGER.debug("Adding series " + i);
                LOGGER.debug(list.toString());
                if (Pf.contains(pf)) {
                    /*pf == 1.0E-4 || pf == 3.0E-4*/
                    if (Pf.size() == 1) {
                        dataset.add(list, popsize, getTechniqueName(mode));
                    } else {
                        dataset.add(list, String.valueOf(popsize) + "-" + pf, getTechniqueName(mode));
                    }
                }
            }
        }

    }

    /*for (int i = 0; i < seriesCount; i++) {
     for (int j = 0; j < categoryCount; j++) {
     final List list = new ArrayList();
     // add some values...
     for (int k = 0; k < entityCount; k++) {
     final double value1 = 10.0 + Math.random() * 3;
     list.add(new Double(value1));
     final double value2 = 11.25 + Math.random(); // concentrate values in the middle
     list.add(new Double(value2));
     }
     LOGGER.debug("Adding series " + i);
     LOGGER.debug(list.toString());
     dataset.add(list, "Series " + i, " Type " + j);
     }
            
     }*/
    return dataset;
}

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;// w  w  w.ja v  a2 s .  c om
    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;
}