--- a/Coll.st Thu Nov 17 15:12:20 1994 +0100
+++ b/Coll.st Thu Nov 17 15:12:25 1994 +0100
@@ -21,7 +21,7 @@
COPYRIGHT (c) 1989 by Claus Gittinger
All Rights Reserved
-$Header: /cvs/stx/stx/libbasic/Attic/Coll.st,v 1.18 1994-10-28 01:21:17 claus Exp $
+$Header: /cvs/stx/stx/libbasic/Attic/Coll.st,v 1.19 1994-11-17 14:12:25 claus Exp $
'!
!Collection class methodsFor:'documentation'!
@@ -42,7 +42,7 @@
version
"
-$Header: /cvs/stx/stx/libbasic/Attic/Coll.st,v 1.18 1994-10-28 01:21:17 claus Exp $
+$Header: /cvs/stx/stx/libbasic/Attic/Coll.st,v 1.19 1994-11-17 14:12:25 claus Exp $
"
!
@@ -191,6 +191,28 @@
^ EmptyCollectionSignal raise
! !
+!Collection methodsFor:'copying'!
+
+copyEmpty:size
+ "return a copy of the receiver with no elements, but space for
+ size elements. This is used by copying and enumertion methods
+ to get a new instance which is similar to the receiver.
+ This method should be redefined in subclasses with instance
+ variables, which should be put into the copy too.
+ For example, SortedCollection has to copy its sortBlock into the
+ new collection."
+
+ ^ self species new:size
+!
+
+copyEmpty
+ "return a copy of the receiver with no elements.
+ This is used by copying and enumertion methods
+ to get a new instance which is similar to the receiver."
+
+ ^ self species new
+! !
+
!Collection methodsFor:'accessing'!
first
@@ -405,7 +427,7 @@
"return the number of occurrences of the argument, anElement in
the receiver"
- |count "<SmallInteger>" |
+ |count "{ Class: SmallInteger }" |
count := 0.
self do:[:element |
@@ -420,7 +442,7 @@
"return the number of elements in the receiver.
This is usually redefined in subclasses for more performance."
- |count "<SmallInteger>" |
+ |count "{ Class: SmallInteger }" |
count := 0.
self do:[:element |
@@ -511,8 +533,8 @@
|newCollection|
- newCollection := self species new postCopyFrom:self.
- self do:[:each | newCollection add:(aBlock value:each)].
+ newCollection := self species new.
+ self do:[:element | newCollection add:(aBlock value:element)].
^ newCollection
"
@@ -532,10 +554,11 @@
|index "{ Class: SmallInteger }"
newCollection|
- newCollection := self species new postCopyFrom:self.
+ newCollection := self species new.
index := 1.
self do:[:element |
- newCollection add:(aTwoArgBlock value:element value:(aSequenceableCollection at:index)).
+ newCollection add:(aTwoArgBlock value:element
+ value:(aSequenceableCollection at:index)).
index := index + 1
].
^ newCollection
@@ -609,7 +632,7 @@
|newCollection|
- newCollection := self species new postCopyFrom:self.
+ newCollection := self species new.
self do:[:each |
(aBlock value:each) ifTrue:[newCollection add:each].
].
@@ -651,7 +674,7 @@
"return a new Array with the collections elements"
|anArray
- index "<SmallInteger>" |
+ index "{ Class: SmallInteger }" |
anArray := Array new:(self size).
index := 1.
@@ -667,7 +690,7 @@
(which must convert to integers in the range 0..255)."
|aByteArray
- index "<SmallInteger>" |
+ index "{ Class: SmallInteger }" |
aByteArray := ByteArray new:(self size).
index := 1.
@@ -683,7 +706,7 @@
(which must convert to floats)."
|aFloatArray
- index "<SmallInteger>" |
+ index "{ Class: SmallInteger }" |
aFloatArray := FloatArray new:(self size).
index := 1.
@@ -699,7 +722,7 @@
(which must convert to floats)."
|aDoubleArray
- index "<SmallInteger>" |
+ index "{ Class: SmallInteger }" |
aDoubleArray := DoubleArray new:(self size).
index := 1.
@@ -715,7 +738,7 @@
(which must convert to characters)"
|aString
- index "<SmallInteger>" |
+ index "{ Class: SmallInteger }" |
aString := String new:(self size).
index := 1.
@@ -781,12 +804,41 @@
"return a stream for writing onto the receiver"
^ WriteStream on:self
+
+ "
+ |s|
+
+ s := #() copy writeStream.
+ s nextPut:1.
+ s nextPut:2.
+ s nextPut:3.
+ s contents inspect
+ "
+
+ "
+ |s|
+
+ s := OrderedCollection new writeStream.
+ s nextPut:1.
+ s nextPut:2.
+ s nextPut:3.
+ s contents inspect
+ "
!
readStream
"return a stream for reading from the receiver"
^ ReadStream on:self
+
+ "
+ |s|
+
+ s := 'hello world' readStream.
+ s next:5.
+ s next.
+ (s next:5) inspect
+ "
! !
!Collection methodsFor:'printing & storing'!