org.swisspush.reststorage.util.ResourceNameUtil Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of rest-storage Show documentation
Show all versions of rest-storage Show documentation
Persistence for REST resources in the filesystem or a redis database
package org.swisspush.reststorage.util;
import java.util.List;
/**
*
* Utility class providing handy methods to handle resource names.
*
*
* @author https://github.com/mcweba [Marc-Andre Weber]
*/
public final class ResourceNameUtil {
public static final String COLON_REPLACEMENT = "§";
public static final String SEMICOLON_REPLACEMENT = "°";
private ResourceNameUtil() {
// prevent instantiation
}
/**
*
* Replaces all colons in the provided resourceName with {@link ResourceNameUtil#COLON_REPLACEMENT}.
*
*
*
* ResourceNameUtil.replaceColonsAndSemiColons(null) = null
* ResourceNameUtil.replaceColonsAndSemiColons("") = ""
* ResourceNameUtil.replaceColonsAndSemiColons("bob") = "bob"
* ResourceNameUtil.replaceColonsAndSemiColons("bob_:_;_alice") = "bob_§_°_alice"
*
*
* @param resourceName the String to replace the colons and semicolons, may be null
* @return a string with the replaced values
*/
public static String replaceColonsAndSemiColons(String resourceName){
if(resourceName == null){
return null;
}
return resourceName.replaceAll(":", COLON_REPLACEMENT).replaceAll(";", SEMICOLON_REPLACEMENT);
}
/**
*
* Replaces all colons and semicolons in all strings of the provided resourceNames with {@link ResourceNameUtil#COLON_REPLACEMENT} and {@link ResourceNameUtil#SEMICOLON_REPLACEMENT}.
*
*
* @param resourceNames the list of strings to replace the colons and semicolons, may be null
*/
public static void replaceColonsAndSemiColonsInList(List resourceNames){
if(resourceNames != null){
resourceNames.replaceAll(ResourceNameUtil::replaceColonsAndSemiColons);
}
}
/**
*
* Resets the replaced colons and semicolons in the provided resourceName with a colon or semicolon.
*
*
*
* ResourceNameUtil.resetReplacedColonsAndSemiColons(null) = null
* ResourceNameUtil.resetReplacedColonsAndSemiColons("") = ""
* ResourceNameUtil.resetReplacedColonsAndSemiColons("bob") = "bob"
* ResourceNameUtil.resetReplacedColonsAndSemiColons("bob_§_°_alice") = "bob_:_;_alice"
*
*
* @param resourceName the String to reset the replaced the colons and semicolons, may be null
* @return a string with the resetted values
*/
public static String resetReplacedColonsAndSemiColons(String resourceName){
if(resourceName == null){
return null;
}
return resourceName.replaceAll(COLON_REPLACEMENT, ":").replaceAll(SEMICOLON_REPLACEMENT, ";");
}
/**
*
* Resets the replaced colons and semicolons in all strings of the provided resourceNames with a colon or semicolon.
*
*
* @param resourceNames the list of strings to reset the colons and semicolons, may be null
*/
public static void resetReplacedColonsAndSemiColonsInList(List resourceNames){
if(resourceNames != null){
resourceNames.replaceAll(ResourceNameUtil::resetReplacedColonsAndSemiColons);
}
}
}