The Trunk: Collections-ar.287.mcz

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

The Trunk: Collections-ar.287.mcz

commits-2
Andreas Raab uploaded a new version of Collections to project The Trunk:
http://source.squeak.org/trunk/Collections-ar.287.mcz

==================== Summary ====================

Name: Collections-ar.287
Author: ar
Time: 1 February 2010, 7:16:54.576 pm
UUID: 3840f8bc-07e3-6f4c-a3d6-8b52f89973aa
Ancestors: Collections-edc.285, Collections-edc.286

Merge Collections-edc.286 with some changes:
- Implement both beginsWithAnyOf: as well as endsWithAnyOf:
- Push the implementation up to SequenceableCollection
- Simplify the implementation (using #anySatisfy:)
- Add comments (also in beginsWith: and endsWith:)
- Add tests


=============== Diff against Collections-edc.285 ===============

Item was changed:
  ----- Method: SequenceableCollection>>beginsWith: (in category 'testing') -----
  beginsWith: aSequenceableCollection
+ "Answer true if the receiver starts with the argument collection"
-
  (aSequenceableCollection isEmpty or: [self size < aSequenceableCollection size]) ifTrue: [^false].
  aSequenceableCollection withIndexDo: [:each :index | (self at: index) ~= each ifTrue: [^false]].
  ^true!

Item was changed:
  ----- Method: SequenceableCollection>>endsWith: (in category 'testing') -----
  endsWith: aSequenceableCollection
+ "Answer true if the receiver ends with the argument collection"
-
  | start |
  (aSequenceableCollection isEmpty or: [self size < aSequenceableCollection size]) ifTrue: [^false].
  start := self size - aSequenceableCollection size.
  aSequenceableCollection withIndexDo: [:each :index | (self at: start + index) ~= each ifTrue: [^false]].
  ^true!

Item was added:
+ ----- Method: SequenceableCollection>>endsWithAnyOf: (in category 'testing') -----
+ endsWithAnyOf: aCollection
+ "Return true if the receiver ends with any of the elements in aCollection."
+ ^aCollection anySatisfy:[:suffix| self endsWith: suffix].!

Item was added:
+ ----- Method: SequenceableCollection>>beginsWithAnyOf: (in category 'testing') -----
+ beginsWithAnyOf: aCollection
+ "Return true if the receiver starts with any of the elements in aCollection."
+ ^aCollection anySatisfy:[:prefix| self beginsWith: prefix].!

Item was removed:
- ----- Method: String>>beginsWithAnyOf: (in category 'comparing') -----
- beginsWithAnyOf: aCollection
- aCollection do:[:suffix|
- (self beginsWith: suffix) ifTrue:[^true].
- ].
- ^false!