LinkedList.st
changeset 17262 e7181a123eac
parent 17210 a43dc2b020bc
child 17272 46ac2aac776b
--- a/LinkedList.st	Tue Dec 30 00:52:52 2014 +0100
+++ b/LinkedList.st	Tue Dec 30 01:36:46 2014 +0100
@@ -11,6 +11,8 @@
 "
 "{ Package: 'stx:libbasic' }"
 
+"{ NameSpace: Smalltalk }"
+
 SequenceableCollection subclass:#LinkedList
 	instanceVariableNames:'firstLink lastLink numberOfNodes'
 	classVariableNames:''
@@ -170,6 +172,8 @@
 first
     "return the first node in the list"
 
+    self obsoleteFeatureWarning:'this will soon change to return the links value instead of the link itself'.
+
     firstLink isNil ifTrue:[^ self emptyCollectionError].
     ^ firstLink
 !
@@ -177,6 +181,22 @@
 firstIfEmpty:exceptionalValue
     "return the first node in the list or exceptionlValue, if empty"
 
+    self obsoleteFeatureWarning:'this will soon change to return the links value instead of the link itself'.
+
+    firstLink isNil ifTrue:[^ exceptionalValue value].
+    ^ firstLink
+!
+
+firstLink
+    "return the first node in the list"
+
+    firstLink isNil ifTrue:[^ self emptyCollectionError].
+    ^ firstLink
+!
+
+firstLinkIfEmpty:exceptionalValue
+    "return the first node in the list or exceptionlValue, if empty"
+
     firstLink isNil ifTrue:[^ exceptionalValue value].
     ^ firstLink
 !
@@ -184,37 +204,52 @@
 last
     "return last node in the list"
 
+    self obsoleteFeatureWarning:'this will soon change to return the links value instead of the link itself'.
+
+    lastLink isNil ifTrue:[self emptyCollectionError].
+    ^ lastLink
+!
+
+lastLink
+    "return last node in the list"
+
     lastLink isNil ifTrue:[self emptyCollectionError].
     ^ lastLink
 ! !
 
 !LinkedList methodsFor:'adding & removing'!
 
-add:aLink
+add:aLinkOrAnyOtherObject
     "adds aLink to the end of the sequence. Returns aLink"
 
-    aLink nextLink:nil.
+    |newLink|
+
+    newLink := aLinkOrAnyOtherObject asLink.
+    
+    newLink nextLink:nil.
     lastLink isNil ifTrue:[
-	firstLink := aLink
+        firstLink := newLink
     ] ifFalse: [
-	lastLink nextLink:aLink
+        lastLink nextLink:newLink
     ].
-    lastLink := aLink.
+    lastLink := newLink.
     numberOfNodes := numberOfNodes + 1.
-    ^ aLink
+    ^ newLink
 !
 
-add:linkToAdd after:aLink
+add:aLinkOrAnyOtherObject after:aLink
     "adds linkToAdd after another link, aLink. If aLink is nil,
      linkToAdd is inserted at the beginning. Returns linkToAdd."
 
-    |this|
+    |this linkToAdd|
 
-    aLink isNil ifTrue:[^ self addFirst:linkToAdd ].
+    aLink isNil ifTrue:[^ self addFirst:aLinkOrAnyOtherObject ].
+
+    linkToAdd := aLinkOrAnyOtherObject asLink.
 
     this := firstLink.
     [this notNil and:[this ~~ aLink]] whileTrue:[
-	this := this nextLink
+        this := this nextLink
     ].
     this isNil ifTrue:[^ self add:linkToAdd ].
     linkToAdd nextLink:(this nextLink).
@@ -223,16 +258,20 @@
     ^ linkToAdd
 !
 
-addFirst:aLink
+addFirst:aLinkOrAnyOtherObject
     "adds aLink to the beginning of the sequence. Returns aLink"
 
+    |linkToAdd|
+
+    linkToAdd := aLinkOrAnyOtherObject asLink.
+
     firstLink isNil ifTrue:[
-	lastLink := aLink.
+        lastLink := linkToAdd.
     ].
-    aLink nextLink:firstLink.
-    firstLink := aLink.
+    linkToAdd nextLink:firstLink.
+    firstLink := linkToAdd.
     numberOfNodes := numberOfNodes + 1.
-    ^ aLink
+    ^ linkToAdd
 !
 
 remove:aLink ifAbsent:exceptionBlock
@@ -439,10 +478,10 @@
 !LinkedList class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/LinkedList.st,v 1.45 2014-12-11 17:06:27 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/LinkedList.st,v 1.46 2014-12-30 00:36:46 cg Exp $'
 !
 
 version_CVS
-    ^ '$Header: /cvs/stx/stx/libbasic/LinkedList.st,v 1.45 2014-12-11 17:06:27 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/LinkedList.st,v 1.46 2014-12-30 00:36:46 cg Exp $'
 ! !