private static String getACKKey(String host, int port, long lastRefTime) { return StringUtils.strip(host) + "," + port + "," + lastRefTime; }
/** * <p>Strips whitespace from the start and end of a String.</p> * * <p>This is similar to {@link #trim(String)} but removes whitespace. * Whitespace is defined by {@link Character#isWhitespace(char)}.</p> * * <p>A {@code null} input String returns {@code null}.</p> * * <pre> * StringUtils.strip(null) = null * StringUtils.strip("") = "" * StringUtils.strip(" ") = "" * StringUtils.strip("abc") = "abc" * StringUtils.strip(" abc") = "abc" * StringUtils.strip("abc ") = "abc" * StringUtils.strip(" abc ") = "abc" * StringUtils.strip(" ab c ") = "ab c" * </pre> * * @param str the String to remove whitespace from, may be null * @return the stripped String, {@code null} if null String input */ public static String strip(final String str) { return strip(str, null); }
/** * <p>Strips whitespace from the start and end of a String returning * an empty String if {@code null} input.</p> * * <p>This is similar to {@link #trimToEmpty(String)} but removes whitespace. * Whitespace is defined by {@link Character#isWhitespace(char)}.</p> * * <pre> * StringUtils.stripToEmpty(null) = "" * StringUtils.stripToEmpty("") = "" * StringUtils.stripToEmpty(" ") = "" * StringUtils.stripToEmpty("abc") = "abc" * StringUtils.stripToEmpty(" abc") = "abc" * StringUtils.stripToEmpty("abc ") = "abc" * StringUtils.stripToEmpty(" abc ") = "abc" * StringUtils.stripToEmpty(" ab c ") = "ab c" * </pre> * * @param str the String to be stripped, may be null * @return the trimmed String, or an empty String if {@code null} input * @since 2.0 */ public static String stripToEmpty(final String str) { return str == null ? EMPTY : strip(str, null); }
newArr[i] = strip(strs[i], stripChars);
/** * <p>Strips whitespace from the start and end of a String returning * {@code null} if the String is empty ("") after the strip.</p> * * <p>This is similar to {@link #trimToNull(String)} but removes whitespace. * Whitespace is defined by {@link Character#isWhitespace(char)}.</p> * * <pre> * StringUtils.stripToNull(null) = null * StringUtils.stripToNull("") = null * StringUtils.stripToNull(" ") = null * StringUtils.stripToNull("abc") = "abc" * StringUtils.stripToNull(" abc") = "abc" * StringUtils.stripToNull("abc ") = "abc" * StringUtils.stripToNull(" abc ") = "abc" * StringUtils.stripToNull(" ab c ") = "ab c" * </pre> * * @param str the String to be stripped, may be null * @return the stripped String, * {@code null} if whitespace, empty or null String input * @since 2.0 */ public static String stripToNull(String str) { if (str == null) { return null; } str = strip(str, null); return str.isEmpty() ? null : str; }
private static boolean isHttpUrl(String name) { String stripped = StringUtils.strip(name); if (stripped == null) { return false; } return stripped.startsWith("http://") || stripped.startsWith("https://"); }
private List<String> getTrimmedStringList(String[] strings) { List<String> list = Lists.newArrayList(); for (String s : strings) { list.add(StringUtils.strip(s)); } return list; } }
private String relativeRoot(String absoluteRoot, String repoUrl) { return StringUtils.strip(StringUtils.remove(absoluteRoot, repoUrl), "/"); }
/** * Create a normalized name from an arbitrary string.<br> * Paths separators are replaced, so this function can't be applied on a whole path, but must be called on each path sections. * * @param name current name of the file * @return a normalized filename */ public static String normalizeName(String name) { String fileName = NAME_FORBIDDEN_PATTERN.matcher(name).replaceAll("_"); fileName = fileName.replaceAll(String.format("([%1$s])([%1$s]+)", "-_"), "$1"); fileName = StringUtils.strip(fileName, "_-"); fileName = fileName.trim(); return fileName; }
public static MIMEContainer Math(String data) { data = StringUtils.strip(data, "$"); return addMimeType(MIME.TEXT_LATEX, "$$" + data + "$$"); }
private static boolean isValidUrl(String name) { if (isHttpUrl(name)) { String url = StringUtils.strip(name); try { // FIXME : Do we really need to perform a request? if it's a url we should treat it as one even if the server is down HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection(); connection.setRequestMethod("HEAD"); connection.setConnectTimeout(ResourceLoader.TIMEOUT); connection.setReadTimeout(ResourceLoader.TIMEOUT); int responseCode = connection.getResponseCode(); if (responseCode == 200) { return true; } } catch (IOException e) { return false; } } return false; }
public int getNumberOfCommentedOutLinesOfCode() { if (isDocComment()) { return 0; } int numberOfCommentedOutLinesOfCode = 0; for (String line : lines) { String strippedLine = org.apache.commons.lang3.StringUtils.strip(line, " /*"); if (CodeDetector.hasDetectedCode(strippedLine)) { numberOfCommentedOutLinesOfCode++; } } return numberOfCommentedOutLinesOfCode; }
result = StringUtils.strip(result, "[]");
@Test public void testStrip_String() { assertNull(StringUtils.strip(null)); assertEquals("", StringUtils.strip("")); assertEquals("", StringUtils.strip(" ")); assertEquals("abc", StringUtils.strip(" abc ")); assertEquals(StringUtilsTest.NON_WHITESPACE, StringUtils.strip(StringUtilsTest.WHITESPACE + StringUtilsTest.NON_WHITESPACE + StringUtilsTest.WHITESPACE)); }
@Test public void testStrip_StringString() { // null strip assertNull(StringUtils.strip(null, null)); assertEquals("", StringUtils.strip("", null)); assertEquals("", StringUtils.strip(" ", null)); assertEquals("abc", StringUtils.strip(" abc ", null)); assertEquals(StringUtilsTest.NON_WHITESPACE, StringUtils.strip(StringUtilsTest.WHITESPACE + StringUtilsTest.NON_WHITESPACE + StringUtilsTest.WHITESPACE, null)); // "" strip assertNull(StringUtils.strip(null, "")); assertEquals("", StringUtils.strip("", "")); assertEquals(" ", StringUtils.strip(" ", "")); assertEquals(" abc ", StringUtils.strip(" abc ", "")); assertEquals(StringUtilsTest.WHITESPACE, StringUtils.strip(StringUtilsTest.WHITESPACE, "")); // " " strip assertNull(StringUtils.strip(null, " ")); assertEquals("", StringUtils.strip("", " ")); assertEquals("", StringUtils.strip(" ", " ")); assertEquals("abc", StringUtils.strip(" abc ", " ")); // "ab" strip assertNull(StringUtils.strip(null, "ab")); assertEquals("", StringUtils.strip("", "ab")); assertEquals(" ", StringUtils.strip(" ", "ab")); assertEquals(" abc ", StringUtils.strip(" abc ", "ab")); assertEquals("c", StringUtils.strip("abcabab", "ab")); assertEquals(StringUtilsTest.WHITESPACE, StringUtils.strip(StringUtilsTest.WHITESPACE, "")); }
ruleSetFileName = StringUtils.strip(id); allRules = true; ruleName = null; ruleSetFileName = StringUtils.strip(tempRuleSetFileName); ruleName = StringUtils.strip(tempRuleName); allRules = tempRuleName == null; } else if (isHttpUrl(id)) { ruleSetFileName = StringUtils.strip(id); allRules = true; ruleName = null;
@Override public String transform(String resultToParse) { StringBuilder resultSQLite = new StringBuilder(); String resultTmp = resultToParse.replaceFirst(".+?\\(", "").trim().replaceAll("\\)$", ""); resultTmp = resultTmp.replaceAll("\\(.+?\\)", ""); for (String columnNameAndType: resultTmp.split(",")) { // Some recent SQLite use tabulation character as a separator => split() by any white space \s String columnName = columnNameAndType.trim().split("\\s")[0]; // Some recent SQLite enclose names with ` => strip those ` columnName = StringUtils.strip(columnName, "`"); if (!"CONSTRAINT".equals(columnName) && !"UNIQUE".equals(columnName)) { resultSQLite.append((char) 4 + columnName + (char) 5 + "0" + (char) 4 + (char) 6); } } return resultSQLite.toString(); }
private long readTimestampFromFile() { String timestampString; try { timestampString = StringUtils.strip(Iterables.getOnlyElement(Files.readAllLines(file.toPath()))); } catch (IOException e) { printer.error("IOException thrown reading timestamp from file: {}", SafeArg.of("file path", file.getPath())); throw Throwables.propagate(e); } return Long.parseLong(timestampString); }
public String getIdentifier(final LogicalPath logicalPath, final String relativePath) { Validate.notNull(logicalPath, "Path required"); Validate.notNull(relativePath, "Relative path cannot be null, although it can be empty"); String initialPath = FileUtils.getCanonicalPath(getPath(logicalPath)); initialPath = FileUtils.ensureTrailingSeparator(initialPath); return initialPath + StringUtils.strip(relativePath, File.separator); }