Collection.st
changeset 936 9054edb471b3
parent 628 7aa563e4c64a
child 1112 0d8dd47d386a
equal deleted inserted replaced
935:4317f75fa478 936:9054edb471b3
     9  other person.  No title to or ownership of the software is
     9  other person.  No title to or ownership of the software is
    10  hereby transferred.
    10  hereby transferred.
    11 "
    11 "
    12 
    12 
    13 Object subclass:#Collection
    13 Object subclass:#Collection
    14 	 instanceVariableNames:''
    14 	instanceVariableNames:''
    15 	 classVariableNames:'InvalidKeySignal EmptyCollectionSignal ValueNotFoundSignal
    15 	classVariableNames:'InvalidKeySignal EmptyCollectionSignal ValueNotFoundSignal
    16                 NotEnoughElementsSignal'
    16 		NotEnoughElementsSignal'
    17 	 poolDictionaries:''
    17 	poolDictionaries:''
    18 	 category:'Collections-Abstract'
    18 	category:'Collections-Abstract'
    19 !
    19 !
    20 
    20 
    21 !Collection class methodsFor:'documentation'!
    21 !Collection class methodsFor:'documentation'!
    22 
    22 
    23 copyright
    23 copyright
   208 
   208 
   209     "error if collection is empty"
   209     "error if collection is empty"
   210     ^ self emptyCollectionError
   210     ^ self emptyCollectionError
   211 !
   211 !
   212 
   212 
       
   213 firstIfEmpty:exceptionValue
       
   214     "return the first element of the collection.
       
   215      If its empty, return the excveptionValue.
       
   216      (i.e. dont trigger an error as done in #first)"
       
   217 
       
   218     self isEmpty ifTrue:[^ exceptionValue value].
       
   219     ^ self first
       
   220 
       
   221     "Modified: 6.2.1996 / 15:27:17 / cg"
       
   222 !
       
   223 
   213 last
   224 last
   214     "return the last element of the collection.
   225     "return the last element of the collection.
   215      This should be redefined in subclasses."
   226      This should be redefined in subclasses."
   216 
   227 
   217     |theLastOne any|
   228     |theLastOne any|
   222 	^ theLastOne
   233 	^ theLastOne
   223     ].
   234     ].
   224 
   235 
   225     "error if collection is empty"
   236     "error if collection is empty"
   226     ^ self emptyCollectionError
   237     ^ self emptyCollectionError
       
   238 !
       
   239 
       
   240 lastIfEmpty:exceptionValue
       
   241     "return the last element of the collection.
       
   242      If its empty, return the exceptionValue.
       
   243      (i.e. dont trigger an error as done in #last)"
       
   244 
       
   245     self isEmpty ifTrue:[^ exceptionValue value].
       
   246     ^ self last
       
   247 
       
   248     "Modified: 6.2.1996 / 15:27:17 / cg"
       
   249     "Created: 6.2.1996 / 15:27:49 / cg"
   227 !
   250 !
   228 
   251 
   229 upTo:anElement
   252 upTo:anElement
   230     "return a new collection consisting of the receivers elements upTo
   253     "return a new collection consisting of the receivers elements upTo
   231      (but excluding) anElement.
   254      (but excluding) anElement.
  1329 ! !
  1352 ! !
  1330 
  1353 
  1331 !Collection class methodsFor:'documentation'!
  1354 !Collection class methodsFor:'documentation'!
  1332 
  1355 
  1333 version
  1356 version
  1334     ^ '$Header: /cvs/stx/stx/libbasic/Collection.st,v 1.44 1995-11-23 16:57:49 cg Exp $'
  1357     ^ '$Header: /cvs/stx/stx/libbasic/Collection.st,v 1.45 1996-02-06 16:29:57 cg Exp $'
  1335 ! !
  1358 ! !
  1336 Collection initialize!
  1359 Collection initialize!