2

I am trying to figure out how I could make something that looks like a folder file structure for a Java shell I am trying to make. I want it to resemble something like the linux folder structure (having a root and all decending from it).

For starters I am wonder if I should use a TreeMap (so some type of order is maintained) or if there is something better. I know Java's API is vast and has many different data structures I am just not sure which would be appropriate.

The other issue would be navigating between the "directories". The basic concept I have is something on the lines of using a variable as a "landmark" that would change depending on where I am moving to or from.

The folders in the tree would be "server" objects (a server.class) created by the root (the main.class) which in turn have "application" objects (application.class) created by a method in the server object.

Does my concept hold any water or would this have no hope of working?

AtomicPorkchop
  • 2,625
  • 5
  • 36
  • 55
  • [FileSystemProvider](http://docs.oracle.com/javase/7/docs/api/java/nio/file/spi/FileSystemProvider.html) – tckmn Jan 03 '13 at 12:26

3 Answers3

1

If you're on java7 you could take a look at shrinkwrap or implement your own FileSystemProvider.

In pre java7 simulating an "in-memory filesystem" is fairly complex. You could look at commons-vfs but if I remember correctly it handles only URLs and not Files.

Peter Svensson
  • 6,105
  • 1
  • 31
  • 31
  • Go ahead and try the answer then :). I think an "in-memory" filesystem will suit you better than a Map/Tree implementation. – Peter Svensson Jan 03 '13 at 12:36
0

This doesn't sound like a Map (key/value store) at all.

I would rather have a tree structure of File/Directory objects. Your current position is simply recorded as one instance of a Directory object. I suspect you'd likely need a doubly-linked structure for efficiency's sake.

This SO question/answer may provide more info and suggestions.

Community
  • 1
  • 1
Brian Agnew
  • 268,207
  • 37
  • 334
  • 440
0

Use a real Tree structure, not a TreeMap. It could use TreeMaps internally for the content of each node (folder), but the whole shouldn't be a TreeMap.

David Pierre
  • 9,459
  • 4
  • 40
  • 32