eXept Software AG Logo

Smalltalk/X Webserver

Documentation of class 'SequenceWithSentinel':

Home

Documentation
www.exept.de
Everywhere
for:
[back]

Class: SequenceWithSentinel


Inheritance:

   Object
   |
   +--Collection
      |
      +--SequenceableCollection
         |
         +--SequenceWithSentinel

Package:
stx:libbasic2
Category:
Collections-Sequenceable
Version:
rev: 1.2 date: 2013/06/25 11:23:55
user: cg
file: SequenceWithSentinel.st directory: libbasic2
module: stx stc-classLibrary: libbasic2

Description:


A collection with a default value for out-of-bounds accessed values.


Class protocol:

instance creation
o  new
(comment from inherited method)
return an instance of myself without indexed variables

o  on: aSequence sentinel: anObject
return a new collection based on aSequence but with invalid bounds-accesses returning abObject


Instance protocol:

accessing
o  at: anIndex
return the element at anIndex, or sentinel if the index is invalid

o  at: anIndex put: anObject
(comment from inherited method)
store the 2nd arg, anObject as indexed instvar with index, anInteger.
this method can be redefined in subclasses. Returns anObject (sigh)

o  size
answer my size

enumeration
o  do: aBlock
(comment from inherited method)
evaluate the argument, aBlock for every element in the collection in
sequence order.

growing
o  grow: howBig
(comment from inherited method)
change the receiver's size

private
o  sentinel: anObject
set the sentinel - the value returned for invalid indices

o  sequence: aSequence
set the underlying collection

o  sequence: aSequence sentinel: aSentinelValue
set the underlying collection and the sentinel (default)

testing
o  isFixedSize
return true if the receiver cannot grow


Examples:


    |coll|

    coll := SequenceWithSentinel on:#(10 20 30 40 50) sentinel:'invalid'.
    Transcript show:'1->'; showCR:(coll at:1).
    Transcript show:'5->'; showCR:(coll at:5).
    Transcript show:'6->'; showCR:(coll at:6).
    coll do:[:each | Transcript showCR:each].


ST/X 7.2.0.0; WebServer 1.670 at bd0aa1f87cdd.unknown:8081; Thu, 25 Apr 2024 13:39:28 GMT