Example usage for java.lang String endsWith

List of usage examples for java.lang String endsWith

Introduction

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

Prototype

public boolean endsWith(String suffix) 

Source Link

Document

Tests if this string ends with the specified suffix.

Usage

From source file:Main.java

public static boolean isMatchingSigFile(File originalFile, File nextSignatureFile) {
    String orginalFilename = originalFile.getName();
    String nextFilename = nextSignatureFile.getName();

    boolean isMatchingSigFile = nextFilename.endsWith(".sig") && nextFilename.startsWith(orginalFilename);

    return isMatchingSigFile;
}

From source file:Main.java

/**
 * Build an Capptain alias for an Android Activity class. This implementation takes the simple
 * name of the class and removes the "Activity" suffix if any (e.g. "com.mycompany.MainActivity"
 * becomes "Main").<br/>/*  ww  w . j a va2s  .c  o  m*/
 * This method is used by {@link CapptainActivity} and its variants.
 * @return an activity name suitable to be reported by the Capptain service.
 */
public static String buildCapptainActivityName(Class<?> activityClass) {
    String name = activityClass.getSimpleName();
    String suffix = "Activity";
    if (name.endsWith(suffix) && name.length() > suffix.length())
        return name.substring(0, name.length() - suffix.length());
    else
        return name;
}

From source file:com.baomidou.framework.common.JarHelper.java

public static List<String> listFiles(JarFile jarFile, String endsWith) {
    if (jarFile == null || StringUtils.isEmpty(endsWith)) {
        return null;
    }/*from   w  w w  .j a  v a  2  s .  co  m*/
    List<String> files = new ArrayList<String>();
    Enumeration<JarEntry> entries = jarFile.entries();
    while (entries.hasMoreElements()) {
        JarEntry entry = entries.nextElement();
        String name = entry.getName();
        if (name.endsWith(endsWith)) {
            files.add(name);
        }
    }
    return files;
}

From source file:Main.java

public static String getLastPath(String path) {
    String strippedPath = removeLastPath(path);

    if (strippedPath == null) {
        return null;
    }/*w  w  w.j a  v a 2 s  . c  om*/

    if (strippedPath.equals(path)) {
        return null;
    } else {
        String result = path.substring(strippedPath.length() + 1);

        if (result.endsWith("/")) {
            result = result.substring(0, result.length() - 1);
        }

        return result;
    }
}

From source file:Main.java

public static String formatValue(double value) {
    if (value < 0) {
        throw new NumberFormatException("Negative value " + value);
    }/*from w ww  .  j a  v a  2  s  .  c  o  m*/
    String s = String.format("%.8f", value);
    while (s.length() > 1 && (s.endsWith("0") || s.endsWith("."))) {
        s = (s.substring(0, s.length() - 1));
    }
    return s;
}

From source file:Main.java

/**
 * Dialog for choosing file./*from  www  .  ja  v  a  2 s.com*/
 * 
 * @param parent the parent component of the dialog, can be null
 * @return selected file or null if no file is selected
 */
public static File chooseImageFile(Component parent) {
    JFileChooser fileChooser = new JFileChooser();
    fileChooser.setFileFilter(new FileFilter() {
        @Override
        public String getDescription() {
            return "Supported image files(JPEG, PNG, BMP)";
        }

        @Override
        public boolean accept(File f) {
            String name = f.getName();
            boolean accepted = f.isDirectory() || name.endsWith(".jpg") || name.endsWith(".jpeg")
                    || name.endsWith(".jp2") || name.endsWith(".png") || name.endsWith(".bmp");
            return accepted;
        }
    });

    fileChooser.showOpenDialog(parent);
    return fileChooser.getSelectedFile();
}

From source file:Main.java

public static String substringAfterLast(String string, String delimiter) {
    final int index = string.lastIndexOf(delimiter);
    if (index == -1 || string.endsWith(delimiter)) {
        return "";
    }//from   w ww.  java  2  s  . c o m
    return string.substring(index + 1);
}

From source file:Main.java

/**
 * Dialog for choosing file./*w  w w  . j a  v a  2 s . co  m*/
 * 
 * @param parent the parent component of the dialog, can be null
 * @return selected file or null if no file is selected
 */
public static File chooseImageFile(Component parent) {
    JFileChooser fileChooser = new JFileChooser();
    fileChooser.setFileFilter(new FileFilter() {
        @Override
        public String getDescription() {
            return "Supported image files(JPEG, PNG, BMP)";
        }

        @Override
        public boolean accept(File f) {
            String name = f.getName();
            boolean accepted = f.isDirectory() || name.endsWith(".jpg") || name.endsWith(".jpeg")
                    || name.endsWith(".png") || name.endsWith(".bmp");
            return accepted;
        }
    });

    fileChooser.showOpenDialog(parent);
    return fileChooser.getSelectedFile();
}

From source file:be.fgov.kszbcss.rhq.websphere.component.j2ee.ModuleInfoFactory.java

private static String search(String[] list, String suffix) {
    for (String item : list) {
        if (item.endsWith(suffix)) {
            return item;
        }// w  w w. jav a2 s.  c  o m
    }
    return null;
}

From source file:com.thoughtworks.go.util.StringUtil.java

public static String removeTrailingSlash(String s) {
    if (s.endsWith("/")) {
        return s.substring(0, s.length() - 1);
    }//from  ww  w  .jav  a  2  s. c  o m
    return s;
}