maskメソッドを追加&TLDに各関数の説明を記述。
@@ -123,4 +123,26 @@ | ||
123 | 123 | return sb.toString(); |
124 | 124 | } |
125 | 125 | |
126 | + /** | |
127 | + * 引数<code>value</code>と同じ長さの<code>maskChar</code>からなる文字列を返します。 | |
128 | + * <p> | |
129 | + * たとえば、このメソッドを以下のように呼び出した場合、 | |
130 | + * <code>result</code>は<code>"*******"</code>となります。 | |
131 | + * <pre> String result = StringUtils.mask("password", '*'); </pre> | |
132 | + * | |
133 | + * @param value マスク対象の文字列 | |
134 | + * @param maskChar マスクする文字 | |
135 | + * @return 引数<code>maskChar</code>でマスクされた文字列。引数<code>value</code>が<code>null</code>の場合は空文字列 | |
136 | + */ | |
137 | + public static String mask(String value, char maskChar){ | |
138 | + if(value == null){ | |
139 | + return ""; | |
140 | + } | |
141 | + StringBuilder sb = new StringBuilder(); | |
142 | + for(int i=0; i < value.length(); i++){ | |
143 | + sb.append(maskChar); | |
144 | + } | |
145 | + return sb.toString(); | |
146 | + } | |
147 | + | |
126 | 148 | } |
@@ -61,6 +61,17 @@ | ||
61 | 61 | } |
62 | 62 | |
63 | 63 | /** |
64 | + * 文字列を*(アスタリスク)に変換します。 | |
65 | + * | |
66 | + * @param value 変換対象の文字列 | |
67 | + * @return 変換後の文字列。引数<code>value</code>が<code>null</code>の場合は空文字列 | |
68 | + * @see StringUtils#mask(String, char) | |
69 | + */ | |
70 | + public static String mask(String value){ | |
71 | + return StringUtils.mask(value, '*'); | |
72 | + } | |
73 | + | |
74 | + /** | |
64 | 75 | * <code>java.util.Date</code>オブジェクトを日付形式にフォーマットして表示します。 |
65 | 76 | * |
66 | 77 | * @param date 変換対象の<code>java.util.Date</code>オブジェクト |