@Test public void testBuildText() { HanZiSeqStyle style = new HanZiSeqStyle(); assertEquals("二百一十一", style.build(211)); assertEquals("二百零一", style.build(201)); assertEquals("三千零十一", style.build(3011)); }
public String buildText(String str1) { StringBuilder sb = new StringBuilder(); int prev = 0; for (int i = 0; i < str1.length(); i++) { char numChar = str1.charAt(i); String temp = basicOf(numChar - '0'); if (numChar - '0' > 0) { if (i - prev > 1) temp = CHINESE_NAMES[0] + temp; prev = i; temp = temp + priorityOf(str1.length() - i); sb.append(temp); } } String result = sb.toString(); if (result.startsWith("一十")) result = result.substring(1); return result.replaceAll("零一十", "零十"); }
HanZiSeqStyle implements SeqNumStyle { public String buildText(String str1) { StringBuilder sb = new StringBuilder(); int prev = 0; for (int i = 0; i < str1.length(); i++) { char numChar = str1.charAt(i); String temp = basicOf(numChar - '0'); if (numChar - '0' > 0) { if (i - prev > 1) temp = CHINESE_NAMES[0] + temp; prev = i; temp = temp + priorityOf(str1.length() - i); sb.append(temp); } } String result = sb.toString(); if (result.startsWith("一十")) result = result.substring(1); return result.replaceAll("零一十", "零十"); } }
HanZiSeqStyle implements SeqNumStyle { public String buildText(String str1) { StringBuilder sb = new StringBuilder(); int prev = 0; for (int i = 0; i < str1.length(); i++) { char numChar = str1.charAt(i); String temp = basicOf(numChar - '0'); if (numChar - '0' > 0) { if (i - prev > 1) temp = CHINESE_NAMES[0] + temp; prev = i; temp = temp + priorityOf(str1.length() - i); sb.append(temp); } } String result = sb.toString(); if (result.startsWith("一十")) result = result.substring(1); return result.replaceAll("零一十", "零十"); }  }
HanZiSeqStyle implements SeqNumStyle { public String buildText(String str1) { StringBuilder sb = new StringBuilder(); int prev = 0; for (int i = 0; i < str1.length(); i++) { char numChar = str1.charAt(i); String temp = basicOf(numChar - '0'); if (numChar - '0' > 0) { if (i - prev > 1) temp = CHINESE_NAMES[0] + temp; prev = i; temp = temp + priorityOf(str1.length() - i); sb.append(temp); } } String result = sb.toString(); if (result.startsWith("一十")) result = result.substring(1); return result.replaceAll("零一十", "零十"); }  String build(int seq); String basicOf(int num); String priorityOf(int index); String buildText(String str1); }
HanZiSeqStyle implements SeqNumStyle { public String buildText(String str1) { StringBuilder sb = new StringBuilder(); int prev = 0; for (int i = 0; i < str1.length(); i++) { char numChar = str1.charAt(i); String temp = basicOf(numChar - '0'); if (numChar - '0' > 0) { if (i - prev > 1) temp = CHINESE_NAMES[0] + temp; prev = i; temp = temp + priorityOf(str1.length() - i); sb.append(temp); } } String result = sb.toString(); if (result.startsWith("一十")) result = result.substring(1); return result.replaceAll("零一十", "零十"); }  String build(int seq); String basicOf(int num); String priorityOf(int index); String buildText(String str1); static final int MAX; static final String[] CHINESE_NAMES; static final String[] PRIORITIES; }