public void FindAmbiguities(AmbiguityConsumer <TSource> consumer) { var matches = new HashSet <string>(); foreach (var child in _children.Values) { foreach (var sibling in _children.Values) { if (child == sibling) { continue; } foreach (var input in child.Examples) { if (sibling.IsValidInput(input)) { matches.Add(input); } } if (matches.Count > 0) { consumer(this, child, sibling, matches); matches = new HashSet <string>(); } } child.FindAmbiguities(consumer); } }
/** * Scans the command tree for potential ambiguous commands. * * <p>This is a shortcut for {@link CommandNode#findAmbiguities(AmbiguityConsumer)} on {@link #getRoot()}.</p> * * <p>Ambiguities are detected by testing every {@link CommandNode#getExamples()} on one node verses every sibling * node. This is not fool proof, and relies a lot on the providers of the used argument types to give good examples.</p> * * @param consumer a callback to be notified of potential ambiguities */ public void FindAmbiguities(AmbiguityConsumer <TSource> consumer) { _root.FindAmbiguities(consumer); }