OrderedCollection.st
changeset 12036 4ce4157ce6a9
parent 12035 b927a2b293f8
child 14071 8e39d6128e1e
--- a/OrderedCollection.st	Mon Sep 28 15:19:34 2009 +0200
+++ b/OrderedCollection.st	Mon Sep 28 15:25:03 2009 +0200
@@ -1844,6 +1844,38 @@
     "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"
@@ -1923,5 +1955,5 @@
 !OrderedCollection class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/OrderedCollection.st,v 1.98 2009-09-28 13:19:34 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/OrderedCollection.st,v 1.99 2009-09-28 13:25:03 cg Exp $'
 ! !