List of usage examples for java.lang String compareToIgnoreCase
public int compareToIgnoreCase(String str)
From source file:cn.edu.wyu.documentviewer.model.DocumentInfo.java
public static int compareToIgnoreCaseNullable(String lhs, String rhs) { if (lhs == null) return -1; if (rhs == null) return 1; return lhs.compareToIgnoreCase(rhs); }
From source file:org.gradle.util.GUtil.java
public static Comparator<String> caseInsensitive() { return new Comparator<String>() { public int compare(String o1, String o2) { int diff = o1.compareToIgnoreCase(o2); if (diff != 0) { return diff; }/*from ww w. j ava 2 s .c om*/ return o1.compareTo(o2); } }; }
From source file:gov.llnl.lc.smt.command.about.SmtAbout.java
public static SmtAboutRecord getAboutRecord(ArrayList<SmtAboutRecord> records, String title) { // given one or more records, return the first one that matches the title provided for (SmtAboutRecord record : records) { String rTitle = record.getTitle(); if (title.compareToIgnoreCase(rTitle) == 0) return record; }//from ww w . j a va 2 s . c om return null; }
From source file:pl.edu.icm.cermine.evaluation.tools.EvaluationUtils.java
public static Comparator<String> cosineComparator(final double threshold) { return new Comparator<String>() { @Override/*from w w w . jav a 2 s .co m*/ public int compare(String t1, String t2) { if (new CosineDistance().compare(TextUtils.tokenize(t1), TextUtils.tokenize(t2)) > threshold) { return 0; } return t1.compareToIgnoreCase(t2); } }; }
From source file:org.soyatec.windowsazure.internal.MessageCanonicalizer2.java
/** * Create the canonicalized resource with the url address and resourceUriComponents. * @param address//from www . j a va 2 s .c o m * The uri address of the HTTP request. * @param uriComponents * Components of the Uri extracted out of the request. * @return canonicalized resource */ private static String getCanonicalizedResource(URI address, ResourceUriComponents uriComponents) { // Beginning with an empty string (""), append a forward slash (/), followed by the name of the account that owns the resource being accessed. // Append the resource's encoded URI path, without any query parameters. // Retrieve all query parameters on the resource URI, including the comp parameter if it exists. // Convert all parameter names to lowercase. // Sort the query parameters lexicographically by parameter name, in ascending order. // URL-decode each query parameter name and value. // Append each query parameter name and value to the string in the following format, making sure to include the colon (:) between the name and the value: // parameter-name:parameter-value // If a query parameter has more than one value, sort all values lexicographically, then include them in a comma-separated list: // parameter-name:parameter-value-1,parameter-value-2,parameter-value-n // Append a new line character (\n) after each name-value pair. // Get Container Metadata // GET http://myaccount.blob.core.windows.net/mycontainer?restype=container&comp=metadata // CanonicalizedResource: // /myaccount/mycontainer\ncomp:metadata\nrestype:container // // List Blobs operation: // GET http://myaccount.blob.core.windows.net/container?restype=container&comp=list&include=snapshots&include=metadata&include=uncommittedblobs // CanonicalizedResource: // /myaccount/mycontainer\ncomp:list\ninclude:metadata,snapshots,uncommittedblobs\nrestype:container StringBuilder canonicalizedResource = new StringBuilder(ConstChars.Slash); canonicalizedResource.append(uriComponents.getAccountName()); // Note that AbsolutePath starts with a '/'. String path = address.getRawPath(); // path = path.replaceAll(" ", "%20"); // path = java.net.URLEncoder.encode(path); canonicalizedResource.append(path); NameValueCollection query = HttpUtilities.parseQueryString(address.getQuery()); ArrayList<String> paramNames = new ArrayList<String>(); paramNames.addAll(query.keySet()); Collections.sort(paramNames, new Comparator<String>() { public int compare(String o1, String o2) { return o1.compareToIgnoreCase(o2); } }); for (String key : paramNames) { StringBuilder canonicalizedElement = new StringBuilder(URLDecoder.decode(key)); canonicalizedElement.append(ConstChars.Colon); String value = query.getMultipleValuesAsString(key); canonicalizedElement.append(URLDecoder.decode(value)); canonicalizedResource.append(ConstChars.Linefeed); canonicalizedResource.append(canonicalizedElement.toString()); } return canonicalizedResource.toString(); }
From source file:Main.java
/** * This method adds underscore in between the words (eg: converts GeneHomolog * to Gene_Homolog)//from w w w.java 2 s . c o m * * @param name */ public static void evaluateString(String name, List<String> options, List<String> words) { if (options == null || words == null) throw new IllegalArgumentException("Options or Words is not initialized"); //remove package name if the name is a class name if (name != null) { int index = name.lastIndexOf("."); name = name.substring(index + 1); } //Set optionSet = new HashSet(); options.add(name); char firstChar = name.charAt(0); firstChar = Character.toUpperCase(firstChar); if (name.indexOf("_") > 0) { String temp = Character.toString(firstChar) + name.substring(1); options.add(temp); } String temp = firstChar + name.substring(1).toLowerCase(); options.add(temp); String evaluatedString = null; ; StringBuffer wholeWords = new StringBuffer(); StringBuffer tempSeparateWord = new StringBuffer(); char[] chars = name.toCharArray(); StringBuffer sb = new StringBuffer(); boolean first = true; int index = 0; for (int i = 0; i < chars.length; i++) { //Character c = new Character(chars[i]); //System.out.println("inside loop i = " +i); if (Character.isUpperCase(chars[i])) { if ((i > 1) && ((i - index) > 1)) { //System.out.println("Inside capital if"); first = false; sb.append("_").append(chars[i]); words.add(tempSeparateWord.toString()); tempSeparateWord = new StringBuffer(); tempSeparateWord.append(chars[i]); wholeWords.append(" ").append(chars[i]); } else { wholeWords.append(chars[i]); tempSeparateWord.append(chars[i]); sb.append(chars[i]); } index = i; } else { if (chars[i] != '_') { sb.append(chars[i]); wholeWords.append(chars[i]); tempSeparateWord.append(chars[i]); } } } //System.out.println("Converted string: "+sb.toString()); //if the string contains "_", then make the first character uppercase if (!first) { char c = Character.toUpperCase(sb.charAt(0)); sb.deleteCharAt(0); sb.insert(0, c); char c1 = Character.toUpperCase(wholeWords.charAt(0)); wholeWords.deleteCharAt(0); wholeWords.insert(0, c1); } options.add(sb.toString()); options.add(wholeWords.toString()); if (words.size() > 0) { /* StringBuffer tmp = (StringBuffer)separateWords.get(0); char c2 = Character.toUpperCase(tmp.charAt(0)); tmp.deleteCharAt(0); tmp.insert(0, c2); separateWords.remove(0); separateWords.add(0, tmp); */ String temp2 = words.get(words.size() - 1).toString(); if (tempSeparateWord != null) { temp = tempSeparateWord.toString(); if (temp2.compareToIgnoreCase(temp) != 0) { words.add(temp); } } } List possibleOptions = new ArrayList(options); options = null;//garbage collection ready //testing for (int i = 0; i < possibleOptions.size(); i++) { System.out.println("options[" + i + "]=" + possibleOptions.get(i)); } for (int i = 0; i < words.size(); i++) { System.out.println("separateWords[" + i + "]=" + words.get(i)); } return; }
From source file:org.soyatec.windowsazure.internal.MessageCanonicalizer2.java
/** * Create a canonicalized string out of HTTP request header contents for * signing blob/queue requests with the Shared Authentication scheme. * //w w w . j av a2 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. * @param body * @return A canonicalized string of the HTTP request. */ public static String canonicalizeHttpRequest(URI address, ResourceUriComponents uriComponents, String method, String contentType, String date, NameValueCollection headers, HttpEntity body) { // StringToSign = VERB + "\n" + // Content-Encoding + "\n" // Content-Language + "\n" // Content-Length + "\n" // Content-MD5 + "\n" + // Content-Type + "\n" + // Date + "\n" + // If-Modified-Since + "\n" // If-Match + "\n" // If-None-Match + "\n" // If-Unmodified-Since + "\n" // Range + "\n" // CanonicalizedHeaders + // CanonicalizedResource; // The first element should be the Method of the request. // I.e. GET, POST, PUT, or HEAD. CanonicalizedString canonicalizedString = new CanonicalizedString(method); canonicalizedString.appendCanonicalizedElement(extractHeader(headers, HeaderNames.ContentEncoding)); canonicalizedString.appendCanonicalizedElement(extractHeader(headers, HeaderNames.ContentLanguage)); String length = extractHeader(headers, HeaderNames.ContentLength); if (length.equals("")) { length = "0"; if (body != null) { length = String.valueOf(body.getContentLength()); } } canonicalizedString.appendCanonicalizedElement(length); canonicalizedString.appendCanonicalizedElement(extractHeader(headers, HeaderNames.ContentMD5)); // 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); } canonicalizedString.appendCanonicalizedElement(extractHeader(headers, HeaderNames.IfModifiedSince)); canonicalizedString.appendCanonicalizedElement(extractHeader(headers, HeaderNames.IfMatch)); canonicalizedString.appendCanonicalizedElement(extractHeader(headers, HeaderNames.IfNoneMatch)); canonicalizedString.appendCanonicalizedElement(extractHeader(headers, HeaderNames.IfUnmodifiedSince)); canonicalizedString.appendCanonicalizedElement(extractHeader(headers, HeaderNames.Range)); // 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:org.opendatakit.utilities.LocalizationUtils.java
/** * Retrieve a translation from the localizationMap. The map might be for text, image, * audio, etc. entries./*www . jav a 2 s .com*/ * <p> * If localizationMap is a string, return it as-is, otherwise, it should be a * Map<String,Object> with locale as the key and value as the internationalized string. * <p> * full_locale is assumed to be of the form: language + "_" + country, with language not * containing an underscore. It first tries exact-case match of full_locale then tries for * case-insensitive matching of full_locale and then of just language. And if none of these * are present, returns the default translation or null if none is available. * * @param localizationMap a map of locale IDs to translations * @param full_locale the locale to get the translation for * @return null or the translation string. */ private static String processLocalizationMap(Object localizationMap, String full_locale) { if (localizationMap == null) { throw new IllegalStateException("null localizationMap"); } if (localizationMap instanceof String) { return (String) localizationMap; } Map<String, Object> aMap = (Map<String, Object>) localizationMap; int underscore = full_locale.indexOf('_'); String lang_only_locale = underscore <= 0 ? null : full_locale.substring(0, underscore); String langOnlyMatch = null; String defaultMatch = null; if (aMap.containsKey(full_locale)) { return (String) aMap.get(full_locale); } // otherwise, do a case-independent compare to find a match // and also consider language-only comparisons and, finally // retrieve the default translation. for (Map.Entry<String, Object> entry : aMap.entrySet()) { String key = entry.getKey(); if (key.compareToIgnoreCase(full_locale) == 0) { return (String) entry.getValue(); } if (lang_only_locale != null && key.compareToIgnoreCase(lang_only_locale) == 0) { langOnlyMatch = (String) entry.getValue(); } if (key.compareToIgnoreCase("default") == 0) { defaultMatch = (String) entry.getValue(); } } if (langOnlyMatch != null) { return langOnlyMatch; } return defaultMatch; }
From source file:ca.uqac.info.trace.execution.BabelTrace.java
/** * Get the proper instance of {@link TraceReader}, based on the * declared input format. Currently the following formats are supported: * <ul>/*from w w w .j av a 2 s. com*/ * <li>CSV</li> * <li>SQL</li> * <li>XML</li> * </ul> * @param type The type * @return The trace reader, null if format is unrecognized */ private static TraceReader getTraceReader(String type) { TraceReader tr = null; if (type.compareToIgnoreCase("xml") == 0) tr = new XmlTraceReader(); /*else if (type.compareToIgnoreCase("sql") == 0) tr = new SqlTraceReader();*/ else if (type.compareToIgnoreCase("csv") == 0) tr = new CsvTraceReader(); return tr; }
From source file:gov.nih.nci.evs.browser.utils.SimpleSearchUtils.java
public static boolean isSimpleSearchSupported(String algorithm, String target) { //if (!isSearchExtensionAvaliable) return false; if (algorithm == null || target == null) return false; if (algorithm.compareToIgnoreCase(EXACT_MATCH) == 0 && target.compareToIgnoreCase(CODES) == 0) { return true; } else if (algorithm.compareToIgnoreCase(EXACT_MATCH) == 0 && target.compareToIgnoreCase(NAMES) == 0) { return true; } else if (algorithm.compareToIgnoreCase(LUCENE) == 0 && target.compareToIgnoreCase(CODES) == 0) { return true; } else if (algorithm.compareToIgnoreCase(LUCENE) == 0 && target.compareToIgnoreCase(NAMES) == 0) { return true; } else if (algorithm.compareToIgnoreCase(CONTAINS) == 0 && target.compareToIgnoreCase(NAMES) == 0) { return true; }//from www.j a v a 2 s . c o m return false; }