Example usage for java.lang String lastIndexOf

List of usage examples for java.lang String lastIndexOf

Introduction

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

Prototype

public int lastIndexOf(String str) 

Source Link

Document

Returns the index within this string of the last occurrence of the specified substring.

Usage

From source file:MinAppletviewer.java

public static void main(String args[]) throws Exception {
    AppSupport theAppSupport = new AppSupport();
    JFrame f = new JFrame();
    URL toload = new URL(args[0]);
    String host = toload.getHost();
    int port = toload.getPort();
    String protocol = toload.getProtocol();
    String path = toload.getFile();
    int join = path.lastIndexOf('/');
    String file = path.substring(join + 1);
    path = path.substring(0, join + 1);//from   ww  w.j a  v a  2  s . c o m

    theAppSupport.setCodeBase(new URL(protocol, host, port, path));
    theAppSupport.setDocumentBase(theAppSupport.getCodeBase());

    URL[] bases = { theAppSupport.getCodeBase() };
    URLClassLoader loader = new URLClassLoader(bases);
    Class theAppletClass = loader.loadClass(file);
    Applet theApplet = (Applet) (theAppletClass.newInstance());

    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    f.add(theApplet, BorderLayout.CENTER);

    theApplet.setStub(theAppSupport);

    f.setSize(200, 200);
    f.setVisible(true);
    theApplet.init();
    theApplet.start();
}

From source file:MainClass.java

public static void main(String args[]) {
    String name = "http://urlWithClassName";
    try {//from   w ww .j a va  2s  .  c  o  m
        if (!name.endsWith(".class")) {
            System.err.println("That doesn't look like a byte code file!");
            return;
        }
        URL u = new URL(name);
        URLClassLoader ucl = new URLClassLoader(u);

        // parse out the name of the class from the URL
        String s = u.getFile();
        String classname = s.substring(s.lastIndexOf('/'), s.lastIndexOf(".class"));
        Class AppletClass = ucl.loadClass(classname, true);
        Applet apl = (Applet) AppletClass.newInstance();
        JFrame f = new JFrame();
        f.setSize(200, 200);
        f.add("Center", apl);
        apl.init();
        apl.start();
        f.setVisible(true);
    } catch (Exception e) {
        System.err.println(e);
    }
}

From source file:indexOfDemo.java

public static void main(String args[]) {
    String s = "Now is the time for all good men " + "to come to the aid of their country.";

    System.out.println(s);//  ww  w.  j a  v  a 2  s .  c o  m
    System.out.println("indexOf(t) = " + s.indexOf('t'));
    System.out.println("lastIndexOf(t) = " + s.lastIndexOf('t'));
    System.out.println("indexOf(the) = " + s.indexOf("the"));
    System.out.println("lastIndexOf(the) = " + s.lastIndexOf("the"));
    System.out.println("indexOf(t, 10) = " + s.indexOf('t', 10));
    System.out.println("lastIndexOf(t, 60) = " + s.lastIndexOf('t', 60));
    System.out.println("indexOf(the, 10) = " + s.indexOf("the", 10));
    System.out.println("lastIndexOf(the, 60) = " + s.lastIndexOf("the", 60));
}

From source file:com.glaf.core.startup.MultiDBNativeCmdStartup.java

public static void main(String[] args) {
    String url = "jdbc:sqlserver://127.0.0.1:1433;databaseName=pMagic2013";
    System.out.println(url.substring(url.lastIndexOf("=") + 1, url.length()));
    url = "jdbc:jtds:sqlserver://127.0.0.1:1433/pMagic2013";
    System.out.println(url.substring(url.lastIndexOf("/") + 1, url.length()));
}

From source file:com.tonygalati.sprites.SpriteGenerator.java

