[Swift-devel] calling rmap

Ben Clifford benc at hawaga.org.uk
Mon Oct 1 05:19:29 CDT 2007


In the AbstractFileMapper subclasses, rmap to my intuition should be 
callable with the same filename multiple times; however, there are 
implementations like this (from FileSystemArrayMapper)

        public Path rmap(String name) {
                if (name == null || name.equals("")) {
                        return null;
                }
                String index = String.valueOf(count);
                filenames.put(index, name);
                Path p = Path.EMPTY_PATH;
                p = p.addFirst(index, true);
                ++count;
                return p;
        }

which look like they can't be called multiple times for the same filename 
without causing additions of multiple array elements mapped to the same 
file.

This works because rmap is indeed only called once, during invocation of 
the existing() method.

So there's a fairly restrictive set of conditions that seems a bit icky. 
For example, here's one rough approximation (I haven't checked them for 
being strictly true, but its close enough)

   i) a mapper must expect existing() to be called exactly once.
  ii) a mapper does not have to give correct mappings until after the 
      existing() call has been invoked.
 iii) rmap should not be called by anyone except the AbstractFileMapper 
      existing() implementation (despite its 'public' prototype)

I find the above three to be unintuitive as I attempt to document how to 
use AbstractFileMapper as a superclass of your own mappers.

-- 



More information about the Swift-devel mailing list