Example usage for java.lang String compareToIgnoreCase

List of usage examples for java.lang String compareToIgnoreCase

Introduction

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

Prototype

public int compareToIgnoreCase(String str) 

Source Link

Document

Compares two strings lexicographically, ignoring case differences.

Usage

From source file:Main.java

/** Returns an alphabetically sorted copy of vector. */
public static void sortListAlphabetically(List list) {
    Collections.sort(list, new Comparator() {
        public int compare(Object a, Object b) {
            String textA = a.toString();
            String textB = b.toString();

            return textA.compareToIgnoreCase(textB);
        }//from w w  w.  ja  v  a 2 s  .c  om
    });
}

From source file:Main.java

/**
 * Given an un-encoded URI query string, this will return a normalized, properly encoded URI query string.
 * <b>Important:</b> This method uses java's URLEncoder, which returns things that are 
 * application/x-www-form-urlencoded, instead of things that are properly octet-esacped as the URI spec
 * requires.  As a result, some substitutions are made to properly translate space characters to meet the
 * URI spec.//from  w  w  w .jav  a 2s.  c  o m
 * @param queryString
 * @return
 */
private static String normalizeQueryString(String queryString) throws UnsupportedEncodingException {
    if ("".equals(queryString) || queryString == null)
        return queryString;

    String[] pieces = queryString.split("&");
    HashMap<String, String> kvp = new HashMap<String, String>();
    StringBuffer builder = new StringBuffer("");

    for (int x = 0; x < pieces.length; x++) {
        String[] bs = pieces[x].split("=", 2);
        bs[0] = URLEncoder.encode(bs[0], "UTF-8");
        if (bs.length == 1)
            kvp.put(bs[0], null);
        else {
            kvp.put(bs[0], URLEncoder.encode(bs[1], "UTF-8").replaceAll("\\+", "%20"));
        }
    }

    // Sort the keys alphabetically, ignoring case.
    ArrayList<String> keys = new ArrayList<String>(kvp.keySet());
    Collections.sort(keys, new Comparator<String>() {
        public int compare(String o1, String o2) {
            return o1.compareToIgnoreCase(o2);
        }
    });

    // With the alphabetic list of parameter names, re-build the query string.
    for (int x = 0; x < keys.size(); x++) {
        // Some parameters have no value, and are simply present.  If so, we put null in kvp,
        // and we just put the parameter name, no "=value".
        if (kvp.get(keys.get(x)) == null)
            builder.append(keys.get(x));
        else
            builder.append(keys.get(x) + "=" + kvp.get(keys.get(x)));

        if (x < (keys.size() - 1))
            builder.append("&");
    }

    return builder.toString();
}

From source file:Main.java

/** Returns an alphabetically sorted list of the keys. */
public static Vector getSortedKeyList(Hashtable hashtable) {
    Vector result = new Vector();
    Enumeration keys = hashtable.keys();
    while (keys.hasMoreElements()) {
        result.add(keys.nextElement());//from  ww w.  j  a  va  2s .  c o  m
    }
    Collections.sort(result, new Comparator() {
        public int compare(Object a, Object b) {
            String textA = a.toString();
            String textB = b.toString();

            return textA.compareToIgnoreCase(textB);
        }
    });

    return result;
}

From source file:Main.java

/**
 * This method checks if the list contains the given string (ignoring case).
 * /*from  ww  w. j av  a  2  s . c o m*/
 * @param list
 *          the list to check
 * @param string
 *          the string
 * @return true/false
 */
public static boolean containsIgnoreCase(List<String> list, String string) {
    if (isNotEmpty(list)) {
        for (String item : list) {
            if ((item != null && string != null && item.compareToIgnoreCase(string) == 0)
                    || (item == null && string == null)) {
                return true;
            }
        }
    }
    return false;
}

From source file:com.vmware.identity.interop.ldap.DirectoryStoreProtocol.java

public static boolean isProtocolSupported(String scheme) {
    for (DirectoryStoreProtocol v : DirectoryStoreProtocol.values()) {
        if (scheme.compareToIgnoreCase(v.getName()) == 0) {
            return true;
        }/*www .jav  a 2 s . co m*/
    }
    return false;
}

From source file:Main.java

/**
 * Gets the boolean value of a named attribute of a node.
 * @param node Node//from   w  w  w . ja  va2s  . c om
 * @param name String
 * @return boolean
 */
public static boolean getAttributeBoolean(Node node, String name) {
    String s = getAttributeString(node, name);
    if (s != null && s.length() > 0) {
        return (s.compareToIgnoreCase("1") == 0);
    } else
        return false;
}

From source file:org.apache.hadoop.util.TestNativeCodeLoader.java

private static boolean requireTestJni() {
    String rtj = System.getProperty("require.test.libhadoop");
    if (rtj == null)
        return false;
    if (rtj.compareToIgnoreCase("false") == 0)
        return false;
    return true;//from   w  w w . j a v a2  s. c  o m
}

From source file:org.apache.hadoop.fs.TestHdfsNativeCodeLoader.java

private static boolean requireTestJni() {
    String rtj = System.getProperty("require.test.libhadoop");
    if (rtj == null) {
        return false;
    }//w w  w. j av a  2  s .c om
    if (rtj.compareToIgnoreCase("false") == 0) {
        return false;
    }
    return true;
}

From source file:ca.uqac.info.trace.TraceGenerator.java

public static MessageFeeder instantiateFeeder(String name, String params) {
    MessageFeeder mf = null;/*from www .j  a  v  a  2  s  .co m*/
    if (name.compareToIgnoreCase("constant") == 0)
        mf = new ConstantFeeder();
    else if (name.compareToIgnoreCase("longchain") == 0)
        mf = new LongChainFeeder(params);
    else if (name.compareToIgnoreCase("pingulevel") == 0)
        mf = new PinguLevel(params);
    else if (name.compareToIgnoreCase("filefeeder") == 0)
        mf = new FileFeeder(params);
    else if (name.compareToIgnoreCase("simplerandom") == 0)
        mf = new SimpleRandomFeeder();
    return mf;
}

From source file:Main.java

/**
 * Null-safe version of string comparison.
 * //from   w  w w  .  j  av a2  s  . c o m
 * @param s1 the first string
 * @param s2 the second string
 * @return the comparison result
 */
public static int stringCompareIgnoreCase(String s1, String s2) {
    if (s1 == null)
        return (s2 == null ? 0 : -1);
    else if (s2 == null)
        return 1;
    else
        return s1.compareToIgnoreCase(s2);
}