Example usage for java.lang String startsWith

List of usage examples for java.lang String startsWith

Introduction

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

Prototype

public boolean startsWith(String prefix) 

Source Link

Document

Tests if this string starts with the specified prefix.

Usage

From source file:Main.java

public static void doItNow(@NonNull Context context, @NonNull String resource) {
    //If a link//ww w.j  a v a 2  s.  c o  m
    if (resource.startsWith("http")) {
        //If an app
        if (resource.startsWith("http://play.google.com/store/apps/")
                || resource.startsWith("https://play.google.com/store/apps/")) {
            String id = resource.substring(resource.indexOf('/', 32));
            //Try, if the user does not have the store installed, launch as web link
            try {
                context.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://" + id)));
            } catch (ActivityNotFoundException anfx) {
                context.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(resource)));
            }
        }
        //Otherwise opened with the browser
        else {
            Uri uri = Uri.parse(resource);
            context.startActivity(new Intent(Intent.ACTION_VIEW, uri));
        }
    }
}

From source file:Main.java

private static Set<File> getExpectationFiles(String dir) {
    Set<File> expectSet = new HashSet<File>();
    File[] files = new File(dir).listFiles(new FilenameFilter() {
        // ignore obviously temporary files
        public boolean accept(File dir, String name) {
            return !name.endsWith("~") && !name.startsWith(".");
        }//from  ww  w  .j a v  a2s  .c om
    });
    if (files != null) {
        expectSet.addAll(Arrays.asList(files));
    }
    return expectSet;
}

From source file:Main.java

/**
 * Searches for and returns the first string which starts with the given
 * prefix. Removes the match from the collection.
 *
 * @param collection the collection./*w  w  w . ja  v a 2  s  .c o  m*/
 * @param prefix     the string prefix.
 * @return a string, or null if no matches.
 */
public static String popStartsWith(Collection<String> collection, String prefix) {
    Iterator<String> iterator = collection.iterator();

    while (iterator.hasNext()) {
        String element = iterator.next();

        if (element != null && element.startsWith(prefix)) {
            iterator.remove();
            return element;
        }
    }

    return null;
}

From source file:Main.java

/** return the res id of android ( current only the calling package )*/
public static int getResId(String str, Context context) {
    String packageName;/*from   w  ww. j  a  v  a2s  .  co m*/
    if (str.startsWith("android.R.")) {
        packageName = "android";
        //android.R.anim.xxx -> R.anim.xxx
        str = str.substring(str.indexOf(".") + 1);
    } else {
        packageName = context.getApplicationInfo().packageName;
    }
    //final String packageName = context.getApplicationInfo().packageName;
    final String[] strs = str.split("\\.");
    try { //R.drawable.xxx_xx
        return Class.forName(packageName + ".R$" + strs[1]).getField(strs[2]).getInt(null);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:Main.java

public static boolean isAndroidClass(String clsName) {
    for (String prefix : androidClassPrefixes) {
        if (clsName.startsWith(prefix)) {
            return true;
        }//from ww  w .j a  v a  2s  . c  o m
    }

    return false;
}

From source file:Main.java

public static boolean validateURL(String url) {
    try {//  ww w .j  av  a  2s.  c  om
        new URL(url);
        if (url.startsWith("http") || url.startsWith("ftp://"))
            return true;
        return false;
    } catch (Exception e) {
        return false;
    }
}

From source file:Main.java

protected static boolean isCompanyThreadName(String threadName) {
    for (String company : COMPANY_PREFIX_LIST) {
        if (threadName.startsWith(company)) {
            return true;
        }/*from   w  w  w.  j  a v a2s.c  o  m*/
    }
    return false;
}

From source file:Main.java

public static boolean isAndroidClass(String clsName) {

    for (String prefix : androidClassPrefixes) {
        if (clsName.startsWith(prefix)) {
            System.out.println(clsName);
            return true;
        }/*from  w  ww.  j  a  v a2 s . c  o m*/
    }
    return false;
}

From source file:Main.java

public static String trimQuotes(String s) {
    if (null != s && s.length() > 1) {
        if (s.startsWith("\"\\\"") && s.endsWith("\\\"\"")) {
            Log.d("MagnetUtils", "String " + s + " starting with \\\"");
            s = s.substring(3, s.length() - 3);
        } else if (s.startsWith("\"") && s.endsWith("\"")) {
            s = s.substring(1, s.length() - 1);
        }/*w w w  .  jav a  2 s  . c  om*/
    }

    return s;
}

From source file:de.tntinteractive.portalsammler.engine.MapReader.java

private static String lineToValue(final String line) {
    if (!line.startsWith(" ")) {
        throw new ShouldNotHappenException("invalid line: " + line);
    }/*from   w ww. jav  a2s .c o m*/
    return line.substring(1);
}