public static void main(String[] args) throws IOException {

    //        if (args.length != 3)
    //        {//w w w  .j a va 2s  . c o m
    //           System.out.print("Usage: com.tonygalati.sprites.SpriteGenerator {path to images} {margin between images in px} {output file}\n");
    //           System.out.print("Note: The max height should only be around 32,767px due to Microsoft GDI using a 16bit signed integer to store dimensions\n");
    //           System.out.print("going beyond this dimension is possible with this tool but the generated sprite image will not work correctly with\n");
    //           System.out.print("most browsers.\n\n");
    //           return;
    //        }

    //        Integer margin = Integer.parseInt(args[1]);
    Integer margin = Integer.parseInt("1");
    String spriteFile = "icons-" + RandomStringUtils.randomAlphanumeric(10) + ".png";
    SpriteCSSGenerator cssGenerator = new SpriteCSSGenerator();

    ClassLoader classLoader = SpriteGenerator.class.getClassLoader();
    URL folderPath = classLoader.getResource(NAIC_SMALL_ICON);
    if (folderPath != null) {
        File imageFolder = new File(folderPath.getPath());

        // Read images
        ArrayList<BufferedImage> imageList = new ArrayList<BufferedImage>();
        Integer yCoordinate = null;

        for (File f : imageFolder.listFiles()) {
            if (f.isFile()) {
                String fileName = f.getName();
                String ext = fileName.substring(fileName.lastIndexOf(".") + 1, fileName.length());

                if (ext.equals("png")) {
                    System.out.println("adding file " + fileName);
                    BufferedImage image = ImageIO.read(f);
                    imageList.add(image);

                    if (yCoordinate == null) {
                        yCoordinate = 0;
                    } else {
                        yCoordinate += (image.getHeight() + margin);
                    }

                    // add to cssGenerator
                    cssGenerator.addSpriteCSS(fileName.substring(0, fileName.indexOf(".")), 0, yCoordinate);
                }
            }
        }

        // Find max width and total height
        int maxWidth = 0;
        int totalHeight = 0;

        for (BufferedImage image : imageList) {
            totalHeight += image.getHeight() + margin;

            if (image.getWidth() > maxWidth)
                maxWidth = image.getWidth();
        }

        System.out.format("Number of images: %s, total height: %spx, width: %spx%n", imageList.size(),
                totalHeight, maxWidth);

        // Create the actual sprite
        BufferedImage sprite = new BufferedImage(maxWidth, totalHeight, BufferedImage.TYPE_INT_ARGB);

        int currentY = 0;
        Graphics g = sprite.getGraphics();
        for (BufferedImage image : imageList) {
            g.drawImage(image, 0, currentY, null);
            currentY += image.getHeight() + margin;
        }

        System.out.format("Writing sprite: %s%n", spriteFile);
        ImageIO.write(sprite, "png", new File(spriteFile));
        File cssFile = cssGenerator.getFile(spriteFile);
        System.out.println(cssFile.getAbsolutePath() + " created");
    } else {
        System.err.println("Could not find folder: " + NAIC_SMALL_ICON);

    }

}

From source file:WebLauncher.java

public static void main(String[] args) {
    DirectJNI.init();//from   www .  j a  v  a  2 s .c om
    for (String className : DirectJNI._rPackageInterfacesHash.keySet()) {
        String shortClassName = className.substring(className.lastIndexOf('.') + 1);
        try {
            Class packageWebClass = DirectJNI._mappingClassLoader.loadClass(className + "Web");
            if (packageWebClass.getDeclaredMethods().length > 0) {
                try {
                    String url = "http://localhost:8080/" + "ws/" + shortClassName;
                    Endpoint.publish(url, packageWebClass.newInstance());
                    System.out.println(shortClassName + "Web" + " has been successfully published to " + url);
                } catch (Exception ie) {
                    ie.printStackTrace();
                }
            }
        } catch (ClassNotFoundException e) {
        }
    }
}

From source file:net.kamhon.ieagle.vo.ManagerList.java

