public static String info(String pattern,Object... params){ for (Object p:params){ pattern = StringUtils.replaceOnce(pattern, "{}", p.toString()); } return pattern; }
private static String[] replaceWithSysPropUserHome(final String[] pathArray) { if (ArrayUtils.isEmpty(pathArray)) { return pathArray; } final String SYS_PROP_USER_HOME = System.getProperty("user.home"); for (int index = 0; index < pathArray.length; index++) { if (StringUtils.startsWith(pathArray[index], "~")) { pathArray[index] = StringUtils.replaceOnce(pathArray[index], "~", SYS_PROP_USER_HOME); } } return pathArray; }
String tmp = StringUtils.replaceOnce(duration, " 0 days", StringUtils.EMPTY); if (tmp.length() != duration.length()) { duration = tmp; tmp = StringUtils.replaceOnce(duration, " 0 hours", StringUtils.EMPTY); if (tmp.length() != duration.length()) { duration = tmp; tmp = StringUtils.replaceOnce(duration, " 0 minutes", StringUtils.EMPTY); duration = tmp; if (tmp.length() != duration.length()) { duration = StringUtils.replaceOnce(tmp, " 0 seconds", StringUtils.EMPTY); String tmp = StringUtils.replaceOnce(duration, " 0 seconds", StringUtils.EMPTY); if (tmp.length() != duration.length()) { duration = tmp; tmp = StringUtils.replaceOnce(duration, " 0 minutes", StringUtils.EMPTY); if (tmp.length() != duration.length()) { duration = tmp; tmp = StringUtils.replaceOnce(duration, " 0 hours", StringUtils.EMPTY); if (tmp.length() != duration.length()) { duration = StringUtils.replaceOnce(tmp, " 0 days", StringUtils.EMPTY); duration = StringUtils.replaceOnce(duration, " 1 seconds", " 1 second"); duration = StringUtils.replaceOnce(duration, " 1 minutes", " 1 minute"); duration = StringUtils.replaceOnce(duration, " 1 hours", " 1 hour"); duration = StringUtils.replaceOnce(duration, " 1 days", " 1 day"); return duration.trim();
@Test public void testReplaceOnce_StringStringString() { assertNull(StringUtils.replaceOnce(null, null, null)); assertNull(StringUtils.replaceOnce(null, null, "any")); assertNull(StringUtils.replaceOnce(null, "any", null)); assertNull(StringUtils.replaceOnce(null, "any", "any")); assertEquals("", StringUtils.replaceOnce("", null, null)); assertEquals("", StringUtils.replaceOnce("", null, "any")); assertEquals("", StringUtils.replaceOnce("", "any", null)); assertEquals("", StringUtils.replaceOnce("", "any", "any")); assertEquals("FOO", StringUtils.replaceOnce("FOO", "", "any")); assertEquals("FOO", StringUtils.replaceOnce("FOO", null, "any")); assertEquals("FOO", StringUtils.replaceOnce("FOO", "F", null)); assertEquals("FOO", StringUtils.replaceOnce("FOO", null, null)); assertEquals("foofoo", StringUtils.replaceOnce("foofoofoo", "foo", "")); }
result = StringUtils.replaceOnce(result, escapedDirective, resolved);
@Override public String getBaseUrlControllerForFinder(ClassOrInterfaceTypeDetails controller, String finder) { String basePath = getBaseUrlForController(controller); return basePath + StringUtils.replaceOnce(finder, "findBy", "by"); }
/** * Converts internal path segments to their external formats. * @param path the internal path * @return the external path */ public static String convertToExternalPath(final String path) { String newPath = replaceOnce(path, "/" + CONTAINER_WEBAC_ACL, "/" + FCR_ACL); newPath = replaceOnce(newPath, "/" + LDPCV_TIME_MAP, "/" + FCR_VERSIONS); newPath = replaceOnce(newPath, "/" + FEDORA_DESCRIPTION, "/" + FCR_METADATA); return newPath; }
@Override protected String handle(String input, String second, String third) { return StringUtils.replaceOnce(input, second, third); }
protected String processBeforeInjection(String text, Node content, RenderableDefinition definition) throws RepositoryException { for (String argument : arguments) { if (content.hasProperty(argument)) { text = StringUtils.replaceOnce(text, "${" + argument + "}", content.getProperty(argument).getString()); } else { log.warn("Cannot replace '{}' since '{}' doesn't have such property.", "${" + argument + "}", content); } } return text; }
/** * Apply time stamp to rule definition * @return string */ private String applyTimeStampToRuleDefinition(String rule, String timeStamp) { String name = RegexParser.getNameFromRule(rule); String formatted = String.format("%s (%s)", name, timeStamp); return StringUtils.replaceOnce(rule, name, formatted); }
@Nonnull public StripResult removeFormatting(String text) { Matcher matcher = COLOR_PATTERN.matcher(text); String result = text; String removed = EMPTY; while (matcher.matches()) { String group = matcher.group(1); removed += group; result = replaceOnce(result, group, EMPTY); matcher = COLOR_PATTERN.matcher(result); } return new StripResult(result, removed); }
@Transactional(readOnly = true) @Override public int count() { StringBuilder queryString = buildFindAllQuery(); Query query = entityManager().createQuery(StringUtils.replaceOnce( queryString.toString(), "SELECT e", "SELECT COUNT(e)")); return ((Number) query.getSingleResult()).intValue(); }
/** Renders the short name of this type given its pattern. */ public String getNickname() { if (pattern == null) { return topLevelAlias.getNickname(); } String result = StringUtils.replaceOnce(pattern, "%s", topLevelAlias.getNickname()); for (TypeName innerTypeName : innerTypeNames) { result = StringUtils.replaceOnce(result, "%i", innerTypeName.getNickname()); } return result; }
/** Renders the fully-qualified name of this type given its pattern. */ public String getFullName() { if (pattern == null) { return topLevelAlias.getFullName(); } String result = StringUtils.replaceOnce(pattern, "%s", topLevelAlias.getFullName()); for (TypeName innerTypeName : innerTypeNames) { result = StringUtils.replaceOnce(result, "%i", innerTypeName.getFullName()); } return result; }
private String getShortCwd() { String currentDir = contextCommands.getCurrentDir(); if (currentDir.startsWith("/user/")) { final String userHome = "/user/" + this.getWhoami();//call getWhoami later if (currentDir.startsWith(userHome)) { currentDir = StringUtils.replaceOnce(currentDir, userHome, "~"); } } return currentDir; } }
@Override public String getFormattedModNameForModId(String modId) { String modNameFormat = Config.getModNameFormat(); if (modNameFormat.isEmpty()) { return null; } String modName = getModNameForModId(modId); modName = removeChatFormatting(modName); // some crazy mod has formatting in the name if (modNameFormat.contains(MOD_NAME_FORMAT_CODE)) { return StringUtils.replaceOnce(modNameFormat, MOD_NAME_FORMAT_CODE, modName); } return modNameFormat + modName; }
/** * We get the relative path for this file * removing the JIRA Home Path */ Option<String> getRelativePathOf(final JiraHome jiraHome, final File file) { if(file.getAbsolutePath().startsWith(jiraHome.getHomePath())) { return Option.some(StringUtils.replaceOnce(file.getAbsolutePath(), jiraHome.getHomePath(), "")); } return Option.none(); } }
@Override protected String doForward(final String path) { if (path.contains(TX_PREFIX) && !path.contains(txSegment())) { throw new RepositoryRuntimeException("Path " + path + " is not in current transaction " + session.getId()); } return replaceOnce(path, txSegment(), EMPTY); }
protected Path expand(final Path remote, final String format) { if(remote.getAbsolute().startsWith(format)) { return new Path(StringUtils.replaceOnce(remote.getAbsolute(), format, workdir.getAbsolute()), remote.getType()); } return remote; } }
/** * Renders the value given the value pattern, and adds any necessary nicknames to the given type * table. */ public String getValueAndSaveTypeNicknameIn(TypeTable typeTable) { if (getValuePattern().contains("%s")) { String nickname = typeTable.getAndSaveNicknameFor(getTypeName()); return StringUtils.replaceOnce(getValuePattern(), "%s", nickname); } else { return getValuePattern(); } } }