Interval.st
changeset 5672 bd82b2b8c930
parent 5557 f5f8d236027c
child 6132 615c4fe0f449
--- a/Interval.st	Tue Oct 24 14:19:39 2000 +0200
+++ b/Interval.st	Tue Oct 24 16:31:26 2000 +0200
@@ -80,6 +80,15 @@
     ^ self new setFrom:start to:stop by:step
 ! !
 
+!Interval class methodsFor:'converting'!
+
+decodeFromLiteralArray:anArray
+    "create & return a new instance from information encoded in anArray.
+     Re-redefined, since the implementation in SeqColl creates instances with an initial
+     size, which is not allowed for intevals."
+
+    ^ self new fromLiteralArrayEncoding:anArray.! !
+
 !Interval methodsFor:'accessing'!
 
 at:index
@@ -181,6 +190,39 @@
     self error:'elements cannot be removed from an interval'
 ! !
 
+!Interval methodsFor:'converting'!
+
+fromLiteralArrayEncoding:encoding
+    "read my values from an encoding.
+     The encoding is supposed to be either of the form: 
+        (#Interval start stop step)
+     This is the reverse operation to #literalArrayEncoding."
+
+    start := (encoding at:2).
+    stop := (encoding at:3). 
+    step := (encoding at:4).
+
+    "
+     Interval new fromLiteralArrayEncoding:((1 to:10) literalArrayEncoding)  
+     Interval new fromLiteralArrayEncoding:((1 to:10 by:2) literalArrayEncoding) 
+     Interval decodeFromLiteralArray:((1 to:10 by:2) literalArrayEncoding) 
+    "!
+
+literalArrayEncoding
+    "encode myself as an array literal, from which a copy of the receiver
+     can be reconstructed with #decodeAsLiteralArray."
+
+    ^ Array
+        with:self class name asSymbol
+        with:start
+        with:stop
+        with:step
+
+    "
+     (1 to:10) literalArrayEncoding      
+     (1 to:10 by:2) literalArrayEncoding
+    "! !
+
 !Interval methodsFor:'enumerating'!
 
 collect:aBlock
@@ -336,5 +378,5 @@
 !Interval class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/Interval.st,v 1.27 2000-08-22 13:56:51 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/Interval.st,v 1.28 2000-10-24 14:31:26 cg Exp $'
 ! !