Queue.st
changeset 4067 b462a3ff3a61
parent 4064 24ce8feaa923
child 4151 32fdabb21a15
--- a/Queue.st	Wed Sep 07 15:27:45 2016 +0200
+++ b/Queue.st	Wed Sep 07 15:40:23 2016 +0200
@@ -192,99 +192,6 @@
     "
 !
 
-next
-    "return the next value in the queue;
-     Return nil, if the queue is empty.
-     WARNING: this is an old behavior, which should be changed
-     to raise an error if empty.
-     It is left in here until all queue-users have been changed to
-     call nextOrNil instead, to avoid breaking existing applications."
-
-    ^ self nextOrNil
-!
-
-nextOrNil
-    "return the next value in the queue;
-     Return nil, if the queue is empty"
-
-    |value pos "{ Class: SmallInteger }"|
-
-    (tally == 0) ifTrue:[^ nil].
-
-    pos := readPosition.
-
-    value := contentsArray at:pos.
-    contentsArray at:pos put:nil.       "/ to help the garbage collector
-    pos := pos + 1.
-    pos > contentsArray size ifTrue:[pos := 1].
-    readPosition := pos.
-    tally := tally - 1.
-    ^ value
-!
-
-nextPut:anObject
-    "enter anObject into the queue - if the queue is full, report an error"
-
-    |sz pos "{ Class: SmallInteger }" |
-
-    sz := contentsArray size.
-    pos := writePosition.
-
-    (tally == sz) ifTrue:[
-        self error:'queue is full' mayProceed:true.
-        ^ self
-    ].
-
-    contentsArray at:pos put:anObject.
-    pos := pos + 1.
-    pos > sz ifTrue:[pos := 1].
-    writePosition := pos.
-    tally := tally + 1.
-!
-
-nextPutAll:aCollection
-    "enter all elements from aCollection into the queue."
-
-    aCollection do:[:element | self nextPut:element]
-!
-
-nextPutFirst:anObject
-    |sz pos "{ Class: SmallInteger }" |
-
-    tally == 0 ifTrue:[
-        self nextPut:anObject.
-        ^ self
-    ].
-
-    sz := contentsArray size.
-    (tally == sz) ifTrue:[
-        self error:'queue is full' mayProceed:true.
-        ^ self
-    ].
-    pos := readPosition - 1.
-    pos < 1 ifTrue:[pos := sz].
-    contentsArray at:pos put:anObject.
-    readPosition := pos.
-
-    tally := tally + 1
-!
-
-peek
-    "return the next value in the queue without removing it.
-     If the queue is empty, return nil."
-
-    (tally == 0) ifTrue:[^ nil].
-    ^ contentsArray at:readPosition.
-!
-
-peekOrNil
-    "return the next value in the queue without removing it.
-     If the queue is empty, return nil."
-
-    (tally == 0) ifTrue:[^ nil].
-    ^ contentsArray at:readPosition.
-!
-
 removeAll
     "remove all elements in the queue; return the receiver"
 
@@ -443,6 +350,105 @@
     "Created: / 27.8.1998 / 11:15:48 / cg"
 ! !
 
+!Queue methodsFor:'accessing-reading'!
+
+next
+    "return the next value in the queue;
+     Return nil, if the queue is empty.
+     WARNING: this is an old behavior, which should be changed
+     to raise an error if empty.
+     It is left in here until all queue-users have been changed to
+     call nextOrNil instead, to avoid breaking existing applications."
+
+    ^ self nextOrNil
+!
+
+nextOrNil
+    "return the next value in the queue;
+     Return nil, if the queue is empty"
+
+    |value pos "{ Class: SmallInteger }"|
+
+    (tally == 0) ifTrue:[^ nil].
+
+    pos := readPosition.
+
+    value := contentsArray at:pos.
+    contentsArray at:pos put:nil.       "/ to help the garbage collector
+    pos := pos + 1.
+    pos > contentsArray size ifTrue:[pos := 1].
+    readPosition := pos.
+    tally := tally - 1.
+    ^ value
+!
+
+peek
+    "return the next value in the queue without removing it.
+     If the queue is empty, return nil."
+
+    (tally == 0) ifTrue:[^ nil].
+    ^ contentsArray at:readPosition.
+!
+
+peekOrNil
+    "return the next value in the queue without removing it.
+     If the queue is empty, return nil."
+
+    (tally == 0) ifTrue:[^ nil].
+    ^ contentsArray at:readPosition.
+! !
+
+!Queue methodsFor:'accessing-writing'!
+
+nextPut:anObject
+    "enter anObject into the queue - if the queue is full, report an error"
+
+    |sz pos "{ Class: SmallInteger }" |
+
+    sz := contentsArray size.
+    pos := writePosition.
+
+    (tally == sz) ifTrue:[
+        self error:'queue is full' mayProceed:true.
+        ^ self
+    ].
+
+    contentsArray at:pos put:anObject.
+    pos := pos + 1.
+    pos > sz ifTrue:[pos := 1].
+    writePosition := pos.
+    tally := tally + 1.
+    ^ self.
+!
+
+nextPutAll:aCollection
+    "enter all elements from aCollection into the queue."
+
+    aCollection do:[:element | self nextPut:element].
+    ^ self
+!
+
+nextPutFirst:anObject
+    |sz pos "{ Class: SmallInteger }" |
+
+    tally == 0 ifTrue:[
+        self nextPut:anObject.
+        ^ self
+    ].
+
+    sz := contentsArray size.
+    (tally == sz) ifTrue:[
+        self error:'queue is full' mayProceed:true.
+        ^ self
+    ].
+    pos := readPosition - 1.
+    pos < 1 ifTrue:[pos := sz].
+    contentsArray at:pos put:anObject.
+    readPosition := pos.
+
+    tally := tally + 1
+! !
+
 !Queue methodsFor:'enumerating'!
 
 do:aBlock