As for the HashSet, I cant see how that will speed the search up. Binary search on an ordered or sorted list is the fastest. A binary search requires log n time; a HashSet uses constant time (on average). For very small n the binary search is probably faster; as n increases the HashSet will be superior. I have little idea where the break-even point is, without
testing - probably the number of keywords is not that great anyway, and so it doesn't matter much in this case.
As for the formating - I like the idea about Stringbuffer - except that there is a limit to capacity (255) Where did this idea come from? I know of no such limit, and have certainly made StringBuffers bigger than 255.
Note that if you like the array of StringBuffers idea, you probably will want a LinkedList rather than an array, as it will be much simpler to insert and delete within the list. Note that the Document model also offers a way of storing the content being edited. Since you apparently
need to use StyledDocument in order to color the text (unless there's another way), there may be little point in
also creating the List of StringBuffers. You can access the contents of the Document just as well, I think.
When the user types a " or /*, I think first you want to know if the text at that point was already part of a quote or comment. If you've been successfully, reliably parsing all edits as they are made, you can just look at the color of the current position; otherwise you'll have to start back somewhere earlier (a "last known normal text section") and parse forward from there. For a ", you'll also want to know if the preceding character was a \. Anyway, from all this, you can determine whether the effecto fo the " or /* was to "activate" quote or comment mode in subsequent text, or to turn it off. Scan forward from there to find the end of the affected section. For quotes, you usually will need to recolor everything up to the next line break. Any subsequent " encountered will flip states between quote and non-quote. A /* in non-quote mode will mean you can stop scanning forward, as will a newline. For /*, scan forward until you find either the */ which closes it, or another /*, indicating subsequent text is already in comment mode.
OK, I'm sure I missed some stuff there, or just plain got it wrong, but that's at least a general way to approach the problem. Enjoy.
[ March 01, 2002: Message edited by: Jim Yingst ]