【发布时间】:2022-01-16 02:52:24
【问题描述】:
我正在为子字符串搜索实现一系列命令模式。我可以通过编写如下内容来静态创建链:
matchChain = new CharMatcher( new DotMatcher( new CharMatcher(null)));
我明确声明字符串中的每个字符将与模式字符句点字符("c.c")匹配
但我的目标是为任何给定的键模式动态创建此链。例如("\`\`cccc.cc\`\`*c") 将是:
matchChain = new CharMatcher( new CharMatcher( new CharMatcher( new CharMatcher( new CharMatcher(new DotMatcher( new CharMatcher( new CharMatcher( new StarMatcher( new CharMatcher(null)))))));
所以 Chain 类是一个抽象类,每个匹配器类都扩展了 Chain。
那么我怎样才能根据给定键/模式的长度动态实例化一个链呢?
【问题讨论】:
-
您需要为此手动编写代码。
标签: java object design-patterns abstract-class instantiation