SequenceableCollection.st
changeset 11879 e7d20a6e6719
parent 11878 dbc05293d160
child 11880 066c4971a69d
equal deleted inserted replaced
11878:dbc05293d160 11879:e7d20a6e6719
  1969      #[1 2 3 4] startsWithAnyOf:#( #(1 3) #(1 2))
  1969      #[1 2 3 4] startsWithAnyOf:#( #(1 3) #(1 2))
  1970     "
  1970     "
  1971 ! !
  1971 ! !
  1972 
  1972 
  1973 !SequenceableCollection methodsFor:'converting'!
  1973 !SequenceableCollection methodsFor:'converting'!
       
  1974 
       
  1975 asCollectionOfSubCollectionsOfSize:pieceSize
       
  1976     "return a collection containing pieces of size pieceSite from the receiver.
       
  1977      The last piece may be smaller, if the receivers size is not a multiple of pieceSize."
       
  1978 
       
  1979     |pieces
       
  1980      start  "{ Class:SmallInteger }"
       
  1981      stop   "{ Class:SmallInteger }"
       
  1982      mySize "{ Class:SmallInteger }"|
       
  1983 
       
  1984     pieces := OrderedCollection new.
       
  1985     start := 1. stop := start + pieceSize - 1.
       
  1986     mySize := self size.
       
  1987     [stop <= mySize] whileTrue:[
       
  1988         pieces add:(self copyFrom:start to:stop).
       
  1989         start := start + pieceSize.
       
  1990         stop := stop + pieceSize.
       
  1991     ].
       
  1992     (start <= mySize) ifTrue:[
       
  1993         pieces add:(self copyFrom:start to:mySize).
       
  1994     ].
       
  1995     ^ pieces
       
  1996 
       
  1997     "
       
  1998      '123123123123123123' asCollectionOfSubCollectionsOfSize:3
       
  1999      '12312312312312312312' asCollectionOfSubCollectionsOfSize:3 
       
  2000     "
       
  2001 !
  1974 
  2002 
  1975 asCollectionOfSubCollectionsSeparatedBy:anElement
  2003 asCollectionOfSubCollectionsSeparatedBy:anElement
  1976     "return a collection containing the subcollections (separated by anElement)
  2004     "return a collection containing the subcollections (separated by anElement)
  1977      of the receiver. If anElement occurs multiple times in a row,
  2005      of the receiver. If anElement occurs multiple times in a row,
  1978      the result will contain empty collections.
  2006      the result will contain empty collections.
  7596 ! !
  7624 ! !
  7597 
  7625 
  7598 !SequenceableCollection class methodsFor:'documentation'!
  7626 !SequenceableCollection class methodsFor:'documentation'!
  7599 
  7627 
  7600 version
  7628 version
  7601     ^ '$Header: /cvs/stx/stx/libbasic/SequenceableCollection.st,v 1.276 2009-08-27 11:35:28 cg Exp $'
  7629     ^ '$Header: /cvs/stx/stx/libbasic/SequenceableCollection.st,v 1.277 2009-08-27 12:28:53 cg Exp $'
  7602 ! !
  7630 ! !
  7603 
  7631 
  7604 SequenceableCollection initialize!
  7632 SequenceableCollection initialize!