*/
public void addCommand(int commandOffset, int commandLength, String commandText, IDocumentListener commandOwner) throws BadLocationException {
final Command command= new Command(commandOffset, commandLength, commandText, commandOwner);
if (intersects(command))
throw new BadLocationException();
final int index= Collections.binarySearch(fCommands, command);
// a command with exactly the same ranges exists already
if (index >= 0)
throw new BadLocationException();
// binary search result is defined as (-(insertionIndex) - 1)
final int insertionIndex= -(index + 1);
// overlaps to the right?
if (insertionIndex != fCommands.size() && intersects((Command) fCommands.get(insertionIndex), command))
throw new BadLocationException();
// overlaps to the left?
if (insertionIndex != 0 && intersects((Command) fCommands.get(insertionIndex - 1), command))
throw new BadLocationException();
fCommands.add(insertionIndex, command);
}