Skip to content

Commit

Permalink
Merge pull request #56 from mumez/develop
Browse files Browse the repository at this point in the history
Added RsStream>>#iterator and #reverseIteraror for supporting easiler iteration
  • Loading branch information
mumez authored Oct 4, 2024
2 parents 8cb2fce + b02faa1 commit 6397285
Show file tree
Hide file tree
Showing 21 changed files with 104 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
tests
testDoWithoutFrom
| strm one two three four five ite1 entries1 ite2 entries2 |
strm := self newStreamNamed: 'testDoWithoutFrom'.
strm trimTo: 0.
self assert: strm length equals: 0.
one := 'one' -> '1'.
two := 'two' -> '2'.
three := 'three' -> '3'.
four := 'four' -> '4'.
five := 'five' -> '5'.
strm << one << two << three << four << five.
ite1 := strm iterator.
entries1 := OrderedCollection new.
ite1 do: [ :each | entries1 add: each ].
self assert: entries1 size equals: 5.
self assert: entries1 first content equals: one.
self assert: entries1 second content equals: two.
self assert: entries1 last content equals: five.
ite2 := strm iterator.
entries2 := ite2 collect: [ :each | each ].
self assert: entries2 size equals: 5.
self assert: entries2 first content equals: one.
self assert: entries2 last content equals: five.
strm trimTo: 0.
self assert: strm length equals: 0.
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
tests
testReverseDoWithoutFrom
| strm one two three four five ite1 entries1 ite2 entries2 |
strm := self newStreamNamed: 'testReverseDoWithoutFrom'.
strm trimTo: 0.
self assert: strm length equals: 0.
one := 'one' -> '1'.
two := 'two' -> '2'.
three := 'three' -> '3'.
four := 'four' -> '4'.
five := 'five' -> '5'.
strm << one << two << three << four << five.
ite1 := strm reverseIterator.
entries1 := OrderedCollection new.
ite1 do: [ :each | entries1 add: each ].
self assert: entries1 size equals: 5.
self assert: entries1 first content equals: five.
self assert: entries1 second content equals: four.
self assert: entries1 last content equals: one.
ite2 := strm reverseIterator.
entries2 := ite2 collect: [ :each | each ].
self assert: entries2 size equals: 5.
self assert: entries2 first content equals: five.
self assert: entries2 last content equals: one.
strm trimTo: 0.
self assert: strm length equals: 0.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
iterating
iterator
^ self iteratorClass on: self
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
iterating
reverseIterator
^ self iterator reversed
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
instance creation
on: aRsStream from: fromId
^ (self on: aRsStream)
initFromId: fromId;
yourself
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
instance creation
on: aRsStream nextFrom: fromId
^ (self on: aRsStream) initFromId: fromId
^ (self on: aRsStream)
initFromId: fromId;
initCurrentId: fromId;
yourself
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
accessing
basicCurrentId
^ currentId
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
actions
by: step do: aBlock whileFalse: endConditionBlock
| entries |
entries := self contentsNextFrom: self currentId count: step.
entries := self entriesFrom: self currentId count: step.
entries do: [ :each |
aBlock value: each.
self currentId: each id ].
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
private
contentsFrom: entryId count: step
^ self stream contentsFrom: entryId count: step
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
accessing
currentId

^ currentId
currentId ifNil: [ ^ self fallbackId ].
^ currentId
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
private
entriesFrom: entryId count: step
self isInclusive ifTrue: [ ^ self contentsFrom: entryId count: step ].
^ self contentsNextFrom: entryId count: step
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
private
fallbackId
^ self stream first id
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
initialization
initCurrentId: fromIdLikeThing
currentId := fromIdLikeThing ifNotNil: [ fromIdLikeThing asStreamMessageId ].
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
initialization
initFromId: fromIdLikeThing
fromId := fromIdLikeThing
ifNil: [ RsStreamMessageId zero ]
ifNotNil: [ fromIdLikeThing asStreamMessageId ].
currentId := fromId
fromId := fromIdLikeThing ifNotNil: [ fromIdLikeThing asStreamMessageId ].
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
accessing
isInclusive: aBoolean
isInclusive := aBoolean
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
testing
isInclusive
isInclusive ifNil: [ ^ currentId isNil ].
^ isInclusive
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
converting
reversed
^ RsStreamReverseIterator on: self stream nextFrom: self currentId
^ RsStreamReverseIterator on: self stream nextFrom: self basicCurrentId
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"name",
"stream",
"fromId",
"currentId"
"currentId",
"isInclusive"
],
"name" : "RsStreamIterator",
"type" : "normal"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
private
contentsFrom: entryId count: step
^ self stream contentsReversedFrom: entryId count: step
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
private
fallbackId
^ self stream last id
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
converting
reversed
^ RsStreamIterator on: self stream nextFrom: self currentId
^ RsStreamIterator on: self stream nextFrom: self basicCurrentId

0 comments on commit 6397285

Please sign in to comment.