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.plan.proyecto.servicios.utilidades.UrlParser.java

public static List<String> pullLinks(String text) {

    List<String> links = new ArrayList();

    String regex = "\\(?\\b(http://|www[.])[-A-Za-z0-9+&@#/%?=~_()|!:,.;]*[-A-Za-z0-9+&@#/%=~_()|]";
    Pattern p = Pattern.compile(regex);
    Matcher m = p.matcher(text);//from  www.  j  a  v a 2  s  . c  o  m
    while (m.find()) {
        String urlStr = m.group();
        if (urlStr.startsWith("(") && urlStr.endsWith(")")) {
            urlStr = urlStr.substring(1, urlStr.length() - 1);
        }
        links.add(urlStr);
    }
    return links;
}

From source file:Main.java

public static boolean checkEndsWithInStringArray(String checkItsEnd, String[] fileEndings) {

    for (String aEnd : fileEndings) {
        if (checkItsEnd.endsWith(aEnd))
            return true;
    }/* ww w.j  a v  a2 s  .  com*/
    return false;
}

From source file:Main.java

/**
 * Given a web services URI or sub-path, intelligently parse out the correct top-level key
 * to use when applying configuration to the WVA.
 *
 * <p>//from ww w. ja  va 2  s  . c  o  m
 *     For example, when interacting with {@code ws/config/canbus/1}, the JSON we send down
 *     must have the top-level key {@code canbus}.
 * </p>
 *
 * @param uri the full request path, or a section of that, to be used when applying configuration
 * to the WVA
 * @return
 * <ul>
 *     <li>
 *         The first piece of the given path following {@code config/}, if {@code config/} is
 *         present in the path. This represents the settings group being configured, which is
 *         the correct string to use as the top-level key.
 *     </li>
 *     <li>
 *         <b>null</b> if the last piece of the path is {@code config}, implying that
 *          we will be unable to decide which key to use (because it is not clear what is
 *          being configured).
 *     </li>
 *     <li>
 *         The first piece of the path, if {@code config} is not found as a section of the path.
 *         This implies that <b>uri</b> is the path under {@code ws/config/} being used, and as
 *         such, the first section of the path represents the settings group being configured.
 *     </li>
 * </ul>
 */
public static String getConfigKeyFromUri(String uri) {
    if (uri.endsWith("/")) {
        // If there's a trailing slash, remove it.
        uri = uri.substring(0, uri.length() - 1);
    }
    String[] pieces = uri.split("/");
    // Take the first piece after 'config'. If 'config/' is not present, then take
    // the first piece of the URI.
    int configIndex = -1;
    for (int i = 0; i < pieces.length; i++) {
        if ("config".equals(pieces[i])) {
            configIndex = i;
            break;
        }
    }

    if (configIndex != -1) {
        if (configIndex == pieces.length - 1) {
            // config was the last piece of the path.
            return null;
        }

        return pieces[configIndex + 1];
    } else {
        // config not present in path. Return the first piece
        return pieces[0];
    }
}

From source file:com.marvelution.jira.plugins.hudson.services.servers.HudsonServerUtils.java

/**
 * Get a Whitelist url for the given url
 * //from w w w . ja  v  a2s . c o  m
 * @param url the url to get a whitelist url for
 * @return the whitelist url
 */
public static String getWhitelistUrl(String url) {
    if (url.endsWith("/")) {
        return url + "*";
    } else {
        return url + "/*";
    }
}

From source file:Main.java

private static String fixPropValue(String value) {
    if (value.startsWith("\""))
        value = value.substring(1);/*from w  w  w. j  av a 2 s . c om*/
    if (value.endsWith("\""))
        value = value.substring(0, value.length() - 1);

    return value;
}

From source file:Main.java

private static String buildGetUrl(List<NameValuePair> params, String url) {
    String paramString = URLEncodedUtils.format(params, "utf-8");
    if (!url.endsWith("?"))
        url += "?";

    url += paramString;/*from w w w  .java 2  s .  co m*/
    return url;
}

From source file:Main.java

/**
 * Builds a file path that ensures the directory and filename are separated by a single separator. This is only suitable
 * for Unix and URL paths. File paths need special care for the differences between systems (/ on Unix and \ on Windows)
 * @param directory/*ww  w  .  j  a  v a  2s.com*/
 * @param fileName
 */
public static String appendUnixPaths(String directory, String fileName) {
    if (directory.endsWith("/")) {
        return directory + removeLeadingUnixSlash(fileName);
    } else {
        return directory + addLeadingUnixSlash(fileName);
    }
}

From source file:Main.java

public static String perfectEnd(String str, String attach) {
    if (str == null) {
        return attach;
    }//from   w  w w. ja v a 2  s  .c  om
    return str.endsWith(attach) ? str : (str + attach);
}

From source file:Main.java

public static String appendJPG(String url) {
    try {//from   w  w w.j a  v a 2 s.c  o m
        for (String m : IMAGE_END) {
            if (url.endsWith(m)) {
                return url;
            }
        }

        url = url + ".jpg";
        return url;
    } catch (Exception e) {
        return url;
    }

}

From source file:io.fabric8.maven.docker.config.ArchiveCompression.java

public static ArchiveCompression fromFileName(String filename) {
    if (filename.endsWith(".tar.gz") || filename.endsWith(".tgz")) {
        return ArchiveCompression.gzip;
    }//www.j  a va2s . co  m

    if (filename.endsWith(".tar.bz") || filename.endsWith(".tar.bzip2") || filename.endsWith(".tar.bz2")) {
        return ArchiveCompression.bzip2;
    }
    return ArchiveCompression.none;
}