I'm in favor of PREVIOUS and NEXT with a required operand, and doing the wrapping, I'm not in favor of the optional flavor nor of the cursor operation.  Introducing a cursored-type iteration to this class is inconsistent with the other collection classes.  A cursored type iteration should be done as a secondary helper class, not by inserting a cursor position inside the collection itself.

Rick

On 5/22/06, Rony G. Flatscher <Rony.Flatscher@wu-wien.ac.at> wrote:
Hi there,

ad CircularQueue: because of its circular nature it would be natural, if one could iterate through the collected elements using NEXT and PREVIOUS, where the methods will wrap automatically if hitting the end/beginning of the circular queue.

This would allow for easily using circular queue objects to e.g. represent tab orders, where the next element may be wrapped if at the beginning or the end of the circular queue: no need in the programs anymore to test whether we are at the beginning or end of a circular queue, easying coding for these use cases considerably.

Therefore I would ask for feedback on the following additional methods:
  • NEXT( [index] )
    • Returns the element following the given index. If the index value refers to the last element in the circular queue or is larger than the available item objects, the first element of the circular queue will be returned. If the index is omitted, the next element following the CURSOR element in the circular queue is returned, starting over with the first element, if necessary.
    • The index value that NEXT uses if the index argument is omitted is stored in the attribute CURSOR.
    • Note: supplying an index value smaller than "1" or one that is larger than the number of items in the circular queue will cause the *first* element of the circular queue to be returned.
    • Note: sending this message to a circular queue that has no entries will return the ".NIL" object.
  • PREVIOUS( [index] )
    • Returns the element preceding the given index. If the index value refers to the first element in the circular queue or is smaller than "1", the last element of the circular queue will be returned. If the index is omitted, the element preceding the CURSOR element in the circular queue is returned, starting over with the last element, if necessary.
    • The index value that PREVIOUS uses if the index argument is omitted is stored in the attribute CURSOR.
    • Note: supplying an index value that is smaller than "1" or one that is larger than the number of item objects in the circular queue will cause the *last* element of the circular queue to be returned.
    • Note: sending this message to a circular queue that has no entries will return the ".NIL" object.
  • CURSOR
    • Returns the present index value from which NEXT and PREVIOUS will start out. Initially its value is set to "0" and will be adjusted accordingly by the methods NEXT and PREVIOUS.
What do you think?

If no one objects I would like to implement this (and create the according tests for the testUnit) by tomorrow evening, such that this funcitonality can be part of the beta drop.

---

Also another question/intention: the present STRING method does not work on a copy of the circular queue. Thinking about it, it may be possible that while the loop runs for creating the string representation, item objects may be deleted from the collection concurrently (the remove method is implemented in the superclass and can therefore run concurrently). So I would like to adjust the code accordingly. Comments appreciated as well.

Regards,

---rony