home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 018.lha / prelude / acollection.st < prev    next >
Text File  |  1986-10-19  |  2KB  |  71 lines

  1. Class ArrayedCollection :SequenceableCollection
  2. | current |
  3. [
  4.        = anArray                       | i |
  5.                 (self size ~= anArray size) ifTrue: [^ false].
  6.                 i <- 0.
  7.                 self do: [:x | (x ~= (anArray at: (i <- i + 1)))
  8.                                 ifTrue: [^ false]].
  9.         ^ true
  10. |
  11.         at: key ifAbsent: exceptionBlock
  12.         ((key <= 0) or: [key > self size])
  13.             ifTrue: [^ exceptionBlock value].
  14.                 ^ self at: key
  15. |
  16.     coerce: aCollection        | temp |
  17.         temp <- self class new: aCollection size.
  18.         temp replaceFrom: 1 to: aCollection size with: aCollection.
  19.         ^ temp
  20. |
  21.        copyFrom: start to: stop                | size temp |
  22.         size <- stop - start + 1.
  23.         temp <- self class new: size.
  24.         temp replaceFrom: 1 to: size with: self startingAt: start.
  25.         ^ temp
  26. |
  27.         currentKey
  28.                 ^ current
  29.     deepCopy        | newobj |
  30.         newobj <- self class new: self size.
  31.         (1 to: self size) do:
  32.             [:i | newobj at: i
  33.                 put: (self at: i) copy ].
  34.         ^ newobj
  35. |
  36.        do: aBlock
  37.                 (1 to: self size) 
  38.             do: [:i | current <- i. 
  39.                 aBlock value: (self at: i)]
  40. |
  41.        first
  42.                 current <- 1.
  43.                 ^ (current <= self size) 
  44.             ifTrue: [ self at: current]
  45. |
  46.     firstKey
  47.         ^ 1
  48. |
  49.     lastKey
  50.         ^ self size
  51. |
  52.     next
  53.                 current <- current + 1.
  54.                 ^ (current <= self size) 
  55.             ifTrue: [ self at: current]
  56. |
  57.     padTo: length
  58.         ^ (self size < length)
  59.             ifTrue: [ self , 
  60.                 (self class new: (length - self size) ) ]
  61.             ifFalse: [ self ]
  62. |
  63.     shallowCopy        | newobj |
  64.         newobj <- self class new: self size.
  65.         (1 to: self size) do:
  66.             [:i | newobj at: i 
  67.                 put: (self at: i) ].
  68.         ^ newobj
  69. ]
  70.