cut関数を追加。
@@ -35,9 +35,11 @@ | ||
35 | 35 | } |
36 | 36 | |
37 | 37 | public void testMask() { |
38 | - assertEquals( | |
39 | - "********", | |
40 | - StringUtils.mask("password", '*')); | |
38 | + assertEquals("********", StringUtils.mask("password", '*')); | |
41 | 39 | } |
42 | 40 | |
41 | + public void testCut() { | |
42 | + assertEquals("abc", StringUtils.cut("abcdef", 3)); | |
43 | + assertEquals("abcdef", StringUtils.cut("abcdef", 7)); | |
44 | + } | |
43 | 45 | } |
@@ -190,22 +190,25 @@ | ||
190 | 190 | return sb.toString(); |
191 | 191 | } |
192 | 192 | |
193 | -// /** | |
194 | -// * | |
195 | -// * @return | |
196 | -// */ | |
197 | -// public static String cut(String value, int length){ | |
198 | -// if(value == null){ | |
199 | -// return ""; | |
200 | -// } | |
201 | -// StringBuilder sb = new StringBuilder(); | |
202 | -// for(int i=0;i < value.length();i++){ | |
203 | -// if(i > length){ | |
204 | -// break; | |
205 | -// } | |
206 | -// sb.append(value.charAt(i)); | |
207 | -// } | |
208 | -// return sb.toString(); | |
209 | -// } | |
193 | + /** | |
194 | + * 文字列の先頭から指定文字数までを切り出します。 | |
195 | + * | |
196 | + * @param value 文字列 | |
197 | + * @param length 切り出す文字数 | |
198 | + * @return 切り出された文字列。引数<code>value</code>が<code>null</code>の場合は空文字列 | |
199 | + */ | |
200 | + public static String cut(String value, int length){ | |
201 | + if(value == null){ | |
202 | + return ""; | |
203 | + } | |
204 | + StringBuilder sb = new StringBuilder(); | |
205 | + for(int i=0;i < value.length();i++){ | |
206 | + if(i >= length){ | |
207 | + break; | |
208 | + } | |
209 | + sb.append(value.charAt(i)); | |
210 | + } | |
211 | + return sb.toString(); | |
212 | + } | |
210 | 213 | |
211 | 214 | } |
@@ -26,10 +26,6 @@ | ||
26 | 26 | } |
27 | 27 | } |
28 | 28 | |
29 | - public static void main(String[] args) { | |
30 | - System.out.println(formatDatetime(new Date())); | |
31 | - } | |
32 | - | |
33 | 29 | /** |
34 | 30 | * 日付のフォーマットパターンを設定します。 |
35 | 31 | * デフォルトは<code>"yyyy/MM/dd"</code>です。 |
@@ -44,7 +40,7 @@ | ||
44 | 40 | |
45 | 41 | /** |
46 | 42 | * 日時のフォーマットパターンを設定します。 |
47 | - * デフォルトは<code>"yyyy/MM/dd HH:mm:SS"</code>です。 | |
43 | + * デフォルトは<code>"yyyy/MM/dd HH:mm:ss"</code>です。 | |
48 | 44 | * <p> |
49 | 45 | * このメソッドで設定したフォーマットパターンは{@link #formatDatetime(Date)}で使用されます。 |
50 | 46 | * |
@@ -56,7 +52,7 @@ | ||
56 | 52 | |
57 | 53 | /** |
58 | 54 | * 時間のフォーマットパターンを設定します。 |
59 | - * デフォルトは<code>"HH:mm:SS"</code>です。 | |
55 | + * デフォルトは<code>"HH:mm:ss"</code>です。 | |
60 | 56 | * <p> |
61 | 57 | * このメソッドで設定したフォーマットパターンは{@link #formatTime(Date)}で使用されます。 |
62 | 58 | * |
@@ -148,4 +148,15 @@ | ||
148 | 148 | return NumberUtil.formatNumber(number, pattern); |
149 | 149 | } |
150 | 150 | |
151 | + /** | |
152 | + * 文字列の先頭から指定文字数までを切り出します。 | |
153 | + * | |
154 | + * @param value 文字列 | |
155 | + * @param length 切り出す文字数 | |
156 | + * @return 切り出された文字列。引数<code>value</code>が<code>null</code>の場合は空文字列 | |
157 | + */ | |
158 | + public static String cut(String value, int length){ | |
159 | + return StringUtils.cut(value, length); | |
160 | + } | |
161 | + | |
151 | 162 | } |