df9ea0af0c7a057b87010cac1e5330d44778fd11.svn-base 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. package xin.glue.user.common;
  2. import java.text.DecimalFormat;
  3. import java.text.ParseException;
  4. public class StringUtils
  5. {
  6. private StringUtils()
  7. {
  8. }
  9. /**
  10. * String 포맷으로 된 Integer를 incremental만큼 증가시켜서 String으로 리턴한다.
  11. * (예, calculateIntegerStringValue("00034", 2) -> "00036"
  12. * calculateIntegerStringValue("00034", -5) -> "00029")
  13. *
  14. * 주의) 실수(實數)는 지원하지 않는다.
  15. *
  16. * @param value String 포맷 Integer
  17. * @param incremental 증분 값
  18. * @return incremental만큼 증가된 String 포맷 Number
  19. */
  20. public static String calculateIntegerStringValue(String value,
  21. int incremental)
  22. {
  23. if (value == null || value.length() == 0)
  24. throw new IllegalArgumentException("String Value is invalid :" + value);
  25. int length = value.length();
  26. String digit = "";
  27. for (int i=0; i<length; i++)
  28. digit += "0";
  29. DecimalFormat decimalFormat = new DecimalFormat(digit);
  30. Long number = null;
  31. try
  32. {
  33. number = (Long)decimalFormat.parse(value);
  34. }
  35. catch (ParseException pe)
  36. {
  37. throw new RuntimeException(
  38. "Cannot convert StringNumber - " + pe.getMessage(), pe);
  39. }
  40. // long value 처리
  41. int result = number.intValue() + incremental;
  42. return decimalFormat.format((long)result);
  43. }
  44. public static void main(String[] args)
  45. {
  46. // String val =
  47. // StringUtils.calculateIntegerStringValue("00000123", 30);
  48. // System.out.println(val);
  49. //
  50. // val = StringUtils.calculateIntegerStringValue("00200123", 1);
  51. // System.out.println(val);
  52. // for (int i=0; i<100; i++)
  53. // {
  54. // System.out.println(StringUtils.calculateIntegerStringValue("00000123", i));
  55. // }
  56. System.out.println((char)(66));
  57. }
  58. }