Example usage for java.lang String subSequence

List of usage examples for java.lang String subSequence

Introduction

In this page you can find the example usage for java.lang String subSequence.

Prototype

public CharSequence subSequence(int beginIndex, int endIndex) 

Source Link

Document

Returns a character sequence that is a subsequence of this sequence.

Usage

From source file:Main.java

public static void main(String[] args) {

    String str = "java2s.com";

    System.out.println("string = " + str);

    // returns the specified subsequence from index 2 to 9
    System.out.println("string subsequence = " + str.subSequence(2, 9));
}

From source file:org.cellprofiler.tileimg.TileImg.java

/**
 * @param args//  w  w  w .  j  a  v a  2  s  .c o  m
 */
public static void main(String[] args) {
    Options options = new Options();
    options.addOption("?", "help", false, "Print help usage");
    options.addOption("h", HEIGHT, true, "The height of each tile");
    options.addOption("w", WIDTH, true, "The width of each tile");
    options.addOption("v", OVERLAP, true, "The amount of pixels shared between adjacent tiles");
    options.addOption("s", SKIP, false,
            "Make tiles of exactly the height and width entered and skip the last tile if height and width are smaller");
    options.addOption("p", PAD, false,
            "Make tiles of exactly the height and width entered and pad the last tile with zeros to make it the same size as the others");
    Option option = new Option("i", INPUT_FILE, true, "The location of the input image file");
    option.setRequired(true);
    options.addOption(option);
    option = new Option("o", OUTPUT_FOLDER, true, "Store tiled images in this folder");
    option.setRequired(true);
    options.addOption(option);
    try {
        CommandLine cmdline = new PosixParser().parse(options, args);
        if (cmdline.hasOption("help")) {
            HelpFormatter hf = new HelpFormatter();
            hf.printHelp("tileimg", options);
            return;
        }
        int height = cmdline.hasOption(HEIGHT) ? Integer.valueOf(cmdline.getOptionValue(HEIGHT))
                : DEFAULT_HEIGHT;
        int width = cmdline.hasOption(WIDTH) ? Integer.valueOf(cmdline.getOptionValue(WIDTH)) : DEFAULT_WIDTH;
        int overlap = cmdline.hasOption(OVERLAP) ? Integer.valueOf(cmdline.getOptionValue(OVERLAP))
                : DEFAULT_OVERLAP;
        boolean skip = cmdline.hasOption(SKIP);
        boolean pad = cmdline.hasOption(PAD);
        if (skip && pad) {
            System.err.println("Illegal option combination: specify either skip or pad, but not both.");
            HelpFormatter hf = new HelpFormatter();
            hf.printHelp("tileimg", options);
            return;
        }
        String inputFile = cmdline.getOptionValue(INPUT_FILE);
        final File inputIOFile = new File(inputFile);
        if (!inputIOFile.canRead()) {
            logger.error(String.format("Can't read from %s", inputFile));
            return;
        }
        String outputFolder = cmdline.getOptionValue(OUTPUT_FOLDER);
        File outputDir = new File(outputFolder);
        if (!outputDir.exists()) {
            if (!outputDir.mkdirs()) {
                logger.error(String.format("Failed to create folder: %s", outputFolder));
                return;
            }
        }
        String rootName = inputIOFile.getName();
        String format = String.format("%s_xoff%%d_yoff%%d_series%%d_index%%d.tif",
                rootName.subSequence(0, rootName.lastIndexOf(".")));

        ImageReader rdr = new ImageReader();
        rdr.setGroupFiles(false);
        rdr.setAllowOpenFiles(true);
        ServiceFactory factory = new ServiceFactory();
        OMEXMLService service = factory.getInstance(OMEXMLService.class);
        OMEXMLMetadata store = service.createOMEXMLMetadata();
        rdr.setMetadataStore(store);
        rdr.setId(inputFile);
        for (int series = 0; series < rdr.getSeriesCount(); series++) {
            rdr.setSeries(series);
            int imageHeight = rdr.getSizeY();
            int imageWidth = rdr.getSizeX();
            int nVerticalTiles = (imageHeight + height - 1) / (height - overlap);
            int nHorizTiles = (imageWidth + width - 1) / (width - overlap);
            int adjTileWidth = (pad | skip) ? width
                    : ((imageWidth + overlap * (nHorizTiles - 1) + nHorizTiles - 1) / nHorizTiles);
            int adjTileHeight = (pad | skip) ? height
                    : ((imageHeight + overlap * (nVerticalTiles - 1) + nVerticalTiles - 1) / nVerticalTiles);
            for (int index = 0; index < rdr.getImageCount(); index++) {
                for (int xIndex = 0; xIndex < nHorizTiles; xIndex++) {
                    int xLeftEdge = (adjTileWidth - overlap) * xIndex;
                    int xRightEdge = Math.min(imageWidth, xLeftEdge + adjTileWidth);
                    for (int yIndex = 0; yIndex < nVerticalTiles; yIndex++) {
                        int yTopEdge = (adjTileHeight - overlap) * yIndex;
                        int yBottomEdge = Math.min(imageHeight, yTopEdge + adjTileHeight);
                        final int tileWidth = xRightEdge - xLeftEdge;
                        final int tileHeight = yBottomEdge - yTopEdge;
                        if (skip && ((tileWidth < width) || (tileHeight < height)))
                            continue;
                        byte[] buf = rdr.openBytes(index, xLeftEdge, yTopEdge, tileWidth, tileHeight);
                        String filename = String.format(format, xLeftEdge, yTopEdge, series, index);
                        File outputFile = new File(outputDir, filename);
                        if (outputFile.exists())
                            outputFile.delete();
                        ImageWriter writer = new ImageWriter();
                        OMEXMLMetadata metadata = service.createOMEXMLMetadata();
                        metadata.setImageID(store.getImageID(series), 0);
                        metadata.setPixelsID(store.getPixelsID(series), 0);
                        for (int channelIdx = 0; channelIdx < store.getChannelCount(series); channelIdx++) {
                            metadata.setChannelID(store.getChannelID(series, channelIdx), 0, channelIdx);
                            metadata.setChannelName(store.getChannelName(series, channelIdx), 0, channelIdx);
                            metadata.setChannelSamplesPerPixel(
                                    store.getChannelSamplesPerPixel(series, channelIdx), 0, channelIdx);
                        }
                        metadata.setPixelsBigEndian(store.getPixelsBigEndian(series), 0);
                        metadata.setPixelsSignificantBits(store.getPixelsSignificantBits(series), 0);
                        metadata.setPixelsType(store.getPixelsType(series), 0);
                        metadata.setPixelsDimensionOrder(DimensionOrder.XYCZT, 0);
                        metadata.setPixelsSizeX(new PositiveInteger(pad ? adjTileWidth : tileWidth), 0);
                        metadata.setPixelsSizeY(new PositiveInteger(pad ? adjTileHeight : tileHeight), 0);
                        final PositiveInteger one = new PositiveInteger(1);
                        if (store.getChannelCount(series) == 1)
                            metadata.setPixelsSizeC(store.getChannelSamplesPerPixel(series, 0), 0);
                        metadata.setPixelsSizeT(one, 0);
                        metadata.setPixelsSizeZ(one, 0);
                        writer.setMetadataRetrieve(metadata);
                        writer.setWriteSequentially(true);
                        writer.setInterleaved(rdr.isInterleaved());
                        writer.setId(outputFile.getAbsolutePath());
                        if (writer.getWriter() instanceof TiffWriter) {
                            TiffWriter tiffWriter = (TiffWriter) (writer.getWriter());
                            IFD ifd = new IFD();
                            ifd.putIFDValue(IFD.ROWS_PER_STRIP, new long[] { adjTileHeight });
                            tiffWriter.saveBytes(0, buf, ifd, 0, 0, tileWidth, tileHeight);
                        } else {
                            writer.saveBytes(0, buf, 0, 0, tileWidth, tileHeight);
                        }
                        if (pad) {
                            final int wPad = adjTileWidth - tileWidth;
                            final int hPad = adjTileHeight - tileHeight;
                            if (wPad > 0) {
                                byte[] temp = new byte[wPad * adjTileHeight];
                                writer.saveBytes(0, temp, tileWidth, 0, wPad, adjTileHeight);
                            }
                            if (hPad > 0) {
                                byte[] temp = new byte[hPad * adjTileWidth];
                                writer.saveBytes(0, temp, 0, tileHeight, adjTileWidth, hPad);
                            }
                        }
                        writer.close();
                        logger.info(String.format("Wrote %s", outputFile.getName()));
                    }
                }
            }
        }

    } catch (ParseException e) {
        HelpFormatter hf = new HelpFormatter();
        hf.printHelp("tileimg", options);
    } catch (FormatException e) {
        logger.error(e.getMessage());
    } catch (IOException e) {
        logger.error(e.getMessage());
    } catch (ServiceException e) {
        logger.error(e.getMessage());
    } catch (DependencyException e) {
        logger.error(e.getMessage());
    }

}

