| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- package xin.glue.user.common;
- import java.text.DecimalFormat;
- import java.text.ParseException;
- public class StringUtils
- {
- private StringUtils()
- {
- }
- /**
- * String 포맷으로 된 Integer를 incremental만큼 증가시켜서 String으로 리턴한다.
- * (예, calculateIntegerStringValue("00034", 2) -> "00036"
- * calculateIntegerStringValue("00034", -5) -> "00029")
- *
- * 주의) 실수(實數)는 지원하지 않는다.
- *
- * @param value String 포맷 Integer
- * @param incremental 증분 값
- * @return incremental만큼 증가된 String 포맷 Number
- */
- public static String calculateIntegerStringValue(String value,
- int incremental)
- {
- if (value == null || value.length() == 0)
- throw new IllegalArgumentException("String Value is invalid :" + value);
-
- int length = value.length();
- String digit = "";
- for (int i=0; i<length; i++)
- digit += "0";
-
- DecimalFormat decimalFormat = new DecimalFormat(digit);
- Long number = null;
- try
- {
- number = (Long)decimalFormat.parse(value);
- }
- catch (ParseException pe)
- {
- throw new RuntimeException(
- "Cannot convert StringNumber - " + pe.getMessage(), pe);
- }
-
- // long value 처리
- int result = number.intValue() + incremental;
- return decimalFormat.format((long)result);
- }
-
- public static void main(String[] args)
- {
- // String val =
- // StringUtils.calculateIntegerStringValue("00000123", 30);
- // System.out.println(val);
- //
- // val = StringUtils.calculateIntegerStringValue("00200123", 1);
- // System.out.println(val);
- // for (int i=0; i<100; i++)
- // {
- // System.out.println(StringUtils.calculateIntegerStringValue("00000123", i));
- // }
-
-
-
- System.out.println((char)(66));
-
-
- }
- }
|