/** * Returns <code>true</code> if the host part of this URL and the given URL are equal. * The comparison is case-insensitive. * * @param url the URL to test for host equality * @return <code>true</code> if the host part of this URL and the given URL are equal */ public boolean hostEquals(FileURL url) { // Note: StringUtils#equals is null-safe return StringUtils.equals(this.host, url.host, false); }
public boolean accept(String value) { if(isCaseSensitive()) return value.endsWith(s); return StringUtils.endsWithIgnoreCase(value, s); } }
public boolean accept(String value) { int len = value.length(); // If case isn't important, a simple String.endsWith is enough. if (isCaseSensitive()) { for (int i = 0; i < extensions.length; i++) if(StringUtils.matches(value, extensions[i], len)) return true; } // If case is important, we have to be a bit more creative and // use String.regionMatches. else { // Matches the value to each extension. for (int i = 0; i < extensions.length; i++) if(StringUtils.matchesIgnoreCase(value, extensions[i], len)) return true; } return false; } }
/** * Returns <code>true</code> if <code>a</code> ends with <code>b</code> regardless of the case. * <p> * This method has a known bug under some alphabets with peculiar capitalisation rules such as the Georgian one, * where <code>Character.toUpperCase(a) == Character.toUpperCase(b)</code> doesn't necessarily imply that * <code>Character.toLowerCase(a) == Character.toLowerCase(b)</code>. The performance hit of testing for this * exceptions is so huge that it was deemed an acceptable issue. * </p> * <p> * Note that this method will return <code>true</code> if <code>b</code> is an emptry string. * </p> * @param a string to test. * @param b suffix to test for. * @return <code>true</code> if <code>a</code> ends with <code>b</code> regardless of the case, <code>false</code> otherwise. */ public static boolean endsWithIgnoreCase(String a, char[] b) {return matchesIgnoreCase(a, b, a.length());}
/** * Equivalent of <code>String.endsWith(String)</code> using a <code>char[]</code>. * @param a String to test. * @param b suffix to test. * @return <code>true</code> if <code>a</code> ends with <code>b</code>. */ public static boolean endsWith(String a, char[] b) { return matches(a, b, a.length()); }
/** * Shorthand for {@link #flatten(String[], String)} invoked with a <code>" "</code> separator. * * @param s the string array to flatten * @return the flattened string array */ public static String flatten(String s[]) { return flatten(s, " "); }
/** * Trys to get an integer from this token string. Advances the current * position in the token string. * * @param def * a default value if an integer cannot be parsed * @return the integer from this token string or the default value */ public int getInt(int def) { int startpos = pos; while (pos < len) { char c = token.charAt(pos); if (c < '0' || c > '9') { if (c != '-' || startpos != pos) break; } pos++; } if (startpos == pos) return def; return StringUtils.parseIntDef(token.substring(startpos, pos), def); }
protected String getVSphereServiceUrl() { if (StringUtils.isNullOrEmpty((server))) { log.warn("Can't construct vim service url, vSphere host name is empty"); throw new IllegalArgumentException(); } StringBuilder builder = new StringBuilder(); builder.append("https://"); builder.append(server); if (port != null) { builder.append(":"); builder.append(port); } builder.append("/sdk/vimService"); return builder.toString(); }
/** * Tests the {@link StringUtils#capitalize(String)} method. * @param input string to capitalize. * @param expected expected result of the capitalization. */ @Test(dataProvider = "capitalize") public void testCapitalize(String input, String expected) { assert expected.equals(StringUtils.capitalize(input)); }
public boolean accept(String value) { if(isCaseSensitive()) return value.startsWith(s); return StringUtils.startsWithIgnoreCase(value, s); } }
/** * Returns <code>true</code> if <code>a</code> ends with <code>b</code> regardless of the case. * <p> * This method has a known bug under some alphabets with peculiar capitalisation rules such as the Georgian one, * where <code>Character.toUpperCase(a) == Character.toUpperCase(b)</code> doesn't necessarily imply that * <code>Character.toLowerCase(a) == Character.toLowerCase(b)</code>. The performance hit of testing for this * exceptions is so huge that it was deemed an acceptable issue. * </p> * <p> * Note that this method will return <code>true</code> if <code>b</code> is an emptry string. * </p> * @param a string to test. * @param b suffix to test for. * @return <code>true</code> if <code>a</code> ends with <code>b</code> regardless of the case, <code>false</code> otherwise. */ public static boolean endsWithIgnoreCase(String a, String b) { return matchesIgnoreCase(a, b, a.length()); }
/** * Tests the {@link StringUtils#matches(String, char[], int)} method. * @param a first string. * @param b second string. * @param pos position at which to start the comparison. * @param expected expected return value of {@link StringUtils#matches(String, char[], int)} */ @Test(dataProvider = "matches") public void testMatches(String a, String b, int pos, boolean expected) { assert StringUtils.matches(a, b.toCharArray(), pos) == expected; }
/** * Tests the {@link StringUtils#parseIntDef(String, int)} method. * @param input string to parse. * @param def default value. * @param expected expected return value of {@link StringUtils#parseIntDef(String, int)}. */ @Test(dataProvider = "parseIntDef") public void testParseIntDef(String input, int def, int expected) { assert StringUtils.parseIntDef(input, def) == expected; }
/** * Capitalizes the given string, making its first character upper case, and the rest of them lower case. * This method reeturns an empty string if <code>null</code> or an empty string is passed. * * @param s the string to capitalize * @return the capitalized string */ public static String capitalize(String s) { if(isNullOrEmpty(s)) return EMPTY; StringBuilder out; out = new StringBuilder(s.length()); out.append(Character.toUpperCase(s.charAt(0))); if(s.length() > 1) out.append(s.substring(1).toLowerCase()); return out.toString(); }
guestRadioButton = new JRadioButton(StringUtils.capitalize(guestCredentials.getLogin())); guestRadioButton.addActionListener(this); compPanel.addRow(Translator.get("auth_dialog.connect_as"), guestRadioButton, 0);
/** * Tests {@link StringUtils#startsWithIgnoreCase(String, String)}. * @param a first string to compare. * @param b second string to compare. * @param expected expected return value of {@link StringUtils#startsWithIgnoreCase(String, String)}. */ @Test(dataProvider = "startsWithIgnoreCase") public void testStartsWithIgnoreCase(String a, String b, boolean expected) { assert StringUtils.startsWithIgnoreCase(a, b) == expected; }
/** * Returns <code>true</code> if the query part of this URL and the given URL are equal. * The comparison is case-sensitive. * * @param url the URL to test for query equality * @return <code>true</code> if the query part of this URL and the given URL are equal */ public boolean queryEquals(FileURL url) { return StringUtils.equals(this.query, url.query, true); }
private static String getAvailableCustomThemeName(File file) { String name; // Retrieves the file's name, cutting the .xml extension off if // necessary. if(StringUtils.endsWithIgnoreCase(name = file.getName(), ".xml")) name = name.substring(0, name.length() - 4); return getAvailableCustomThemeName(name); }
@Test(dataProvider = "matchesIgnoreCase") public void testMatchesIgnoreCase(String a, String b, int pos, boolean expected) { assert StringUtils.matchesIgnoreCase(a, b, pos) == expected; }