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:sh.isaac.api.util.StringUtils.java

/**
 * Null-safe string compare./*from  ww w .j a v  a 2 s .  co m*/
 *
 * @param s1 the s 1
 * @param s2 the s 2
 * @return the int
 */
public static int compareStringsIgnoreCase(String s1, String s2) {
    int rval = 0;

    if ((s1 != null) || (s2 != null)) {
        if (s1 == null) {
            rval = -1;
        } else if (s2 == null) {
            rval = 1;
        } else {
            return s1.compareToIgnoreCase(s2);
        }
    }

    return rval;
}

From source file:org.b3log.symphony.service.ManQueryService.java

/**
 * Initializes manuals.//from   w ww .  j  av a 2 s  . com
 */
private static void init() {
    // http://stackoverflow.com/questions/585534/what-is-the-best-way-to-find-the-users-home-directory-in-java
    final String userHome = System.getProperty("user.home");
    if (StringUtils.isBlank(userHome)) {
        return;
    }

    try {
        Thread.sleep(5 * 1000);

        final String tldrPagesPath = userHome + File.separator + "tldr" + File.separator + "pages"
                + File.separator;
        final Collection<File> mans = FileUtils.listFiles(new File(tldrPagesPath), new String[] { "md" }, true);
        for (final File manFile : mans) {
            InputStream is = null;
            try {
                is = new FileInputStream(manFile);
                final String md = IOUtils.toString(is, "UTF-8");
                String html = Markdowns.toHTML(md);

                final JSONObject cmdMan = new JSONObject();
                cmdMan.put(Common.MAN_CMD, StringUtils.substringBeforeLast(manFile.getName(), "."));

                html = html.replace("\n", "").replace("\r", "");
                cmdMan.put(Common.MAN_HTML, html);

                CMD_MANS.add(cmdMan);
            } catch (final Exception e) {
                LOGGER.log(Level.ERROR, "Loads man [" + manFile.getPath() + "] failed", e);
            } finally {
                IOUtils.closeQuietly(is);
            }
        }
    } catch (final Exception e) {
        return;
    }

    TLDR_ENABLED = !CMD_MANS.isEmpty();

    Collections.sort(CMD_MANS, (o1, o2) -> {
        final String c1 = o1.optString(Common.MAN_CMD);
        final String c2 = o2.optString(Common.MAN_CMD);

        return c1.compareToIgnoreCase(c2);
    });
}

From source file:org.soyatec.windowsazure.internal.MessageCanonicalizer.java

/**
 * Create a canonicalized string out of HTTP request header contents for
 * signing blob/queue requests with the Shared Authentication scheme.
 * //from   ww  w .j  a  v a 2 s.c  o  m
 * @param address
 *            The uri address of the HTTP request.
 * @param uriComponents
 *            Components of the Uri extracted out of the request.
 * @param method
 *            The method of the HTTP request (GET/PUT, etc.).
 * @param contentType
 *            The content type of the HTTP request.
 * @param date
 *            The date of the HTTP request.
 * @param headers
 *            Should contain other headers of the HTTP request.
 * @return A canonicalized string of the HTTP request.
 */
public static String canonicalizeHttpRequest(URI address, ResourceUriComponents uriComponents, String method,
        String contentType, String date, NameValueCollection headers) {
    // The first element should be the Method of the request.
    // I.e. GET, POST, PUT, or HEAD.
    CanonicalizedString canonicalizedString = new CanonicalizedString(method);

    // The second element should be the MD5 value.
    // This is optional and may be empty.
    String httpContentMD5Value = Utilities.emptyString();

    // First extract all the content MD5 values from the header.
    List<String> httpContentMD5Values = HttpRequestAccessor.getHeaderValues(headers, HeaderNames.ContentMD5);

    // If we only have one, then set it to the value we want to append to
    // the canonicalized string.
    if (httpContentMD5Values != null && httpContentMD5Values.size() == 1) {
        httpContentMD5Value = (String) httpContentMD5Values.get(0);
    }
    canonicalizedString.appendCanonicalizedElement(httpContentMD5Value);

    // The third element should be the content type.
    canonicalizedString.appendCanonicalizedElement(contentType);

    // The fourth element should be the request date.
    // See if there's an storage date header.
    // If there's one, then don't use the date header.
    List<String> httpStorageDateValues = HttpRequestAccessor.getHeaderValues(headers,
            HeaderNames.StorageDateTime);
    if (httpStorageDateValues != null && httpStorageDateValues.size() > 0) {
        date = "";
    }
    if (date != null) {
        canonicalizedString.appendCanonicalizedElement(date);
    }

    // Look for header names that start with
    // StorageHttpConstants.HeaderNames.PrefixForStorageHeader
    // Then sort them in case-insensitive manner.
    ArrayList<String> httpStorageHeaderNameArray = new ArrayList<String>();
    for (Object keyObj : headers.keySet()) {
        String key = (String) keyObj;
        if (key.toLowerCase().startsWith(HeaderNames.PrefixForStorageHeader)) {
            httpStorageHeaderNameArray.add(key.toLowerCase());
        }
    }

    Collections.sort(httpStorageHeaderNameArray, new Comparator<String>() {
        public int compare(String o1, String o2) {
            return o1.compareToIgnoreCase(o2);
        }
    });

    for (String key : httpStorageHeaderNameArray) {
        StringBuilder canonicalizedElement = new StringBuilder(key);
        String delimiter = ConstChars.Colon;
        List<String> values = HttpRequestAccessor.getHeaderValues(headers, key);
        for (String headerValue : values) {
            // Unfolding is simply removal of CRLF.
            String unfoldedValue = headerValue.replaceAll(ConstChars.CarriageReturnLinefeed,
                    Utilities.emptyString());
            // Append it to the canonicalized element string.
            canonicalizedElement.append(delimiter);
            canonicalizedElement.append(unfoldedValue);
            delimiter = ConstChars.Comma;
        }
        // Now, add this canonicalized element to the canonicalized header
        // string.
        canonicalizedString.appendCanonicalizedElement(canonicalizedElement.toString());
    }

    // Now we append the canonicalized resource element.
    String canonicalizedResource = getCanonicalizedResource(address, uriComponents);
    canonicalizedString.appendCanonicalizedElement(canonicalizedResource);

    return canonicalizedString.getValue();
}

