OrderedCollection.st
changeset 12036 4ce4157ce6a9
parent 12035 b927a2b293f8
child 14071 8e39d6128e1e
equal deleted inserted replaced
12035:b927a2b293f8 12036:4ce4157ce6a9
  1842     "
  1842     "
  1843 
  1843 
  1844     "Modified: 12.4.1996 / 17:57:54 / cg"
  1844     "Modified: 12.4.1996 / 17:57:54 / cg"
  1845 !
  1845 !
  1846 
  1846 
       
  1847 indexOf:anObject ifAbsent:exceptionValue
       
  1848     "return the index of anObject or 0 if not found in the collection.
       
  1849      Compare using =
       
  1850      If the receiver does not contain anElement,
       
  1851      return the result of evaluating the argument, exceptionBlock."
       
  1852 
       
  1853     |index|
       
  1854 
       
  1855     index := contentsArray 
       
  1856                 indexOf:anObject 
       
  1857                 startingAt:firstIndex
       
  1858                 endingAt:lastIndex.
       
  1859     index == 0 ifTrue:[^ exceptionValue value].
       
  1860     ^ index - firstIndex + 1
       
  1861 
       
  1862     "
       
  1863      |c|
       
  1864 
       
  1865      c := OrderedCollection new:10000.
       
  1866      c add:10; add:20; add:30.
       
  1867      c indexOf:99 ifAbsent:'nope' 
       
  1868     "
       
  1869 
       
  1870     "
       
  1871      |c|
       
  1872 
       
  1873      c := OrderedCollection new:10000.
       
  1874      c add:10; add:20; add:30.
       
  1875      c indexOf:30 ifAbsent:'nope'  
       
  1876     "
       
  1877 !
       
  1878 
  1847 indexOf:anObject startingAt:startIndex
  1879 indexOf:anObject startingAt:startIndex
  1848     "return the index of anObject, starting search at startIndex.
  1880     "return the index of anObject, starting search at startIndex.
  1849      Compare using =; return 0 if not found in the collection"
  1881      Compare using =; return 0 if not found in the collection"
  1850 
  1882 
  1851     |index|
  1883     |index|
  1921 ! !
  1953 ! !
  1922 
  1954 
  1923 !OrderedCollection class methodsFor:'documentation'!
  1955 !OrderedCollection class methodsFor:'documentation'!
  1924 
  1956 
  1925 version
  1957 version
  1926     ^ '$Header: /cvs/stx/stx/libbasic/OrderedCollection.st,v 1.98 2009-09-28 13:19:34 cg Exp $'
  1958     ^ '$Header: /cvs/stx/stx/libbasic/OrderedCollection.st,v 1.99 2009-09-28 13:25:03 cg Exp $'
  1927 ! !
  1959 ! !