From source file:com.yahoo.semsearch.fastlinking.utils.Normalize.java

License:asdf

public static void main(String args[]) {
    String test = "ad. - asd. ; ; ; ;asdf assssXxvv.com hola.com .com one two     three four   ";
    System.out.println(test);// w w  w  .j  av a  2  s  .  c o m
    System.out.println(Normalize.normalize(test));
    for (Span a : Normalize.normalizeWithSpans(test)) {
        System.out.println(a.getStartOffset() + "-" + a.getEndOffset() + " >" + a.span + "<:>"
                + test.subSequence(a.getStartOffset(), a.getEndOffset()) + "<");
    }
}

From source file:tpt.dbweb.cat.io.TaggedTextXMLReader.java

public static void main(String... args) {
    String file = "result/ace2004/roth-dev/dev//tagged-by-pronoun.xml";
    for (TaggedText tt : new TaggedTextXMLReader().getTaggedTextFromFile(file)) {
        System.out.println(tt);/*from w  ww.jav a 2 s.co m*/
    }

    try {
        for (String str : Utility
                .iterable(new TaggedTextXMLReader().getArticleIterator(new FileInputStream(file), file))) {
            System.out.print("START: " + str.subSequence(0, 50));
            System.out.print("...");
            System.out.println(str.subSequence(str.length() - 50, str.length()) + " END");
        }
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }

}