From source file:com.highcharts.export.controller.ExportController.java

private static String sanitize(String parameter) {
    if (parameter != null && !parameter.trim().isEmpty()
            && !(parameter.compareToIgnoreCase("undefined") == 0)) {
        return parameter.trim();
    }//  ww  w  .j  a v a  2s. c om
    return null;
}

From source file:jp.or.openid.eiwg.scim.util.SCIMUtil.java

/**
 * BASE64/*from w ww.j av  a  2s . co  m*/
 *
 * @param val ?
 * @return ?
 * @throws UnsupportedEncodingException
 * @throws Exception
 */
public static String decodeBase64(String val) throws IOException {
    // BASE64?
    val = val.replaceAll("[\n|\r]", "");
    String decodeString = new String(Base64.decodeBase64(val), "UTF-8");

    // ???????
    String encodeString = encodeBase64(decodeString);
    if (encodeString.compareToIgnoreCase(val) != 0) {
        decodeString = "";
    }

    // BASE64??
    return decodeString;
}

From source file:Highcharts.ExportController.java

private static String sanitize(String parameter) {
        if (parameter != null && !parameter.trim().isEmpty()
                && !(parameter.compareToIgnoreCase("undefined") == 0)) {
            return parameter.trim();
        }/*  w ww.  j  ava 2 s. com*/
        return null;
    }

From source file:com.microsoft.rightsmanagement.sampleapp.App.java

/**
 * Checks if file is a ptxt file.//from w w w.  j av  a 2  s  . co  m
 * 
 * @param fileName the file name
 * @return true, if is ptxt file
 */
public static boolean isPTxtFile(String fileName) {
    if (fileName == null || fileName.lastIndexOf('.') < 0) {
        // TODO throw invalid argument exception
    }
    String extension = fileName.substring(fileName.lastIndexOf('.'), fileName.length());
    boolean isProtected = false;
    if (extension.compareToIgnoreCase(PROTECTED_FILE_SUFFIX) == 0) {
        isProtected = true;
    }
    return isProtected;
}

From source file:com.microsoft.rightsmanagement.sampleapp.App.java

/**
 * Checks if file is a txt2 file.// w  ww.  ja v a  2s  . co  m
 * 
 * @param fileName the file name
 * @return true, if is txt2 file
 */
public static boolean isTxt2File(String fileName) {
    if (fileName == null || fileName.lastIndexOf('.') < 0) {
        // TODO throw invalid argument exception
    }
    String extension = fileName.substring(fileName.lastIndexOf('.'), fileName.length());
    boolean isProtected = false;
    if (extension.compareToIgnoreCase(MYOWNFORMAT_PROTECTED_FILE_SUFFIX) == 0) {
        isProtected = true;
    }
    return isProtected;
}

From source file:alter.vitro.vgw.service.query.wrappers.ResponseAggrMsg.java

/**
 *     valid deploy status FOR GATEWAY LEVEL operations
 *//*  w w  w .j  a v a  2s  . co  m*/
public static boolean isValidDeplyStatus(String pStatus) {
    int i;
    for (i = 0; i < VALID_DEPLOY_STATUSES.length; i++) //
    {
        if (pStatus.compareToIgnoreCase(VALID_DEPLOY_STATUSES[i]) == 0) {
            return true;
        }
    }
    logger.error("An invalid deploy status was specified!!!");
    return false;
}

From source file:org.dawnsci.fileviewer.Utils.java

public static int compareFiles(File a, File b, SortType sortType, int direction) {
    // boolean aIsDir = a.isDirectory();
    // boolean bIsDir = b.isDirectory();
    // if (aIsDir && ! bIsDir) return -1;
    // if (bIsDir && ! aIsDir) return 1;

    // sort case-sensitive files in a case-insensitive manner
    int compare = 0;
    switch (sortType) {
    case NAME:/*w w  w. j  a v a2s . co  m*/
        compare = a.getName().compareToIgnoreCase(b.getName());
        if (compare == 0)
            compare = a.getName().compareTo(b.getName());
        break;
    case SIZE:
        long sizea = a.length(), sizeb = b.length();
        compare = sizea < sizeb ? -1 : 1;
        break;
    case TYPE:
        String typea = getFileTypeString(a), typeb = getFileTypeString(b);
        compare = typea.compareToIgnoreCase(typeb);
        if (compare == 0)
            compare = typea.compareTo(typeb);
        break;
    case DATE:
        Date date1 = new Date(a.lastModified());
        Date date2 = new Date(b.lastModified());
        compare = date1.compareTo(date2);
        break;
    default:
        return 0;
    }
    if (FileTableViewerComparator.DESC == direction)
        return (-1 * compare);
    return compare;
}