Example usage for java.lang String contains

List of usage examples for java.lang String contains

Introduction

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

Prototype

public boolean contains(CharSequence s) 

Source Link

Document

Returns true if and only if this string contains the specified sequence of char values.

Usage

From source file:com.pushinginertia.commons.net.util.HttpServletRequestUtils.java

private static IpAddress getRemoteIpAddressFromXForwardedFor(final String xForwardedFor) {
    if (xForwardedFor.contains(",")) {
        // sometimes the header is of form: client ip,proxy 1 ip,proxy 2 ip,...,proxy n ip
        // we just want the client
        final String first = xForwardedFor.split(",")[0].trim();
        return new IpAddress(first);
    }//from w  ww .j av  a2  s .  com

    return new IpAddress(xForwardedFor);
}

From source file:com.amazonaws.codepipeline.jenkinsplugin.TestUtils.java

public static void assertContainsIgnoreCase(final String strToMatch, final String strToCheck) {
    final String strToMatchLower = strToMatch.toLowerCase();
    final String strToCheckLower = strToCheck.toLowerCase();
    assertTrue(strToCheckLower.contains(strToMatchLower));
}

From source file:Main.java

public static boolean isPlaylistUrl(String url) {
    if (url == null) {
        return false;
    }/*from ww  w  .  ja v a  2  s  .  c  o m*/

    try {
        URL _url = new URL(url);
        String host = _url.getHost();
        if (host == null) {
            return false;
        }
        if (!host.contains("nicovideo.jp")) {
            return false;
        }
        String path = _url.getPath();
        if (path == null) {
            return false;
        }
        return path.startsWith("/search") || path.startsWith("/mylist");
    } catch (MalformedURLException e) {
    }

    return false;
}

From source file:de.doncarnage.minecraft.baseplugin.util.ItemUtil.java

/**
 * Returns a MaterialData object of the given item string.
 *
 * @param item the item name as string/*from  www.  j  a v a2 s  . com*/
 * @return a {@link MaterialData} instance
 */
public static MaterialData getMaterialDataByString(String item) {
    Preconditions.checkNotNull(item);
    if (!item.contains(ITEM_SPLITTER)) {
        return getMaterialDataByString(item, null);
    }
    String[] block = item.split(ITEM_SPLITTER);
    if (block.length > 2) {
        return null;
    } else if (block.length == 2) {
        return ItemUtil.getMaterialDataByString(block[0], block[1]);
    } else if (block.length == 1) {
        return ItemUtil.getMaterialDataByString(block[0]);
    }
    return null;
}

From source file:io.stallion.users.OAuthClientController.java

public static long fullIdToLongId(String fullClientId) {
    String idPart = "";
    if (!fullClientId.contains("-")) {
        idPart = fullClientId;/*from  ww w. j av a 2s .co m*/
    } else {
        idPart = StringUtils.split(fullClientId, "-", 2)[0];
    }
    if (!StringUtils.isNumeric(idPart)) {
        return 0;
    }
    return Long.parseLong(idPart);
}

From source file:Main.java

public static void openMailChooser(Context context, String text, String[] mails, String subject) {
    Intent mailIntent = new Intent();
    mailIntent.setAction(Intent.ACTION_SEND);
    mailIntent.putExtra(Intent.EXTRA_TEXT, text);
    mailIntent.putExtra(Intent.EXTRA_EMAIL, mails);
    mailIntent.putExtra(Intent.EXTRA_SUBJECT, subject);
    mailIntent.setType(INTENT_TYPE_MSG);

    PackageManager pm = context.getPackageManager();
    Intent sendIntent = new Intent(Intent.ACTION_SEND);
    sendIntent.setType(INTENT_TYPE_TEXT);

    Intent openInChooser = Intent.createChooser(mailIntent, "");

    List<ResolveInfo> resInfo = pm.queryIntentActivities(sendIntent, 0);
    List<LabeledIntent> intentList = new ArrayList<LabeledIntent>();
    for (ResolveInfo ri : resInfo) {
        String packageName = ri.activityInfo.packageName;
        if (packageName.contains(PACKAGE_EMAIL)) {
            mailIntent.setPackage(packageName);
        } else if (packageName.contains(PACKAGE_MMS) || packageName.contains(PACKAGE_GMAIL)) {
            Intent intent = new Intent();
            intent.setComponent(new ComponentName(packageName, ri.activityInfo.name));
            intent.setAction(Intent.ACTION_SEND);
            intent.setType(INTENT_TYPE_TEXT);
            if (packageName.contains(PACKAGE_MMS)) {
                intent.putExtra("subject", subject);
                intent.putExtra("sms_body", text);
                intent.putExtra("address", mails[0]);
                intent.setType(INTENT_TYPE_MSG);
            } else if (packageName.contains(PACKAGE_GMAIL)) {
                intent.putExtra(Intent.EXTRA_TEXT, text);
                intent.putExtra(Intent.EXTRA_SUBJECT, subject);
                intent.putExtra(Intent.EXTRA_EMAIL, mails);
                intent.setType(INTENT_TYPE_MSG);
            }/*  ww w.j a  v a 2  s . c  o m*/

            intentList.add(new LabeledIntent(intent, packageName, ri.loadLabel(pm), ri.icon));
        }
    }

    LabeledIntent[] extraIntents = intentList.toArray(new LabeledIntent[intentList.size()]);

    openInChooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, extraIntents);
    context.startActivity(openInChooser);
}

