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:com.splunk.shuttl.archiver.util.UtilsURI.java

/**
 * Trim eventual ending {@link File#separator}.<br/>
 * Ex:<br/>//from www .  j  a  va2 s .  c om
 * 
 * <pre>
 * "file:/a/b/c" -> "/a/b/c"
 * "file:/a/b/c/" -> "/a/b/c"
 * "file:/a/b/c.txt" -> "/a/b/c.txt"
 * </pre>
 */
public static String getPathByTrimmingEndingFileSeparator(URI uri) {
    String path = uri.getPath();
    if (path.endsWith(File.separator))
        return path.substring(0, path.length() - 1);
    else
        return path;
}

From source file:Main.java

public static long obdVersionStringToLong(String obdVerison) {
    if ("".equals(obdVerison))
        return 0;
    if (obdVerison.endsWith("S"))
        obdVerison = obdVerison.substring(0, obdVerison.length() - 1);
    String[] obdVersionArray = obdVerison.split("\\.");
    return Long.valueOf(obdVersionArray[0] + obdVersionArray[1] + obdVersionArray[2]);
}

From source file:Main.java

/**
 * Returns album IDs containing at least one cached track.
 * @return Albums IDs//from www. j  av  a2  s . com
 */
public static Set<String> getCachedAlbumSet() {
    File cacheDir = getMusicCacheDir();
    File[] albumList = cacheDir.listFiles();
    Set<String> output = new HashSet<>();
    for (File album : albumList) {
        if (album.list(new FilenameFilter() {
            @Override
            public boolean accept(File dir, String filename) {
                return filename.endsWith(".complete");
            }
        }).length > 0) {
            output.add(album.getName());
        }
    }
    return output;
}

From source file:Main.java

/**
 * Translates a XML file name to a Java file name according
 * to Android naming convention.//from w  w w  . j a va  2s.  c  o  m
 *
 * Doesn't append .java extension
 *
 * @return Java file name associated with XML file name
 */
public static String getJavaFileNameFromXmlFileName(String xmlFileName) {

    if (xmlFileName.endsWith(".xml")) {
        // cut off ".xm"
        xmlFileName = xmlFileName.substring(0, xmlFileName.length() - 4);
    }

    char[] charsXml = xmlFileName.toCharArray();
    StringBuilder stringBuilder = new StringBuilder();
    // make the first char upper case
    stringBuilder.append(Character.toUpperCase(charsXml[0]));
    // start looking for '_' at the second char
    for (int i = 1; i < charsXml.length; i++) {
        char currentChar = charsXml[i];
        if (currentChar == '_') {
            // skip '_' and add the next char as upper case
            char toAppend = Character.toUpperCase(charsXml[++i]);
            stringBuilder.append(toAppend);
        } else {
            stringBuilder.append(currentChar);
        }
    }
    return stringBuilder.toString();
}

From source file:Main.java

/**
 * Get the string enclosed with quote.//from   w ww.j  a  va2  s  . c o m
 * 
 * @param string
 * @return
 */
public static String addQuote(String string) {
    if (string != null && (!(string.startsWith("\"") && string.endsWith("\"")))) //$NON-NLS-1$//$NON-NLS-2$
    {
        return "\"" + string + "\""; //$NON-NLS-1$//$NON-NLS-2$
    }
    return string;
}

From source file:mergedoc.Application.java

/**
 * ? Look & Feel ???//from  ww w . j a  va  2 s . c  om
 * @throws ClassNotFoundException LookAndFeel ????????
 * @throws InstantiationException ????????????
 * @throws IllegalAccessException ????????????
 * @throws UnsupportedLookAndFeelException lnf.isSupportedLookAndFeel() ? false ??
 */
private static void initSystemLookAndFeel() throws ClassNotFoundException, InstantiationException,
        IllegalAccessException, UnsupportedLookAndFeelException {
    UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    Toolkit.getDefaultToolkit().setDynamicLayout(true);

    // Windows ???
    String osName = System.getProperty("os.name", "");
    if (osName.indexOf("Windows") != -1) {

        Object propoFont = new FontUIResource("MS UI Gothic", Font.PLAIN, 12);
        Object fixedFont = new FontUIResource("MS Gothic", Font.PLAIN, 12);

        // ??????????
        // ????? instanceof FontUIResource ?
        // ???UIDefaults ? Lazy Value ??????
        for (Object keyObj : UIManager.getLookAndFeelDefaults().keySet()) {
            String key = keyObj.toString();
            if (key.endsWith("font") || key.endsWith("Font")) {
                UIManager.put(key, propoFont);
            }
        }

        // ?????
        UIManager.put("OptionPane.messageFont", fixedFont);
        UIManager.put("TextPane.font", fixedFont);
        UIManager.put("TextArea.font", fixedFont);
    }
}

From source file:Main.java

public static String trimQuote(String origin) {
    String afterConvert = origin;
    if (origin.startsWith("\"") && origin.endsWith("\"")) {
        afterConvert = afterConvert.substring(1, afterConvert.length() - 1);
    }/*  w w w.  j a  v  a  2 s . c o m*/
    return afterConvert;
}

From source file:Main.java

public static Class<?> findClass(String name, Collection<String> availableImports, ClassLoader cl) {
    Class<?> clazz = null;//  ww  w. ja va 2  s  .  c  om
    for (String imp : availableImports) {
        if (imp.endsWith(".*")) {
            imp = imp.substring(0, imp.length() - 2);
        }
        String className = imp.endsWith(name) ? imp : imp + "." + name;
        clazz = findClass(className, cl);
        if (clazz != null) {
            break;
        }
    }
    return clazz;
}

From source file:Main.java

public static String concatPath(String a, String b, String separator) {
    if (a.endsWith(separator) && b.startsWith(separator)) {
        return a + b.substring(1);
    } else if (a.endsWith(separator)) {
        return a + b;
    } else if (b.startsWith(separator)) {
        return a + b;
    }/*ww w. j a  v  a2s  .  c o  m*/
    return a + separator + b;
}

From source file:Main.java

public static String prepareFilePathForVideoSaveWithDraftUri(Uri draftUri) {
    String draftPath = draftUri.getPath();
    String draftMediaDirPath = draftPath.substring(0, draftPath.length() - 5);
    File draftMediaDir = new File(draftMediaDirPath);
    if (!draftMediaDir.exists()) {
        draftMediaDir.mkdirs();/*w ww. jav  a2s. co m*/
    }
    String[] files = draftMediaDir.list(new FilenameFilter() {
        @Override
        public boolean accept(File dir, String filename) {
            return filename.endsWith("-0.mp4") || filename.endsWith("-a.mp4");
        }
    });
    List<String> filePaths = Arrays.asList(files);
    Collections.sort(filePaths, new Comparator<String>() {
        @Override
        public int compare(String lhs, String rhs) {
            return rhs.compareTo(lhs);
        }
    });
    if (filePaths.size() > 0) {
        for (String file : filePaths) {
            return new File(draftMediaDir, file.substring(0, file.length() - 6) + ".mp4").getAbsolutePath();
        }
    }
    return new File(draftMediaDir, generateRandomFilename("mp4")).getAbsolutePath();
}