[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Help-smalltalk] [PATCH] add equality methods
From: |
Paolo Bonzini |
Subject: |
[Help-smalltalk] [PATCH] add equality methods |
Date: |
Sat, 05 Apr 2008 14:54:25 -0000 |
It occurred to me that I had forgot equality methods. This patch
adds them at the end.
There are a lot of features that can be implemented:
- renames, for example using one of:
'src' asFile commit: [ :f | f extension: 'dest' ]
'src' asFile extension: 'dest'; commit
- moves, again using things like
'/tmp/blah' asFile commit: [ :f | f path: Directory working ]
- copies, like
Directory working add: '/tmp/blah' asFile
More ideas can be found at http://wiki.squeak.org/squeak/5929. I don't
agree with all of the ideas in that page, but for most of them I do.
I don't agree especially with "mode changes" -- I think that those
are best implemented using decorator objects in Smalltalk. But for
example having transparent gzip/gunzip access if one loads the ZLib
package would be nice.
Adding testcases would also be great, even though a normal `make
distcheck' already stresses quite a lot the system.
---
kernel/File.st | 14 ++++++++++++++
kernel/VFS.st | 29 +++++++++++++++++++++++++++++
2 files changed, 43 insertions(+), 0 deletions(-)
diff --git a/kernel/File.st b/kernel/File.st
index 1b77272..87a982c 100644
--- a/kernel/File.st
+++ b/kernel/File.st
@@ -186,6 +186,20 @@ FilePath subclass: File [
^self path: ImageFileName
]
+ = aFile [
+ "Answer whether the receiver represents the same file as the receiver."
+
+ <category: 'basic'>
+ ^self class == aFile class and: [ self asString = aFile asString ]
+ ]
+
+ hash [
+ "Answer a hash value for the receiver."
+
+ <category: 'basic'>
+ ^self asString hash
+ ]
+
lstatOn: fileName into: statStruct [
<category: 'private-C call-outs'>
<cCall: 'lstat_obj' returning: #int args: #(#string #smalltalk)>
diff --git a/kernel/VFS.st b/kernel/VFS.st
index 342f47e..b1ee48b 100644
--- a/kernel/VFS.st
+++ b/kernel/VFS.st
@@ -61,6 +61,20 @@ virtual files that refer to a real file on disk.'>
^self new file: file
]
+ = aFile [
+ "Answer whether the receiver represents the same file as the receiver."
+
+ <category: 'basic'>
+ ^self class == aFile class and: [ self file = aFile file ]
+ ]
+
+ hash [
+ "Answer a hash value for the receiver."
+
+ <category: 'basic'>
+ ^self file hash
+ ]
+
asString [
"Answer the container file containing me."
<category: 'accessing'>
@@ -464,6 +478,21 @@ FilePath subclass: ArchiveMember [
class for members of archive files that creates temporary files when
extracting files from an archive.'>
+ = aFile [
+ "Answer whether the receiver represents the same file as the receiver."
+
+ <category: 'basic'>
+ ^self class == aFile class and: [ self archive = aFile archive
+ and: [ self name = aFile name ] ]
+ ]
+
+ hash [
+ "Answer a hash value for the receiver."
+
+ <category: 'basic'>
+ ^self archive hash bitXor: self name hash
+ ]
+
archive: anArchiveFile [
"Set the archive of which the receiver is a member."
--
1.5.3.4.910.gc5122-dirty
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Help-smalltalk] [PATCH] add equality methods,
Paolo Bonzini <=