public List<TokenHook> compile() throws InvalidOperationException { if (this.compiled) { throw new IllegalStateException("XMLEditableString already compiled"); } if (tokenMask != null) { for (int[] positions : this.tokenMask) { int startPosition = positions[0]; int length = positions[1]; TokenHook hook = new TokenHook(startPosition, length, TokenHook.TokenType.Word); hook.processedString = this.currentString.substring(startPosition, startPosition + length); this.tokens.add(hook); } } this.reverseChangeLog(); this.compiled = true; ArrayList<TokenHook> hooks = new ArrayList<>(this.tokens.size() + this.xml.size()); hooks.addAll(this.tokens); hooks.addAll(this.xml); Collections.sort(hooks, (t1, t2) -> t1.startIndex - t2.startIndex); return hooks; }