--- a/OrderedCollection.st Fri Aug 28 12:38:51 2009 +0100
+++ b/OrderedCollection.st Sat Oct 24 16:48:19 2009 +0100
@@ -593,20 +593,19 @@
|index retVal|
- index := contentsArray indexOf:anObject startingAt:firstIndex endingAt:lastIndex.
+ index := self indexOf:anObject.
index ~~ 0 ifTrue:[
- retVal := contentsArray at:index.
- index := index - firstIndex + 1.
+ retVal := contentsArray at:index+firstIndex-1.
self removeFromIndex:index toIndex:index.
^ retVal
].
^ exceptionBlock value
"
- #(1 2 3 4 5) asOrderedCollection remove:9 ifAbsent:[self halt]
- #(1 2 3 4 5) asOrderedCollection remove:3 ifAbsent:[self halt]
+ #(1 2 3 4 5) asOrderedCollection remove:9 ifAbsent:[self halt]; yourself
+ #(1 2 3 4 5) asOrderedCollection remove:3 ifAbsent:[self halt]; yourself
- #(1 2 3 4 5 6 7 8 9) asOrderedCollection remove:3 ifAbsent:'oops'
+ #(1 2 3 4 5 6 7 8 9) asOrderedCollection remove:3 ifAbsent:'oops'
#(1 2 3 4 5) asOrderedCollection remove:9 ifAbsent:'oops'
#(1.0 2.0 3.0 4.0 5.0) asOrderedCollection remove:4 ifAbsent:'oops'
#(1.0 2.0 3.0 4.0 5.0) asOrderedCollection removeIdentical:4 ifAbsent:'oops'
@@ -1830,13 +1829,53 @@
|c|
c := OrderedCollection new:10000.
- c add:1; add:2; add:3.
+ c add:10; add:20; add:30.
c indexOf:99
"
+ "
+ |c|
+
+ c := OrderedCollection new:10000.
+ c add:10; add:20; add:30.
+ c indexOf:30
+ "
+
"Modified: 12.4.1996 / 17:57:54 / cg"
!
+indexOf:anObject ifAbsent:exceptionValue
+ "return the index of anObject or 0 if not found in the collection.
+ Compare using =
+ If the receiver does not contain anElement,
+ return the result of evaluating the argument, exceptionBlock."
+
+ |index|
+
+ index := contentsArray
+ indexOf:anObject
+ startingAt:firstIndex
+ endingAt:lastIndex.
+ index == 0 ifTrue:[^ exceptionValue value].
+ ^ index - firstIndex + 1
+
+ "
+ |c|
+
+ c := OrderedCollection new:10000.
+ c add:10; add:20; add:30.
+ c indexOf:99 ifAbsent:'nope'
+ "
+
+ "
+ |c|
+
+ c := OrderedCollection new:10000.
+ c add:10; add:20; add:30.
+ c indexOf:30 ifAbsent:'nope'
+ "
+!
+
indexOf:anObject startingAt:startIndex
"return the index of anObject, starting search at startIndex.
Compare using =; return 0 if not found in the collection"
@@ -1916,5 +1955,6 @@
!OrderedCollection class methodsFor:'documentation'!
version
- ^ '$Id: OrderedCollection.st 10447 2009-06-14 13:09:55Z vranyj1 $'
+ ^ '$Id: OrderedCollection.st 10473 2009-10-24 15:48:19Z vranyj1 $'
! !
+