From source file:GoogleImages.java

public static void main(String[] args) throws InterruptedException {
    String searchTerm = "s woman"; // term to search for (use spaces to separate terms)
    int offset = 40; // we can only 20 results at a time - use this to offset and get more!
    String fileSize = "50mp"; // specify file size in mexapixels (S/M/L not figured out yet)
    String source = null; // string to save raw HTML source code

    // format spaces in URL to avoid problems
    searchTerm = searchTerm.replaceAll(" ", "%20");

    // get Google image search HTML source code; mostly built from PhyloWidget example:
    // http://code.google.com/p/phylowidget/source/browse/trunk/PhyloWidget/src/org/phylowidget/render/images/ImageSearcher.java
    int offset2 = 0;
    Set urlsss = new HashSet<String>();
    while (offset2 < 600) {
        try {/*from   w  w w.j a  v  a 2 s  . co m*/
            URL query = new URL("https://www.google.ru/search?start=" + offset2
                    + "&q=angry+woman&newwindow=1&client=opera&hs=bPE&source=lnms&tbm=isch&sa=X&ved=0ahUKEwiAgcKozIfNAhWoHJoKHSb_AUoQ_AUIBygB&biw=1517&bih=731&dpr=0.9#imgrc=G_1tH3YOPcc8KM%3A");
            HttpURLConnection urlc = (HttpURLConnection) query.openConnection(); // start connection...
            urlc.setInstanceFollowRedirects(true);
            urlc.setRequestProperty("User-Agent", "");
            urlc.connect();
            BufferedReader in = new BufferedReader(new InputStreamReader(urlc.getInputStream())); // stream in HTTP source to file
            StringBuffer response = new StringBuffer();
            char[] buffer = new char[1024];
            while (true) {
                int charsRead = in.read(buffer);
                if (charsRead == -1) {
                    break;
                }
                response.append(buffer, 0, charsRead);
            }
            in.close(); // close input stream (also closes network connection)
            source = response.toString();
        } // any problems connecting? let us know
        catch (Exception e) {
            e.printStackTrace();
        }

        // print full source code (for debugging)
        // println(source);
        // extract image URLs only, starting with 'imgurl'
        if (source != null) {
            //                System.out.println(source);
            int c = StringUtils.countMatches(source, "http://www.vmir.su");
            System.out.println(c);
            int index = source.indexOf("src=");
            System.out.println(source.subSequence(index, index + 200));
            while (index >= 0) {
                System.out.println(index);
                index = source.indexOf("src=", index + 1);
                if (index == -1) {
                    break;
                }
                String rr = source.substring(index,
                        index + 200 > source.length() ? source.length() : index + 200);

                if (rr.contains("\"")) {
                    rr = rr.substring(5, rr.indexOf("\"", 5));
                }
                System.out.println(rr);
                urlsss.add(rr);
            }
        }
        offset2 += 20;
        Thread.sleep(1000);
        System.out.println("off set = " + offset2);

    }

    System.out.println(urlsss);
    urlsss.forEach(new Consumer<String>() {

        public void accept(String s) {
            try {
                saveImage(s, "C:\\Users\\Java\\Desktop\\ang\\" + UUID.randomUUID().toString() + ".jpg");
            } catch (IOException ex) {
                Logger.getLogger(GoogleImages.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    });
    //            String[][] m = matchAll(source, "img height=\"\\d+\" src=\"([^\"]+)\"");

    // older regex, no longer working but left for posterity
    // built partially from: http://www.mkyong.com/regular-expressions/how-to-validate-image-file-extension-with-regular-expression
    // String[][] m = matchAll(source, "imgurl=(.*?\\.(?i)(jpg|jpeg|png|gif|bmp|tif|tiff))");    // (?i) means case-insensitive
    //            for (int i = 0; i < m.length; i++) {                                                          // iterate all results of the match
    //                println(i + ":\t" + m[i][1]);                                                         // print (or store them)**
    //            }
}

From source file:org.schreibubi.JCombinationsTools.coordinatorPatch.CoordinatorPatch.java

/**
 * @param args/*from   w  w  w  .  j  a va2s .c om*/
 */
public static void main(String[] args) {

    Info.printVersion("CoordinatorPatch");
    try {
        CoordinatorPatchOptions[] settings = CoordinatorPatchOptions.values();
        SettingsSingleton.initialize("CoordinatorPatch", settings);
        // command line arguments have the highest priority, so they go into level 2
        SettingsSingleton.getInstance().parseArguments(args, 2);

        if (SettingsSingleton.getInstance().getProperty("help").equals("true")) {
            SettingsSingleton.getInstance().displayHelp();
            Runtime.getRuntime().exit(0);
        }

        if (SettingsSingleton.getInstance().getProperty("version").equals("true")) {
            Info.printVersion("CoordinatorPatch");
            Runtime.getRuntime().exit(0);
        }

        String combinationFileName = SettingsSingleton.getInstance().getProperty("combinations");

        // pre-tags
        VArrayList<String> preTags = new VArrayList<String>();
        String preTagsString = SettingsSingleton.getInstance().getProperty("pretags");
        preTags = new VArrayList<String>(Arrays.asList(preTagsString.split(",")));
        // post-tags
        VArrayList<String> postTags = new VArrayList<String>();
        String postTagsString = SettingsSingleton.getInstance().getProperty("posttags");
        postTags = new VArrayList<String>(Arrays.asList(postTagsString.split(",")));

        FileNameLookupSingleton.initialize(preTags, postTags);

        File dir = new File(combinationFileName).getAbsoluteFile().getParentFile();
        File combinationFile = FileNameLookupSingleton.getInstance().lookup(dir, combinationFileName);
        System.out.println("Processing: " + combinationFile.getName());

        System.out.println("Executing: " + combinationFileName);
        SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmss");
        Date today = new Date();
        String tempdir = "/tmp/master" + formatter.format(today) + "/";
        String symbolTableLines = tempdir + "evaluated.combinations";
        String mangled_combinations = tempdir + "mangled.combinations";

        File tempdirectory = new File(tempdir);
        if (!tempdirectory.exists()) {
            tempdirectory.mkdir();
        }

        // Generate all possible combinations
        System.out.print("Generating and evaluation all combinations...");
        VHashMap<String> optionsFromEvalGenWalker = new VHashMap<String>();
        EvalGenCombinations.exec(new FileReader(combinationFileName), dir, optionsFromEvalGenWalker);
        System.out.println("done");

        // now additional default options are known...
        // -----------------------------------------------------------------------------
        String argumentsString = optionsFromEvalGenWalker.get("Coordinator");
        if (argumentsString != null) {
            String[] arguments = argumentsString.split(" ");
            SettingsSingleton.getInstance().parseArguments(arguments, 1);
        }

        if (SettingsSingleton.getInstance().areRequiredOptionsSet() == false) {
            SettingsSingleton.getInstance().displayHelp();
            Runtime.getRuntime().exit(0);
        }

        String conditionFilePrefix = SettingsSingleton.getInstance().getProperty("conditionprefix");
        String conditionFileTemplateName = conditionFilePrefix + ".template";
        String conditionFileHeaderName = conditionFilePrefix + ".header";
        String pcfOutputDir = SettingsSingleton.getInstance().getProperty("pcfdir");

        if (!SettingsSingleton.getInstance().getProperty("conditiontemplate").equals("")) {
            conditionFileTemplateName = SettingsSingleton.getInstance().getProperty("conditiontemplate");
        }
        if (!SettingsSingleton.getInstance().getProperty("conditionheader").equals("")) {
            conditionFileHeaderName = SettingsSingleton.getInstance().getProperty("conditionheader");
        }

        String conditionFileName = "";
        if (!SettingsSingleton.getInstance().getProperty("condition").equals("")) {
            conditionFileName = SettingsSingleton.getInstance().getProperty("condition");
        } else {
            int dotPos = combinationFileName.indexOf(".");
            if (dotPos > -1) {
                conditionFileName = conditionFilePrefix + "_" + combinationFileName.subSequence(0, dotPos);
            } else {
                conditionFileName = conditionFilePrefix + "_" + combinationFileName;
            }
        }

        // Create the condition file
        System.out.print("Creating " + conditionFileName + "...");
        TemplateEngine.exec(new File(symbolTableLines), false, conditionFileName, false,
                conditionFileTemplateName, new File("."), new File(pcfOutputDir),
                new File(conditionFileHeaderName), null);
        System.out.println("done");

        if (SettingsSingleton.getInstance().getProperty("nopatgen").equals("false")) {
            String setiFileName = SettingsSingleton.getInstance().getProperty("seti");

            // Generate Binary Diff value
            System.out.print("Generating test values for binary diff...");
            VArrayList<String> templateNames;
            templateNames = GenerateBinaryDiffValues.exec(symbolTableLines, tempdir, setiFileName, "TEMPLATE");
            System.out.println("done");

            for (String template : templateNames) {
                String mpadir = SettingsSingleton.getInstance().getProperty("mpadir");

                System.out.print("Generating test patterns from pattern-templates... " + template);
                VArrayList<String> fns = TemplateEngine.exec(new File(tempdir + template + ".testvalues"), true,
                        "$PATNAME$%LOWERCASE%.pat", false, template + ".template", new File("."),
                        new File(mpadir), null, null);
                System.out.println(" ...done");

                String patBaseName1 = fns.get(0).substring(0, fns.get(0).length() - 4);
                String mpaName1 = patBaseName1 + ".mpa";
                String patBaseName2 = fns.get(1).substring(0, fns.get(1).length() - 4);
                String mpaName2 = patBaseName2 + ".mpa";

                PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter("asdappattern.mk")));
                pw.println("asdappattern: " + mpaName1 + " " + mpaName2);
                pw.close();
                // now run the pattern compiler
                System.out.print("Running pattern compiler... " + template);
                if (fns.size() != 2)
                    throw new Exception("only one or more than two test patterns have been generated!");

                boolean silent = false;
                if (SettingsSingleton.getInstance().getProperty("silent").equals("true")) {
                    silent = true;
                }
                String[] makecommand = { "sh", "-c", SettingsSingleton.getInstance().getProperty("exec") };

                compile(makecommand, silent);
                System.out.println(" ...done");

                File mpaFile1 = new File(mpadir, mpaName1);
                File mapFile2 = new File(mpadir, mpaName2);
                if (!mpaFile1.exists())
                    throw new Exception("compiling didn't produce expected files " + mpaName1);
                if (!mapFile2.exists())
                    throw new Exception("compiling didn't produce expected files " + mpaName2);

                // generate the binary diffs
                System.out.print("Generating binary diff... " + template);
                if (setiFileName.length() > 0) {
                    BinaryDiff.exec(mpaName1, mpaName2, tempdir + template + ".diff", 4, 48, 48);
                } else {
                    BinaryDiff.exec(mpaName1, mpaName2, tempdir + template + ".diff", 4, 0, 0);
                }
                System.out.println(" ...done");

                // now find out which chunk corresponds to which variable
                // and
                // generate the diff template
                System.out.print("Trying to relate found differences to variables... " + template);
                GeneratePatchTemplate.exec(tempdir + template + ".diff", tempdir + template + ".possiblechunks",
                        tempdir + template + ".patchtemplate", symbolTableLines, template, mangled_combinations,
                        setiFileName);
                System.out.println(" ...done");
                // }

                // Take the template and run it through the template engine
                // template engine needs a switch for output dir!
                System.out.print("Generating patch... " + template);
                TemplateEngine.exec(new File(mangled_combinations), false, tempdir + template + ".patch", false,
                        tempdir + template + ".patchtemplate", new File("."), null, null, null);
                System.out.println(" ...done");

                // generate all the files by patching
                System.out.print("Patching... " + template);
                BinaryPatch.exec(tempdir + template + ".patch");
                System.out.println(" ...done");

                if (SettingsSingleton.getInstance().getProperty("noremove").equals("false")) {
                    new File(patBaseName1 + ".pat").delete();
                    new File(patBaseName2 + ".pat").delete();
                    if (!setiFileName.equals("")) {
                        new File(patBaseName1 + ".tmc").delete();
                        new File(patBaseName2 + ".tmc").delete();
                    }
                    new File(patBaseName1 + ".asc").delete();
                    new File(patBaseName2 + ".asc").delete();
                    mpaFile1.delete();
                    mapFile2.delete();
                    PrintWriter pw2 = new PrintWriter(new BufferedWriter(new FileWriter("asdappattern.mk")));
                    pw2.println("asdappattern: ");
                    pw2.close();
                }

            }
        }
    } catch (ParseException e) {
    } catch (TokenStreamException e) {
        System.out.println("TokenStreamException: " + e.getMessage());
    } catch (RecognitionException e) {
        System.out.println("RecognitionException: " + e.getMessage());
    } catch (Exception e) {
        System.out.println("Coordinator error: " + e.getMessage());
        System.exit(1);
    }
}

From source file:org.schreibubi.JCombinationsTools.coordinator.Coordinator.java

/**
 * @param args//  w  w w  .  j a v a 2 s  .  co  m
 */
public static void main(String[] args) {

    Info.printVersion("Coordinator");
    try {

        CoordinatorOptions[] settings = CoordinatorOptions.values();
        SettingsSingleton.initialize("Coordinator", settings);
        // command line arguments have the highest priority, so they go into level 2
        SettingsSingleton.getInstance().parseArguments(args, 2);

        if (SettingsSingleton.getInstance().getProperty("help").equals("true")) {
            SettingsSingleton.getInstance().displayHelp();
            Runtime.getRuntime().exit(0);
        }

        if (SettingsSingleton.getInstance().getProperty("version").equals("true")) {
            Info.printVersion("SetiPrinter");
            Runtime.getRuntime().exit(0);
        }

        String combinationFileName = SettingsSingleton.getInstance().getProperty("combinations");

        // pre-tags
        VArrayList<String> preTags = new VArrayList<String>();
        String preTagsString = SettingsSingleton.getInstance().getProperty("pretags");
        preTags = new VArrayList<String>(Arrays.asList(preTagsString.split(",")));
        // post-tags
        VArrayList<String> postTags = new VArrayList<String>();
        String postTagsString = SettingsSingleton.getInstance().getProperty("posttags");
        postTags = new VArrayList<String>(Arrays.asList(postTagsString.split(",")));

        FileNameLookupSingleton.initialize(preTags, postTags);

        File dir = new File(combinationFileName).getAbsoluteFile().getParentFile();
        File combinationFile = FileNameLookupSingleton.getInstance().lookup(dir, combinationFileName);
        System.out.println("Processing: " + combinationFile.getName());

        // Generate all possible combinations
        System.out.print("Generating and evaluation all combinations...");
        VHashMap<String> optionsFromEvalGenWalker = new VHashMap<String>();
        VArrayList<VHashMap<Symbol>> symbolTableLines = EvalGenCombinations
                .exec(new FileReader(combinationFile), dir, optionsFromEvalGenWalker);
        System.out.println("done");

        // now additional default options are known...
        // -----------------------------------------------------------------------------
        String argumentsString = optionsFromEvalGenWalker.get("Coordinator");
        if (argumentsString != null) {
            String[] arguments = argumentsString.split(" ");
            SettingsSingleton.getInstance().parseArguments(arguments, 1);
        }

        if (SettingsSingleton.getInstance().areRequiredOptionsSet() == false) {
            SettingsSingleton.getInstance().displayHelp();
            Runtime.getRuntime().exit(0);
        }

        String conditionFilePrefix = SettingsSingleton.getInstance().getProperty("conditionprefix");

        boolean ignoreMissingCBMpos = false;
        if (SettingsSingleton.getInstance().getProperty("ignoremissingcbmpos").equals("true")) {
            ignoreMissingCBMpos = true;
        }
        boolean silent = false;
        if (SettingsSingleton.getInstance().getProperty("silent").equals("true")) {
            silent = true;
        }

        String cbmOutputDir = SettingsSingleton.getInstance().getProperty("cbmdir");
        String patternInputDir = SettingsSingleton.getInstance().getProperty("patterndir");
        String pcfOutputDir = SettingsSingleton.getInstance().getProperty("pcfdir");

        int cbmOffset = Integer.parseInt(SettingsSingleton.getInstance().getProperty("cbmOffset"));

        String conditionFileTemplateName = conditionFilePrefix + ".template";
        String conditionFileHeaderName = conditionFilePrefix + ".header";

        if (!SettingsSingleton.getInstance().getProperty("conditiontemplate").equals("")) {
            conditionFileTemplateName = SettingsSingleton.getInstance().getProperty("conditiontemplate");
        }
        if (!SettingsSingleton.getInstance().getProperty("conditionheader").equals("")) {
            conditionFileHeaderName = SettingsSingleton.getInstance().getProperty("conditionheader");
        }

        String conditionFileName = "";
        if (!SettingsSingleton.getInstance().getProperty("condition").equals("")) {
            conditionFileName = SettingsSingleton.getInstance().getProperty("condition");
        } else {
            int dotPos = combinationFileName.indexOf(".");
            if (dotPos > -1) {
                conditionFileName = conditionFilePrefix + "_" + combinationFileName.subSequence(0, dotPos);
            } else {
                conditionFileName = conditionFilePrefix + "_" + combinationFileName;
            }
        }
        String setiFile = SettingsSingleton.getInstance().getProperty("seti");
        // -----------------------------------------------------------------------------
        if (SettingsSingleton.getInstance().getProperty("nocbmgen").equals("false")) {
            boolean filesWereOverwritten = false;
            System.out.print("Creating CBM dat files...");

            SetiChainBuilder constructSetiChain = new SetiChainBuilder(setiFile);

            VHashMap<TemplateInfo> templateInfos = new VHashMap<TemplateInfo>();

            HashMap<String, Integer> patCbmSettings = new HashMap<String, Integer>();

            int cbmPatternCount = cbmOffset;

            for (ListIterator<VHashMap<Symbol>> i = symbolTableLines.listIterator(); i.hasNext();) {
                /* get variables used to fill out the actual template */
                VHashMap<Symbol> sT = i.next();

                String patName = sT.get("PATNAME").convertToString().getValue();
                TemplateInfo tI = templateInfos.get(patName);
                // if template was not done already before
                if (tI == null) {
                    // read in the cbm position file for this template
                    tI = readCBMpos(patternInputDir, patName, ignoreMissingCBMpos);
                    if (tI == null) {
                        if (!silent) {
                            System.err.println("WARNING: " + patName
                                    + ".asc does not contain a cbm part, but ignored due to manual override!");
                        }
                    } else {
                        templateInfos.put(patName, tI);
                    }
                }

                if (tI != null) {
                    // check if we already have a dat file with the same settings...
                    VArrayList<Symbol> currentSymbols = selectSymbols(sT, tI.getCbmNames());
                    currentSymbols.add(sT.get("PATNAME"));

                    Integer foundNumber = patCbmSettings.get(currentSymbols.toString());
                    if (foundNumber != null) {
                        // we have already a dat file containing the same settings
                        // so set the CBMNAME accordingly
                        sT.put("CBMNAME", new SymbolString(Integer.toHexString(foundNumber).toUpperCase()));
                    } else {
                        // first time we have these conditions
                        cbmPatternCount++;
                        String cbmName = Integer.toHexString(cbmPatternCount);

                        VArrayList<String> cbmNames = tI.getCbmNames();

                        // remember our settings...
                        VArrayList<Symbol> selectedSymbols = selectSymbols(sT, cbmNames);
                        selectedSymbols.add(sT.get("PATNAME"));
                        patCbmSettings.put(selectedSymbols.toString(), cbmPatternCount);

                        sT.put("CBMNAME", new SymbolString(cbmName.toUpperCase()));

                        // calculate seti-chains and put them in CBM chunks
                        for (CBMChunk chunk : tI.getCbms())
                            if (sT.get(chunk.getName()) != null) {
                                VArrayList<Integer> content = constructSetiChain.createCBMChain(
                                        sT.get(chunk.getName()).convertToString(), tI.getChannels(),
                                        chunk.getLength(), chunk.getSetiType());
                                chunk.setCbmContent(content);
                            }
                        // now optimize CBMChunks (are already in ascending
                        // order, so we only need to check the next one)
                        VArrayList<CBMChunk> compressedChunks = new VArrayList<CBMChunk>(tI.getCbms());

                        // write them to file

                        File cbmOutput = new File(cbmOutputDir, cbmName + ".dat");
                        if (cbmOutput.exists()) {
                            filesWereOverwritten = true;
                        }
                        DataOutputStream out = new DataOutputStream(
                                new BufferedOutputStream(new FileOutputStream(cbmOutput)));
                        out.writeInt(compressedChunks.size());
                        for (CBMChunk chunk : compressedChunks)
                            if (sT.get(chunk.getName()) != null) {
                                // output hexstring to cbm-file
                                out.writeInt(chunk.getStart());
                                out.writeInt(chunk.getLength());
                                for (Integer integer : chunk.getCbmContent()) {
                                    out.writeInt(integer);
                                }
                            } else
                                throw new Exception(chunk.getName() + " does not exist");

                        out.close();
                    }
                } else {
                    sT.put("CBMNAME", new SymbolString(""));
                }
            }
            System.out.println("done");
            if ((!silent) && (filesWereOverwritten)) {
                System.err.println("WARNING: Some .dat files were overwritten!");
            }
        } else {
            // Even if no CBM.dat generation is requested, we need to set the CBMNAME...
            for (ListIterator<VHashMap<Symbol>> i = symbolTableLines.listIterator(); i.hasNext();) {
                /* get variables used to fill out the actual template */
                VHashMap<Symbol> sT = i.next();
                sT.put("CBMNAME", new SymbolString(""));
            }
        }

        if (SettingsSingleton.getInstance().getProperty("nopcf").equals("false")) {
            // Create the condition file
            System.out.print("Creating " + conditionFileName + "...");
            TemplateEngine.exec(symbolTableLines, false, conditionFileName, false, conditionFileTemplateName,
                    new File("."), new File(pcfOutputDir), new File(conditionFileHeaderName), null);
            System.out.println("done");
        }

    } catch (ParseException e) {
    } catch (TokenStreamException e) {
        System.out.println("TokenStreamException: " + e.getMessage());
    } catch (RecognitionException e) {
        System.out.println("RecognitionException: " + e.getMessage());
    } catch (Exception e) {
        System.out.println("Coordinator error: " + e.getMessage());
        e.printStackTrace();
        System.exit(1);
    }
}

From source file:Main.java

/**
 * @param bssid the device's bssid/* w ww  . j av  a2 s . co m*/
 * @return whether the device's bssid is belong to sta state
 */
public static boolean isStaDevice(String bssid) {
    return bssid.subSequence(0, 2).equals("18");
}

From source file:Main.java

/**
 * @param bssid the device's bssid//from   w ww.  ja  v  a2  s. com
 * @return whether the device's bssid is belong to softap state
 */
public static boolean isSoftapDevice(String bssid) {
    return bssid.subSequence(0, 2).equals("1a");
}

From source file:com.fjn.helper.common.util.StringUtil.java

/**
 * dateFromDB??,?yyyy-MM-dd hh:mm:ss.n ???yyyy-MM-dd
 * @param dateFromDB/*from w  w w.  ja  v a 2s.  c  om*/
 * @return
 */
public static String getYMonth(String dateFromDB) {
    return dateFromDB.subSequence(0, 10).toString();
}