/** * Add the pattern to the node. As a side effect, Branch or EOS nodes may be inserted in the * original place of this node. */ public AddResult add(int depth, String pattern) { AddResult result; PatternNodeFactory patternNodeFactory = parentContext.getPNF(); if (depth == pattern.length()) { PatternNode node = new EndOfStringNode(parentContext, this); result = node.add(depth, pattern); return result; } if (Pattern.getType(depth, pattern) != type) { PatternNode node = new BranchNode(parentContext, this); result = node.add(depth, pattern); return result; } depth++; // if we're at the end of the pattern, don't create unnecessary EOS nodes if (depth == pattern.length()) { return new AddResult(this, this, depth); } if (next == null) { next = patternNodeFactory.getInstance(parentContext, depth, pattern); } result = next.add(depth, pattern); next = result.root; result.root = this; return result; }