home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 21 / AACD 21.iso / AACD / Programming / amigatalk / general / ArrayedCollection.st < prev    next >
Encoding:
Text File  |  2000-05-15  |  1.7 KB  |  77 lines

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