public static void main(String a[]) {
    try {/*from  w w  w .j a v  a  2  s.  co  m*/
        Set<String> clazzStr = ReflectionUtil.findFileNames("com", true, "net.kamhon.+?\\.manager\\..+?");
        for (String str : clazzStr) {
            // if (clazz.) {
            // add(clazz);
            // }
            // add(str.getClass().getName());
            log.info((str.substring(str.lastIndexOf(".") + 1).charAt(0) + "").toLowerCase()
                    + str.substring(str.lastIndexOf(".") + 2));
        }

    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:Main.java

public static void main(String[] args) {
    String str = new String("Apple");

    int index = str.indexOf('p'); // index will have a value of 1
    System.out.println(index);/*from w  w  w.  j  av  a  2s.  c o m*/

    index = str.indexOf("pl"); // index will have a value of 2
    System.out.println(index);
    index = str.lastIndexOf('p'); // index will have a value of 2
    System.out.println(index);

    index = str.lastIndexOf("pl"); // index will have a value of 2
    System.out.println(index);

    index = str.indexOf("k"); // index will have a value of -1
    System.out.println(index);
}

From source file:org.glowroot.benchmark.ResultFormatter.java

public static void main(String[] args) throws IOException {
    File resultFile = new File(args[0]);

    Scores scores = new Scores();
    double baselineStartupTime = -1;
    double glowrootStartupTime = -1;

    ObjectMapper mapper = new ObjectMapper();
    String content = Files.toString(resultFile, Charsets.UTF_8);
    content = content.replaceAll("\n", " ");
    ArrayNode results = (ArrayNode) mapper.readTree(content);
    for (JsonNode result : results) {
        String benchmark = result.get("benchmark").asText();
        benchmark = benchmark.substring(0, benchmark.lastIndexOf('.'));
        ObjectNode primaryMetric = (ObjectNode) result.get("primaryMetric");
        double score = primaryMetric.get("score").asDouble();
        if (benchmark.equals(StartupBenchmark.class.getName())) {
            baselineStartupTime = score;
            continue;
        } else if (benchmark.equals(StartupWithGlowrootBenchmark.class.getName())) {
            glowrootStartupTime = score;
            continue;
        }/*from ww  w . ja  v  a2s.  co m*/
        ObjectNode scorePercentiles = (ObjectNode) primaryMetric.get("scorePercentiles");
        double score50 = scorePercentiles.get("50.0").asDouble();
        double score95 = scorePercentiles.get("95.0").asDouble();
        double score99 = scorePercentiles.get("99.0").asDouble();
        double score999 = scorePercentiles.get("99.9").asDouble();
        double score9999 = scorePercentiles.get("99.99").asDouble();
        double allocatedBytes = getAllocatedBytes(result);
        if (benchmark.equals(ServletBenchmark.class.getName())) {
            scores.baselineResponseTimeAvg = score;
            scores.baselineResponseTime50 = score50;
            scores.baselineResponseTime95 = score95;
            scores.baselineResponseTime99 = score99;
            scores.baselineResponseTime999 = score999;
            scores.baselineResponseTime9999 = score9999;
            scores.baselineAllocatedBytes = allocatedBytes;
        } else if (benchmark.equals(ServletWithGlowrootBenchmark.class.getName())) {
            scores.glowrootResponseTimeAvg = score;
            scores.glowrootResponseTime50 = score50;
            scores.glowrootResponseTime95 = score95;
            scores.glowrootResponseTime99 = score99;
            scores.glowrootResponseTime999 = score999;
            scores.glowrootResponseTime9999 = score9999;
            scores.glowrootAllocatedBytes = allocatedBytes;
        } else {
            throw new AssertionError(benchmark);
        }
    }
    System.out.println();
    printScores(scores);
    if (baselineStartupTime != -1) {
        System.out.println("STARTUP");
        System.out.format("%25s%14s%14s%n", "", "baseline", "glowroot");
        printLine("Startup time (avg)", "ms", baselineStartupTime, glowrootStartupTime);
    }
    System.out.println();
}

From source file:dk.statsbiblioteket.util.qa.PackageScannerDriver.java

/**
 * @param args The command line arguments.
 * @throws IOException If command line arguments can't be passed or there
 *                     is an error reading class files.
 *//*from  ww w  .  jav a 2 s. c  o  m*/
@SuppressWarnings("deprecation")
public static void main(final String[] args) throws IOException {
    Report report;
    CommandLine cli = null;
    String reportType, projectName, baseSrcDir, targetPackage;
    String[] targets = null;

    // Build command line options
    CommandLineParser cliParser = new PosixParser();
    Options options = new Options();
    options.addOption("h", "help", false, "Print help message and exit");
    options.addOption("n", "name", true, "Project name, default 'Unknown'");
    options.addOption("o", "output", true, "Type of output, 'plain' or 'html', default is html");
    options.addOption("p", "package", true, "Only scan a particular package in input dirs, use dotted "
            + "package notation to refine selections");
    options.addOption("s", "source-dir", true,
            "Base source dir to use in report, can be a URL. " + "@FILE@ and @MODULE@ will be escaped");

    // Parse and validate command line
    try {
        cli = cliParser.parse(options, args);
        targets = cli.getArgs();
        if (args.length == 0 || targets.length == 0 || cli.hasOption("help")) {
            throw new ParseException("Not enough arguments, no input files");
        }
    } catch (ParseException e) {
        printHelp(options);
        System.exit(1);
    }

    // Extract information from command line
    reportType = cli.getOptionValue("output") != null ? cli.getOptionValue("output") : "html";

    projectName = cli.getOptionValue("name") != null ? cli.getOptionValue("name") : "Unknown";

    baseSrcDir = cli.getOptionValue("source-dir") != null ? cli.getOptionValue("source-dir")
            : System.getProperty("user.dir");

    targetPackage = cli.getOptionValue("package") != null ? cli.getOptionValue("package") : "";
    targetPackage = targetPackage.replace(".", File.separator);

    // Set up report type
    if ("plain".equals(reportType)) {
        report = new BasicReport();
    } else {
        report = new HTMLReport(projectName, System.out, baseSrcDir);
    }

    // Do actual scanning of provided targets
    for (String target : targets) {
        PackageScanner scanner;
        File f = new File(target);

        if (f.isDirectory()) {
            scanner = new PackageScanner(report, f, targetPackage);
        } else {
            String filename = f.toString();
            scanner = new PackageScanner(report, f.getParentFile(),
                    filename.substring(filename.lastIndexOf(File.separator) + 1));
        }
        scanner.scan();
    }

    // Cloce the report before we exit
    report.end();
}