Andreas Raab uploaded a new version of Collections to project The Trunk:
http://source.squeak.org/trunk/Collections-ar.318.mcz ==================== Summary ==================== Name: Collections-ar.318 Author: ar Time: 25 February 2010, 2:56:24.321 pm UUID: 8f0ad3d5-ed2f-2a4b-b453-b1f97d8fbf2c Ancestors: Collections-ul.317 Introducing NullStream - a generator and consumer of an infinite number of elements just like /dev/null. Useful for testing and benchmarks. =============== Diff against Collections-ul.317 =============== Item was added: + ----- Method: NullStream>>reset (in category 'positioning') ----- + reset + "Set the receiver's position to the beginning of the sequence of objects." + + position := 0! Item was added: + ----- Method: NullStream>>collectionSpecies (in category 'accessing') ----- + collectionSpecies + "The type of collection returned by the stream" + + ^binary ifTrue:[ByteArray] ifFalse:[ByteString]! Item was added: + ----- Method: NullStream>>peek (in category 'writing') ----- + peek + "Answer what would be returned if the message next were sent to the + receiver. If the receiver is at the end, answer nil." + + ^self element! Item was added: + ----- Method: NullStream>>element (in category 'accessing') ----- + element + "The element returned by the stream" + + ^binary ifTrue:[0] ifFalse:[Character value: 0]! Item was added: + ----- Method: NullStream>>ascii (in category 'accessing') ----- + ascii + "Switches the stream to ascii mode" + + binary := false.! Item was added: + ----- Method: NullStream>>nextInto:startingAt: (in category 'reading') ----- + nextInto: aCollection startingAt: startIndex + "Read the next elements of the receiver into aCollection. + Return aCollection or a partial copy if less than aCollection + size elements have been read." + + ^self next: (aCollection size - startIndex+1) into: aCollection startingAt: startIndex.! Item was added: + ----- Method: NullStream>>next:putAll: (in category 'writing') ----- + next: anInteger putAll: aCollection + "Store the next anInteger elements from the given collection." + + ^self next: anInteger putAll: aCollection startingAt: 1! Item was added: + ----- Method: NullStream>>nextInto: (in category 'reading') ----- + nextInto: aCollection + "Read the next elements of the receiver into aCollection. + Return aCollection or a partial copy if less than aCollection + size elements have been read." + + ^self next: aCollection size into: aCollection startingAt: 1.! Item was added: + ----- Method: NullStream>>next: (in category 'reading') ----- + next: anInteger + "Answer the next anInteger elements of my collection. Must override + because default uses self contents species, which might involve a large + collection." + + position := position +anInteger. + ^self collectionSpecies new: anInteger! Item was added: + ----- Method: NullStream>>position: (in category 'positioning') ----- + position: anInteger + "Set the current position for accessing the objects to be anInteger, as long + as anInteger is within the bounds of the receiver's contents. If it is not, + create an error notification." + + (anInteger >= 0) + ifTrue: [position := anInteger] + ifFalse: [self positionError]! Item was added: + ----- Method: NullStream>>nextPut: (in category 'writing') ----- + nextPut: anObject + "Insert the argument, anObject, as the next object accessible by the + receiver. Answer anObject." + + position := position +1. + ^anObject! Item was added: + ----- Method: NullStream>>skip: (in category 'positioning') ----- + skip: anInteger + "Set the receiver's position to be the current position+anInteger. A + subclass might choose to be more helpful and select the minimum of the + receiver's size and position+anInteger, or the maximum of 1 and + position+anInteger for the repositioning." + + self position: position + anInteger! Item was added: + ----- Method: NullStream>>next:into:startingAt: (in category 'reading') ----- + next: n into: aCollection startingAt: startIndex + "Read n objects into the given collection. + Return aCollection or a partial copy if less than + n elements have been read." + + position := position +n. + ^aCollection! Item was added: + ----- Method: NullStream>>isEmpty (in category 'testing') ----- + isEmpty + "Answer whether the receiver's contents has no elements." + + ^false + ! Item was added: + ----- Method: NullStream>>next:putAll:startingAt: (in category 'writing') ----- + next: anInteger putAll: aCollection startingAt: startIndex + "Store the next anInteger elements from the given collection." + + position := position + anInteger. + ^aCollection! Item was added: + ----- Method: NullStream>>binary (in category 'accessing') ----- + binary + "Switches the stream to binary mode" + + binary := true! Item was added: + ----- Method: NullStream>>initialize (in category 'initialize') ----- + initialize + "Initialize the receiver" + + binary := false. + position := 0.! Item was added: + ----- Method: NullStream>>next:into: (in category 'reading') ----- + next: n into: aCollection + "Read n objects into the given collection. + Return aCollection or a partial copy if less than + n elements have been read." + + ^self next: n into: aCollection startingAt: 1! Item was added: + Stream subclass: #NullStream + instanceVariableNames: 'binary position' + classVariableNames: '' + poolDictionaries: '' + category: 'Collections-Streams'! + + !NullStream commentStamp: 'ar 2/25/2010 14:49' prior: 0! + NullStream is a stream generating and consuming an infinite number of elements. It can be used as an equivalent of /dev/null or for performance benchmarks.! Item was added: + ----- Method: NullStream>>contents (in category 'accessing') ----- + contents + "Answer all of the contents of the receiver." + + self shouldNotImplement! Item was added: + ----- Method: NullStream>>nextPutAll: (in category 'writing') ----- + nextPutAll: aCollection + "Append the elements of aCollection to the sequence of objects accessible + by the receiver. Answer aCollection." + + position := position + aCollection size. + ^aCollection! Item was added: + ----- Method: NullStream>>atEnd (in category 'testing') ----- + atEnd + "Answer whether the receiver can access any more objects." + + ^false! Item was added: + ----- Method: NullStream>>isBinary (in category 'testing') ----- + isBinary + "Return true if the receiver is a binary byte stream" + + ^binary! Item was added: + ----- Method: NullStream classSide>>new (in category 'instance creation') ----- + new + "Creates a new instance" + + ^self basicNew initialize! Item was added: + ----- Method: NullStream>>next (in category 'reading') ----- + next + "Answer the next object accessible by the receiver." + + position := position +1. + ^self element! Item was added: + ----- Method: NullStream>>position (in category 'positioning') ----- + position + "Answer the current position of accessing the sequence of objects." + + ^position! |
Free forum by Nabble | Edit this page |