Collection.st
changeset 936 9054edb471b3
parent 628 7aa563e4c64a
child 1112 0d8dd47d386a
--- a/Collection.st	Mon Feb 05 18:16:20 1996 +0100
+++ b/Collection.st	Tue Feb 06 17:29:57 1996 +0100
@@ -11,11 +11,11 @@
 "
 
 Object subclass:#Collection
-	 instanceVariableNames:''
-	 classVariableNames:'InvalidKeySignal EmptyCollectionSignal ValueNotFoundSignal
-                NotEnoughElementsSignal'
-	 poolDictionaries:''
-	 category:'Collections-Abstract'
+	instanceVariableNames:''
+	classVariableNames:'InvalidKeySignal EmptyCollectionSignal ValueNotFoundSignal
+		NotEnoughElementsSignal'
+	poolDictionaries:''
+	category:'Collections-Abstract'
 !
 
 !Collection class methodsFor:'documentation'!
@@ -210,6 +210,17 @@
     ^ self emptyCollectionError
 !
 
+firstIfEmpty:exceptionValue
+    "return the first element of the collection.
+     If its empty, return the excveptionValue.
+     (i.e. dont trigger an error as done in #first)"
+
+    self isEmpty ifTrue:[^ exceptionValue value].
+    ^ self first
+
+    "Modified: 6.2.1996 / 15:27:17 / cg"
+!
+
 last
     "return the last element of the collection.
      This should be redefined in subclasses."
@@ -226,6 +237,18 @@
     ^ self emptyCollectionError
 !
 
+lastIfEmpty:exceptionValue
+    "return the last element of the collection.
+     If its empty, return the exceptionValue.
+     (i.e. dont trigger an error as done in #last)"
+
+    self isEmpty ifTrue:[^ exceptionValue value].
+    ^ self last
+
+    "Modified: 6.2.1996 / 15:27:17 / cg"
+    "Created: 6.2.1996 / 15:27:49 / cg"
+!
+
 upTo:anElement
     "return a new collection consisting of the receivers elements upTo
      (but excluding) anElement.
@@ -1331,6 +1354,6 @@
 !Collection class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/Collection.st,v 1.44 1995-11-23 16:57:49 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/Collection.st,v 1.45 1996-02-06 16:29:57 cg Exp $'
 ! !
 Collection initialize!