🎨
Andy開發紀錄
  • 關於
    • 自介
  • 設計模式
    • 觀察者模型
    • 有限狀態機
    • 裝飾器模式
  • 其他
    • Scrum敏捷式開發
    • SOLID設計
    • TDD驅動測試開發
    • Event Driven Architecture
    • CQRS命令查詢職責分離
    • Concurrent並行相關
      • Single Thread Execution
      • 共用元件設計
        • CountDownLatchWorkPool
        • IForkWorkService
      • Pattern
        • THREAD-PER-MESSAGE
        • PRODUCER CONSUMER
        • SINGLE THREAD
        • Guarded Suspension 守衛模式
      • IQueue
        • ListQueue
        • BlockQueue
        • OrderBlockQueue
  • 元件設計
    • Sql Help
      • SQL Help Generate
      • StringBuilderGenerator
      • SQL Generate
    • excel工具
    • BDD行為驅動開發
    • 多工設計
      • 多工自動調整Thread數量
    • 常用Design Patten實作
    • Telegram Bot元件
    • 代碼元件
    • HCP API元件
    • 文字解析元件
    • MockitObject
    • 資料驗證元件
    • Zip壓縮工具
    • Sql Code Generate
  • 讀書心得
    • Clean code第一章
  • side project
    • 後端服務
  • IDEA
    • IDEA 外掛推薦
    • IDEA 外掛開發
Powered by GitBook
On this page

Was this helpful?

  1. 元件設計

文字解析元件

常見拆解文字有兩種方式,為了避免修改格式造成程式修改容易建立共用元件

  • byte長度切割

  • char長度切割

class TextCutRuleslSeriveTest {
	private final String UTF8 = "utf-8";
	ITextCutRuleslSerive<List<String>> textCutRuleslSerive = new TextCutRuleslSerive<>();

	public TextCutRuleslSeriveTest() {
		textCutRuleslSerive.addRule(i -> i.startsWith("ST01"), getST01());
		textCutRuleslSerive.addRule(i -> i.startsWith("ST02"), getST02());
		textCutRuleslSerive.addRule(i -> i.startsWith("ST03"), getST03());

	}

	@Test
	public void test_give_4Line_reutrn_4Line() {

		// GIVE
		// ST011234567890,ST0212345,ST0312
		List<String> line = new ArrayList<String>();
		line.add("ST011234567890");
		line.add("ST0212345");
		line.add("ST0312");
		line.add("ST010987654321");

		// WHEN 轉換
		List<List<String>> list = textCutRuleslSerive.to(line);

		// THEN
		System.out.println(list);

		assertThat(list.get(0).get(0).endsWith("ST01"));
		assertThat(list.get(0).get(1).endsWith("1234567890"));

		assertThat(list.get(1).get(0).endsWith("ST02"));
		assertThat(list.get(1).get(1).endsWith("12345"));

		assertThat(list.get(2).get(0).endsWith("ST03"));
		assertThat(list.get(2).get(1).endsWith("12"));

		assertThat(list.get(3).get(0).endsWith("ST01"));
		assertThat(list.get(3).get(1).endsWith("0987654321"));

	}

	TextCutRoleConfig<List<String>> getST01() {
		TextCutRoleConfig<List<String>> textCutRoleConfig = new TextCutRoleConfig<>(TextCutType.BYTE, UTF8,
				line -> line.getLines());
		textCutRoleConfig.addRole(4);
		textCutRoleConfig.addRole(10);
		return textCutRoleConfig;

	}

	TextCutRoleConfig<List<String>> getST02() {
		TextCutRoleConfig<List<String>> textCutRoleConfig = new TextCutRoleConfig<>(TextCutType.BYTE, UTF8,
				line -> line.getLines());
		textCutRoleConfig.addRole(4);
		textCutRoleConfig.addRole(5);
		return textCutRoleConfig;

	}

	TextCutRoleConfig<List<String>> getST03() {
		TextCutRoleConfig<List<String>> textCutRoleConfig = new TextCutRoleConfig<>(TextCutType.BYTE, UTF8,
				line -> line.getLines());
		textCutRoleConfig.addRole(4);
		textCutRoleConfig.addRole(2);
		return textCutRoleConfig;

	}

}
PreviousHCP API元件NextMockitObject

Last updated 2 years ago

Was this helpful?