void (@NonNls String key, int value) { if (key.isEmpty()) { myValues.add(value); return; } for (int c = 0; c < myChildren.size(); c++) { PrefixTree child = myChildren.get(c); int i, limit = Math.min(key.length(), child.myPrefix.length()); for (i = 0; i < limit; i++) { if (key.charAt(i) != child.myPrefix.charAt(i)) break; } if (i == child.myPrefix.length()) { child.add(key.substring(limit), value); return; } else if (i > 0) { PrefixTree firstPart = new PrefixTree(key.substring(0, i)); child.myPrefix = child.myPrefix.substring(i); firstPart.myChildren.add(child); myChildren.set(c, firstPart); firstPart.add(key.substring(i), value); return; } } PrefixTree newSubtree = new PrefixTree(key); newSubtree.myValues.add(value); myChildren.add(newSubtree); }