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 String GetFilename(String uri) {
    if (uri.equalsIgnoreCase("/")) {
        return "/";
    }/*w ww .j  av a  2  s  .  c om*/
    if (uri.endsWith("/")) {
        uri = uri.substring(0, uri.length() - 1);
    }
    if (uri.indexOf('/') < 0) {
        return uri;
    }

    SimpleStringSplitter sss = new SimpleStringSplitter('/');
    sss.setString(uri);
    String tmp = "";
    String ret = "";
    while (sss.hasNext()) {
        tmp = sss.next();
        if (tmp.trim().length() > 0) {
            ret = tmp.trim();
        }
    }
    return ret;
}

From source file:Main.java

/**
 * Test if the given String ends with the specified suffix,
 * ignoring upper/lower case./*w  ww  . j a  v  a 2s  . c  om*/
 * @param str the String to check
 * @param suffix the suffix to look for
 * @see java.lang.String#endsWith
 */
public static boolean endsWithIgnoreCase(String str, String suffix) {
    if (str == null || suffix == null) {
        return false;
    }
    if (str.endsWith(suffix)) {
        return true;
    }
    if (str.length() < suffix.length()) {
        return false;
    }

    String lcStr = str.substring(str.length() - suffix.length()).toLowerCase();
    String lcSuffix = suffix.toLowerCase();
    return lcStr.equals(lcSuffix);
}

From source file:Main.java

public static boolean endWithMytext(String mytext, String end) {
    if (TextUtils.isEmpty(mytext) && TextUtils.isEmpty(end))
        return false;
    else {//from  www .j  a va 2s . c  om
        if (mytext.endsWith(end))
            return true;
        else
            return false;
    }
}

From source file:com.intuit.karate.JsonUtils.java

public static void setValueByPath(DocumentContext doc, String path, Object value) {
    if ("$".equals(path)) {
        throw new RuntimeException("cannot replace root path $");
    }//from   w  w w .j  a  v  a 2 s. c om
    Pair<String, String> pathLeaf = getParentAndLeafPath(path);
    String left = pathLeaf.getLeft();
    String right = pathLeaf.getRight();
    if (right.endsWith("]")) { // json array
        int indexPos = right.lastIndexOf('[');
        int index = Integer.valueOf(right.substring(indexPos + 1, right.length() - 1));
        right = right.substring(0, indexPos);
        List list;
        String listPath = left + "." + right;
        try {
            list = doc.read(listPath);
            if (index < list.size()) {
                list.set(index, value);
            } else {
                list.add(value);
            }
        } catch (Exception e) {
            logger.trace("will create non-existent path: {}", listPath);
            list = new ArrayList();
            list.add(value);
            doc.put(left, right, list);
        }
    } else {
        doc.put(left, right, value);
    }
    logger.trace("after set: {}", doc.jsonString());
}

From source file:com.clican.pluto.common.util.TimeUtils.java

/**
 * ???//from   www .j  a  v  a  2s . c o m
 * 
 * @param expr
 * @return
 */
public static long getMillisionSecond(String expr) {
    if (StringUtils.isEmpty(expr)) {
        return -1;
    }
    if (expr.endsWith("ms")) {
        return Long.parseLong(expr.replaceAll(expr, "ms"));
    } else if (expr.endsWith("sec")) {
        expr = expr.replaceAll("sec", "");
        return Long.parseLong(expr) * 1000;
    } else if (expr.endsWith("min")) {
        expr = expr.replaceAll("min", "");
        return Long.parseLong(expr) * 1000 * 60;
    } else if (expr.endsWith("hour")) {
        expr = expr.replaceAll("hour", "");
        return Long.parseLong(expr) * 1000 * 60 * 60;
    } else if (expr.endsWith("day")) {
        expr = expr.replaceAll("day", "");
        return Long.parseLong(expr) * 1000 * 60 * 60 * 24;
    } else if (expr.endsWith("week")) {
        expr = expr.replaceAll("week", "");
        return Long.parseLong(expr) * 1000 * 60 * 60 * 24 * 7;
    } else if (expr.endsWith("month")) {
        expr = expr.replaceAll("month", "");
        return Long.parseLong(expr) * 1000 * 60 * 60 * 24 * 30;
    } else {
        throw new IllegalArgumentException("illegal expression arg");
    }
}

From source file:com.igormaznitsa.mindmap.model.ExtraFile.java

@Nonnull
private static String ensureFolderPath(@Nonnull final String str) {
    if (str.endsWith("/") || str.endsWith("\\"))
        return str;
    return str + File.separatorChar;
}

From source file:fr.asso.vieillescharrues.parseurs.TelechargeFichier.java

/**
 * Mthode statique grant le tlechargement de fichiers
 * @param url Adresse du fichier/*w ww.j a  va 2s.c  o  m*/
 * @param fichierDest Nom du ficher en local
 */
public static void DownloadFromUrl(URL url, String fichierDest) throws IOException {
    File file;
    if (fichierDest.endsWith(".jpg"))
        file = new File(PATH + "images/", fichierDest);
    else
        file = new File(PATH, fichierDest);
    file.getParentFile().mkdirs();
    URLConnection ucon = url.openConnection();

    try {
        tailleDistant = ucon.getHeaderFieldInt("Content-Length", 0); //Rcupre le header HTTP Content-Length
        tailleLocal = (int) file.length();
    } catch (Exception e) {
        e.printStackTrace();
    }
    // Compare les tailles des fichiers
    if ((tailleDistant == tailleLocal) && (tailleLocal != 0))
        return;

    InputStream is = ucon.getInputStream();
    BufferedInputStream bis = new BufferedInputStream(is);
    ByteArrayBuffer baf = new ByteArrayBuffer(50);
    int current = 0;
    while ((current = bis.read()) != -1) {
        baf.append((byte) current);
    }
    FileOutputStream fos = new FileOutputStream(file);
    fos.write(baf.toByteArray());
    fos.close();
}

From source file:com.nuevebit.miroculus.mrna.core.MiRNA.java

/**
 * Sometimes the name contains an asterisk at the end, before setting the
 * name for this miRNA we should remove it.
 *
 * @param name//from  ww w.j  a  va  2s .  c o  m
 * @return the name without an asterisk at the end.
 */
public static String normalizeName(String name) {
    if (name.endsWith("*")) {
        name = name.substring(0, name.length() - 1);
    }

    return name.trim();
}

From source file:de.ks.option.properties.PropertiesOptionSource.java

protected static String getPropertiesFile() {
    String workingDir = System.getProperty("user.dir");
    if (workingDir.endsWith("bin")) {
        File parentFile = new File(workingDir).getParentFile();
        return parentFile.getPath() + File.separator + "options." + PROPERTIES_FILENAME;
    } else {//from   w ww  .  jav a2 s. c om
        return workingDir + File.separator + "options." + PROPERTIES_FILENAME;
    }
}

From source file:de.micromata.genome.gwiki.page.impl.wiki.MacroAttributesUtils.java

protected static String trim(String text) {
    if (text.length() < 3) {
        return text;
    }/*from  w  ww.  j  a  v a2s. com*/
    String ttext = StringUtils.trim(text);
    if (ttext.length() > 0 && ttext.endsWith("\\")) {
        return text;
    }

    return ttext;
}