From source file:Main.java

static File getDefaultGameDir() {
    String os = System.getProperty("os.name").toLowerCase();
    String baseDir = null;//ww w . ja va 2s . c  o  m
    String subDir = ".minecraft";

    if (os.contains("win")) {
        baseDir = System.getenv("APPDATA");
    } else if (os.contains("mac")) {
        subDir = "Library/Application Support/minecraft";
    }

    if (baseDir == null) {
        baseDir = System.getProperty("user.home");
    }

    return new File(baseDir, subDir);
}

From source file:Main.java

public static String setPoint(String in) {
    char[] res;//from ww  w  .  j a  v a2s  .co m
    char[] cur = in.toCharArray();
    boolean isNeg = in.contains("-");
    int lengthNum;
    if (isNeg)
        lengthNum = in.length() - 1;
    else
        lengthNum = in.length();
    int length = in.length() - NUM_AFTER_COM;
    if (lengthNum > NUM_AFTER_COM) {
        res = new char[in.length() + 1];
        res[length] = '.';
        System.arraycopy(cur, 0, res, 0, length);
        System.arraycopy(cur, length, res, length + 1, NUM_AFTER_COM);
    } else {
        int size;
        if (isNeg) {
            length = in.length() - 1;
            size = NUM_AFTER_COM + 3;
            res = new char[size];
            res[0] = '-';
            res[1] = '0';
            res[2] = '.';
            System.arraycopy(cur, 1, res, size - length, length);
        } else {
            length = in.length();
            size = NUM_AFTER_COM + 2;
            res = new char[size];
            res[0] = '0';
            res[1] = '.';
            System.arraycopy(cur, 0, res, size - length, length);
        }
        for (int i = 0; i < res.length; i++) {
            if (res[i] == '\u0000')
                res[i] = '0';
        }
    }
    return new String(res);
}

From source file:Main.java

public static HashSet<String> stringToHashSet(String str) {
    HashSet<String> hs = new HashSet<String>();
    if (str.equals("") || str == null)
        return null;
    if (!str.contains(","))
        hs.add(str);/*from   w w w .  ja va2 s  .c  om*/
    else {
        String[] arr = str.split(",");
        for (String s : arr)
            hs.add(s);
    }
    return hs;

}

From source file:com.apress.progwt.server.web.controllers.ControllerUtil.java

/**
 * /*from  w w  w.  j  av a 2 s . co m*/
 * @param req
 * @param userService
 * @return
 */
public static Map<String, Object> getDefaultModel(HttpServletRequest req, UserService userService) {
    Map<String, Object> model = new HashMap<String, Object>();

    User su = null;
    model.put("message", req.getParameter("message"));
    try {
        su = userService.getCurrentUser();
        model.put("user", su);
    } catch (UsernameNotFoundException e) {
        // log.debug("No user logged in.");
    }

    if (req != null) {
        // IE < 7 check. used in common.ftl PNGImage
        String userAgent = req.getHeader("User-Agent");
        if (userAgent != null && userAgent.contains("MSIE") && !userAgent.contains("MSIE 7")) {
            model.put("iePre7", true);
        }
    }

    return model;
}