List of usage examples for java.lang String compareTo
public int compareTo(String anotherString)
From source file:com.pandoroid.pandora.PandoraRadio.java
public static int getRelativeAudioQualityMagnitude(String quality_string) { if (quality_string.compareTo(MP3_192) == 0) { return 4; }/*from www . j a v a2 s. co m*/ if (quality_string.compareTo(MP3_128) == 0) { return 3; } if (quality_string.compareTo(AAC_64) == 0) { return 2; } if (quality_string.compareTo(AAC_32) == 0) { return 1; } return -1; }
From source file:Main.java
/** * Compares two Well-known TNF records//from w w w. j av a 2 s . c o m * * @param pString1 The string corresponding to the first TNF record * @param pString2 The string corresponding to the second TNF record * @return true if the TNF records are equal */ /* package protected */static boolean compareWellKnownURI(String pString1, String pString2) { if (pString1 == null) { if (pString2 == null) { return true; } return false; } /* Before performing the comparison, the prefix urn:nfc:wkt: is removed from the type names, if present */ if (pString1.startsWith("urn:nfc:wkt:")) { pString1 = pString1.substring(12); } if (pString2.startsWith("urn:nfc:wkt:")) { pString2 = pString2.substring(12); } /* Then perform the comparison (case sensitive) */ return (pString1.compareTo(pString2) == 0) ? true : false; }
From source file:com.puppycrawl.tools.checkstyle.checks.imports.ImportOrderCheck.java
/** * Compares two strings./*w w w .ja v a 2 s . com*/ * * @param string1 * the first string. * @param string2 * the second string. * @param caseSensitive * whether the comparison is case sensitive. * @return the value {@code 0} if string1 is equal to string2; a value * less than {@code 0} if string1 is lexicographically less * than the string2; and a value greater than {@code 0} if * string1 is lexicographically greater than string2. */ private static int compare(String string1, String string2, boolean caseSensitive) { int result; if (caseSensitive) { result = string1.compareTo(string2); } else { result = string1.compareToIgnoreCase(string2); } return result; }
From source file:net.amigocraft.mpt.util.MiscUtil.java
/** * Compares two version strings.//from w w w . j a v a2 s. co m * @param version1 the first version to compare * @param version2 the second version to compare * @return -1 if the first is more recent, 1 if the second is more recent, or 0 if the versions are equal */ public static int compareVersions(String version1, String version2) { // separate main version from qualifier String vStr1 = version1.contains("-") ? version1.split("-")[0] : version1; String vStr2 = version2.contains("-") ? version2.split("-")[0] : version2; // compare major versions int major1; int major2; try { major1 = Integer.parseInt(vStr1.split("\\.")[0]); if (major1 < 0) throw new NumberFormatException(); } catch (NumberFormatException ex) { throw new IllegalArgumentException("Version string \"" + vStr1 + "\" contains invalid major version!"); } try { major2 = Integer.parseInt(vStr2.split("\\.")[0]); if (major2 < 0) throw new NumberFormatException(); } catch (NumberFormatException ex) { throw new IllegalArgumentException("Version string \"" + vStr2 + "\" contains invalid major version!"); } if (major2 > major1) return 1; else if (major2 < major1) return -1; // else major versions are equal // compare minor versions int minor1; int minor2; try { minor1 = vStr1.split("\\.").length > 1 ? Integer.parseInt(vStr1.split("\\.")[1]) : 0; if (minor1 < 0) throw new NumberFormatException(); } catch (NumberFormatException ex) { throw new IllegalArgumentException("Version string \"" + vStr1 + "\" contains invalid minor version!"); } try { minor2 = vStr2.split("\\.").length > 1 ? Integer.parseInt(vStr2.split("\\.")[1]) : 0; if (minor2 < 0) throw new NumberFormatException(); } catch (NumberFormatException ex) { throw new IllegalArgumentException("Version string \"" + vStr2 + "\" contains invalid minor version!"); } if (minor2 > minor1) return 1; else if (minor2 < minor1) return -1; // else minor versions are equal // compare incremental versions int inc1; int inc2; try { inc1 = vStr1.split("\\.").length > 2 ? Integer.parseInt(vStr1.split("\\.")[2]) : 0; if (inc1 < 0) throw new NumberFormatException(); } catch (NumberFormatException ex) { throw new IllegalArgumentException("Version string \"" + vStr1 + "\" contains invalid minor version!"); } try { inc2 = vStr2.split("\\.").length > 2 ? Integer.parseInt(vStr2.split("\\.")[2]) : 0; if (inc2 < 0) throw new NumberFormatException(); } catch (NumberFormatException ex) { throw new IllegalArgumentException("Version string \"" + vStr2 + "\" contains invalid minor version!"); } if (inc2 > inc1) return 1; else if (inc2 < inc1) return -1; // else incremental versions are equal String qual1 = version1.contains("-") ? version1.substring(version1.indexOf("-") + 1) : ""; String qual2 = version2.contains("-") ? version2.substring(version2.indexOf("-") + 1) : ""; int lex = qual1.compareTo(qual2); if (lex > 0) return -1; else if (lex < 0) return 1; else return 0; }
From source file:fr.paris.lutece.plugins.calendar.web.SmallMonthCalendar.java
/** * Calculate the style class to render the day * @param calendar A calendar object positionned on the day to render * @param bIsSelectedDay true if the date is the selected day, false * otherwise// w w w. ja va 2 s. c o m * @return A CSS style */ public static String getDayClass(Calendar calendar, boolean bIsSelectedDay) { String strClass = Constants.STYLE_CLASS_SMALLMONTH_DAY; String strDate = Utils.getDate(calendar); String strToday = Utils.getDateToday(); if (CalendarHome.hasOccurrenceEvent(calendar, PluginService.getPlugin(Constants.PLUGIN_NAME))) { strClass += Constants.STYLE_CLASS_SUFFIX_EVENT; } else if (Utils.isDayOff(calendar)) { strClass += Constants.STYLE_CLASS_SUFFIX_OFF; } else if (strDate.compareTo(strToday) < 0) { strClass += Constants.STYLE_CLASS_SUFFIX_OLD; } else if (strDate.equals(strToday)) { strClass += Constants.STYLE_CLASS_SUFFIX_TODAY; } if (bIsSelectedDay) { strClass += Constants.SPACE + Constants.STYLE_CLASS_SELECTED_DAY; } return strClass; }
From source file:gov.nih.nci.evs.browser.utils.ViewInHierarchyUtils.java
public static Vector<String> parseData(String line, String tab) { if (line == null) return null; Vector data_vec = new Vector(); StringTokenizer st = new StringTokenizer(line, tab); while (st.hasMoreTokens()) { String value = st.nextToken(); if (value.compareTo("null") == 0) value = " "; data_vec.add(value);// ww w. ja va2s. c om } return data_vec; }
From source file:gov.nih.nci.evs.browser.utils.CodeSearchUtils.java
public static CodedNodeSet restrictToSource(CodedNodeSet cns, String source) { if (cns == null) return cns; if (source == null || source.compareTo("*") == 0 || source.compareTo("") == 0 || source.compareTo("ALL") == 0) return cns; LocalNameList contextList = null;// w w w .ja v a2 s . c om LocalNameList sourceLnL = null; NameAndValueList qualifierList = null; Vector<String> w2 = new Vector<String>(); w2.add(source); sourceLnL = vector2LocalNameList(w2); LocalNameList propertyLnL = null; CodedNodeSet.PropertyType[] types = new PropertyType[] { PropertyType.PRESENTATION }; try { cns = cns.restrictToProperties(propertyLnL, types, sourceLnL, contextList, qualifierList); } catch (Exception ex) { _logger.error("restrictToSource throws exceptions."); return null; } return cns; }
From source file:gdt.data.grain.Support.java
/** * Remove the key and the associated value from the * hash table. /* ww w . j a va 2 s . co m*/ * @param keyName key string * @param tab hash table. */ public static void removeKey(String keyName, Hashtable<String, ?> tab) { if (keyName == null) return; if (tab == null) return; Enumeration<String> en = tab.keys(); String curKey = null; while (en.hasMoreElements()) { curKey = (String) en.nextElement(); if (keyName.compareTo(curKey) == 0) { tab.remove(curKey); break; } } }
From source file:Main.java
public static int stringCompareHonoringUnsigned(String inA, String inB) { int i, n, an, bn; int ai = 0, bi = 0; char al, bl;/*w ww . ja va 2 s . c o m*/ an = inA.length(); bn = inB.length(); n = (an < bn) ? an : bn; for (i = 0; i < n; ++i) { al = inA.charAt(i); bl = inB.charAt(i); if (al >= '0' && al <= '9' && bl >= '0' && bl <= '9') { ai = stringToUnsigned(inA, i); bi = stringToUnsigned(inB, i); break; } else if (al != bl) { break; } } return (ai > bi) ? 1 : (ai < bi) ? -1 : (i < n) ? inA.compareTo(inB) : (an > bn) ? 1 : (an < bn) ? -1 : 0; }
From source file:gdt.data.grain.Support.java
/** * Get value from the hash table by key string * @param keyName key string/*from w w w. j a va2 s.c om*/ * @param tab hash table. * @return found value or null. */ public static Object getValue(String keyName, Hashtable<String, ?> tab) { if (keyName == null) return null; if (tab == null) return null; Enumeration<String> en = tab.keys(); String curKey = null; while (en.hasMoreElements()) { curKey = (String) en.nextElement(); if (keyName.compareTo(curKey) == 0) return tab.get(curKey); } return null; }