All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.swisspush.reststorage.util.ResourceNameUtil Maven / Gradle / Ivy

There is a newer version: 3.1.8
Show newest version
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); } } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy