Java: Swing: Structure: Cursors
A cursor points to a location between two indices of a list, or to its the beginning/end.
A B | C D | A B C D A B C D |
Cursors may be represented by the index that (would) follow(s) them (i.e. the list's size at the end), this is sensible because it limits the range of cursors from zero to the list's size (and not -1, which is typically used to denote an invalid/non-existing index.
The argument to a list's add(index, item(s)) maybe regarded as a cursor: the item(s) is/are inserted between two items; or at the beginning/end.
If the list is modified, the cursor should remain logically at the same position. Often, this means the index used for representation will change.
The cursor changes in the following mean the index representation changes.
Cursor shifts by count of inserted items.
A B | C D (2) A 1 2 B | C D (4)
Cursor remains as is
A B | C D (2) A B | C 1 2 D (2)
Does cursor shift by one or not?
A B ? 1 2 ? C D (2 or 4?)
Cursor decreased by count of removed items
A | C D (1)
Cursor remains as is
A B | D (2)
Cursor moves to beginning=end of the removed region, i.e. is decreased by the number of items that were before it
A | D (1)
Does cursor move to the beginning or end?
A ? 1 2 ? D (1 or 3?)
(strong replacements are in this aspect equivalent to an removal/insertion or insertion/removal sequence)
same, unless more information about the change
Cursor remains as is
A 1 | 2 D (2)
B ? D A ? C (1 or 3)
Was the cursor more "before C" or more "after B"?
Two cursors may be used to denote a range. In fact, this is equivalent to the "from - to" (from inclusive, to exclusive) "index" way of denoting a range, and from and to maybe regarded as cursors instead of indices.
A | B C | D (range: B C) A B || C D (range: empty)
These cursors have the same problems with insertings/replacements as above (i.e. do insertions at the beginning or end of the range become part of the range or not?). With permutations, the notion of the range may not make sense at all.
Special case: A range that has become empty will never become non-empty.
(C) 2001-2009 Christian Kaufhold (swing@chka.de)