Java: Swing: Structure: Cursors

# 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.

## Index representation changes

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.

### Insertion before the cursor

Cursor shifts by count of inserted items.

A B | C D (2)
A 1 2 B | C D (4)

### Insertion after the cursor

Cursor remains as is

A B | C D (2)
A B | C 1 2 D (2)

### Insertion at the cursor

Does cursor shift by one or not?

A B ? 1 2 ? C D (2 or 4?)

### Removal of items up to the cursor

Cursor decreased by count of removed items

A | C D (1)

### Removal of items at/after the cursor

Cursor remains as is

A B | D (2)

### Removal of items with a range over the cursor

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)

### Strong replacements

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)

### Weak range replacements

same, unless more information about the change

### Weak one-by-one replacements

Cursor remains as is

A 1 | 2 D (2)

### Index permutations

B ? D A ? C (1 or 3)

Was the cursor more "before C" or more "after B"?

## Cursors for ranges

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.

## Cursors with direction

## Inserting with direction

(C) 2001-2009 Christian Kaufhold (swing@chka.de)