Commit d41c1132414340f9239204da6c63c4d4949b1550
1 parent
b3e2c357
Exists in
master
Adição de javadoc à classe br.gov.frameworkdemoiselle.util.String
Showing
1 changed file
with
108 additions
and
0 deletions
Show diff stats
impl/core/src/main/java/br/gov/frameworkdemoiselle/util/Strings.java
| ... | ... | @@ -43,15 +43,41 @@ import java.util.regex.Pattern; |
| 43 | 43 | |
| 44 | 44 | import br.gov.frameworkdemoiselle.annotation.Ignore; |
| 45 | 45 | |
| 46 | +/** | |
| 47 | + * Contain a set of methods that implements a set of functionalities that envolves manipulation of strings. | |
| 48 | + * | |
| 49 | + * @author SERPRO | |
| 50 | + */ | |
| 46 | 51 | public final class Strings { |
| 47 | 52 | |
| 48 | 53 | private Strings() { |
| 49 | 54 | } |
| 50 | 55 | |
| 56 | + /** | |
| 57 | + * Returns if some string matches with the format of a ResourceBundle key or not. | |
| 58 | + * | |
| 59 | + * @param key | |
| 60 | + * string to check if matches with key format of ResourceBundle. | |
| 61 | + * | |
| 62 | + * @return boolean | |
| 63 | + * true if matches and false otherwise. | |
| 64 | + */ | |
| 51 | 65 | public static boolean isResourceBundleKeyFormat(final String key) { |
| 52 | 66 | return Pattern.matches("^\\{(.+)\\}$", key == null ? "" : key); |
| 53 | 67 | } |
| 54 | 68 | |
| 69 | + /** | |
| 70 | + * Removes specific characteres from a given string. | |
| 71 | + * | |
| 72 | + * @param string | |
| 73 | + * string to be changed, by the removing of some characters. | |
| 74 | + * | |
| 75 | + * @param chars | |
| 76 | + * characters to be removed from string. | |
| 77 | + * | |
| 78 | + * @return String | |
| 79 | + * returns the given string without the given characters. | |
| 80 | + */ | |
| 55 | 81 | public static String removeChars(String string, char... chars) { |
| 56 | 82 | String result = string; |
| 57 | 83 | |
| ... | ... | @@ -63,6 +89,20 @@ public final class Strings { |
| 63 | 89 | return result; |
| 64 | 90 | } |
| 65 | 91 | |
| 92 | + /** | |
| 93 | + * Inserts the character "0" in the begin of a given string. The quantity of zeros that will be placed | |
| 94 | + * depends on the difference between the length of the given string and the value of howMuchZeros. | |
| 95 | + * | |
| 96 | + * @param string | |
| 97 | + * string to insert zeros characthers. | |
| 98 | + * | |
| 99 | + * @param howMuchZeros | |
| 100 | + * its controls how much zeros will be insert. | |
| 101 | + * | |
| 102 | + * @return String | |
| 103 | + * Retuns the string, added with appropriate number of zeros. | |
| 104 | + * For exemplo, if string = "yes" and howMuchZeros = 5, the returned string will be "00yes". | |
| 105 | + */ | |
| 66 | 106 | public static String insertZeros(String string, int howMuchZeros) { |
| 67 | 107 | StringBuffer result = new StringBuffer((string == null ? "" : string).trim()); |
| 68 | 108 | int difference = howMuchZeros - result.toString().length(); |
| ... | ... | @@ -74,6 +114,22 @@ public final class Strings { |
| 74 | 114 | return result.toString(); |
| 75 | 115 | } |
| 76 | 116 | |
| 117 | + /** | |
| 118 | + * <p> | |
| 119 | + * Replaces the numbers between braces in the given string with the given parameters. | |
| 120 | + * The process will replace a number between braces for the parameter for which its order | |
| 121 | + * in the set of parameters matches with the number of the given string. | |
| 122 | + * <p> | |
| 123 | + * For exemple, if is received the following string "Treats an {0} exception" and the set of parameters | |
| 124 | + * {"DemoiselleException"}, the return will be the following string: "Treats an DemoiselleException exception". | |
| 125 | + * | |
| 126 | + * @param string | |
| 127 | + * with the numbers with braces to be replaced with the parameters. | |
| 128 | + * @param params | |
| 129 | + * parameters that will replace the number with braces in the given string. | |
| 130 | + * @return String | |
| 131 | + * string with numbers replaced with the matching parameter. | |
| 132 | + */ | |
| 77 | 133 | public static String getString(final String string, final Object... params) { |
| 78 | 134 | String result = null; |
| 79 | 135 | |
| ... | ... | @@ -92,10 +148,28 @@ public final class Strings { |
| 92 | 148 | return result; |
| 93 | 149 | } |
| 94 | 150 | |
| 151 | + /** | |
| 152 | + * Verifies if a given string is empty or null. | |
| 153 | + * | |
| 154 | + * @param string | |
| 155 | + * string to be verified. | |
| 156 | + * | |
| 157 | + * @return boolean | |
| 158 | + * returns true if the given string is empty or null and returns false otherwise. | |
| 159 | + */ | |
| 95 | 160 | public static boolean isEmpty(String string) { |
| 96 | 161 | return string == null || string.trim().isEmpty(); |
| 97 | 162 | } |
| 98 | 163 | |
| 164 | + /** | |
| 165 | + * Converts any object to string. | |
| 166 | + * | |
| 167 | + * @param object | |
| 168 | + * object to be converted. | |
| 169 | + * | |
| 170 | + * @return String | |
| 171 | + * the given object converted to string. | |
| 172 | + */ | |
| 99 | 173 | public static String toString(Object object) { |
| 100 | 174 | StringBuffer result = new StringBuffer(); |
| 101 | 175 | Object fieldValue; |
| ... | ... | @@ -127,6 +201,16 @@ public final class Strings { |
| 127 | 201 | return result.toString(); |
| 128 | 202 | } |
| 129 | 203 | |
| 204 | + /** | |
| 205 | + * Replace the camel case string for a lowercase string separated for a given symbol. | |
| 206 | + * | |
| 207 | + * @param string | |
| 208 | + * string that separeted with camel case. | |
| 209 | + * @param symbol | |
| 210 | + * simbol to be the new separator for the given string. | |
| 211 | + * @return String | |
| 212 | + * the given string separated with the given symbol. | |
| 213 | + */ | |
| 130 | 214 | public static String camelCaseToSymbolSeparated(String string, String symbol) { |
| 131 | 215 | if (symbol == null) { |
| 132 | 216 | symbol = ""; |
| ... | ... | @@ -135,6 +219,14 @@ public final class Strings { |
| 135 | 219 | return string == null ? null : string.replaceAll("\\B([A-Z])", symbol + "$1").toLowerCase(); |
| 136 | 220 | } |
| 137 | 221 | |
| 222 | + /** | |
| 223 | + * Sets the first character of a given string to upper case. | |
| 224 | + * | |
| 225 | + * @param string | |
| 226 | + * | |
| 227 | + * @return String | |
| 228 | + * the given string with the first character setted to upper case. | |
| 229 | + */ | |
| 138 | 230 | public static String firstToUpper(String string) { |
| 139 | 231 | String result = string; |
| 140 | 232 | |
| ... | ... | @@ -145,6 +237,14 @@ public final class Strings { |
| 145 | 237 | return result; |
| 146 | 238 | } |
| 147 | 239 | |
| 240 | + /** | |
| 241 | + * Removes braces from a given string. | |
| 242 | + * | |
| 243 | + * @param string | |
| 244 | + * | |
| 245 | + * @return String | |
| 246 | + * the given string without braces. | |
| 247 | + */ | |
| 148 | 248 | public static String removeBraces(String string) { |
| 149 | 249 | String result = string; |
| 150 | 250 | |
| ... | ... | @@ -155,6 +255,14 @@ public final class Strings { |
| 155 | 255 | return result; |
| 156 | 256 | } |
| 157 | 257 | |
| 258 | + /** | |
| 259 | + * Inserts braces in a given string. | |
| 260 | + * | |
| 261 | + * @param string | |
| 262 | + * | |
| 263 | + * @return String | |
| 264 | + * the given string with braces. | |
| 265 | + */ | |
| 158 | 266 | public static String insertBraces(String string) { |
| 159 | 267 | String result = string; |
| 160 | 268 | ... | ... |