Tuesday, May 31, 2011

FileTree.java very complex, can someone help me get started?

Need helping getting started on method ';public void mkdir(String dir) throws TreeViolationException {';. Need a step by step psuedocode or explanation of how to do this algorithm. Thank you.

------------------------------

Here is the link for the assignment:

http://remus.rutgers.edu/cs112/2009/spri

-------------------------------

Here is my FileTree.java:



package apps;



import structures.*;



import java.io.BufferedReader;

import java.io.IOException;

import java.util.StringTokenizer;

import java.util.ArrayList;

import java.util.NoSuchElementException;



/**

* This class implements some UNIX filesystem commands, using a general

* tree to implement the filesystem.

*

* @author ru-nb-cs112

*

*/

public class FileTree {



/**

* The full pathname of the current directory, starting with ';/';,

* not containing any '..'

* Unless the pathname itself is just ';/';, it may not end with ';/';

*/

String currentDirectory;



/**

* The actual general tree node of the current directory

*/

GeneralTree currentDirNode;



/**

* Maintains the state of the filesystem by using methods and

* structure of GeneralTree

*/

GeneralTree fileSystem;



/**

* Builds an ';empty'; file system with root set to ';/'; and no

* other files or directories under the root.

* The current directory would be ';/';, the root of the new tree.

*/

public FileTree() {

fileSystem = new GeneralTree();

fileSystem.makeRoot(';/';);

currentDirectory = ';/';;

currentDirNode = fileSystem;

}





/**

*

* Builds a filesystem by reading its structure from the

* given BufferedReader. The structure is represented as

* the preorder and postorder traversal pair. The preorder

* traversal is listed first, followed by the postorder traversal,

* one string per line for each node of the file tree.

* The current directory would be ';/';, the root of the new tree.

* NOTE: The root of the filesystem MUST be ';/';.

*

* @param br BufferedReader from which tree traversals are read

* @throws IOException if there is an IO error while reading.

* @throws TreeViolationException if the input does not represent a legal

* FileTree with ';/'; at root.

*/

public FileTree(BufferedReader br)

throws IOException, TreeViolationException {

fileSystem = new GeneralTree();

currentDirectory = ';/';;

currentDirNode = fileSystem;



ArrayList%26lt;String%26gt; temp = new ArrayList%26lt;String%26gt;();

String line;

//Read from the file

while((line=br.readLine()) !=null){

temp.add(line);

}//while



int numNodes=temp.size();



//checks to make sure there are nodes and there aren't an uneven amount

if((numNodes%2!=0) || (numNodes==0)){

throw new TreeViolationException();

}//if



String preOrder[] = new String[numNodes/2];

String postOrder[] = new String[numNodes/2];

int count=0;



//put into preOrder[]

for(int i=0;i%26lt;numNodes/2;i++){

preOrder[i]=temp.get(count++);

}//for



//put into postOrder[]

for(int j=0;j%26lt;numNodes/2;j++){

postOrder[j]=temp.get(count++);

}//for



//build the tree

fileSystem.buildTree(preOrder,postOr?br>
}



/**

* Returns the full path name of the current directory.

*

* @return Full pathname of the current directory

*/

public String pwd() {

return currentDirectory;

}//pwd



/**

* Given the FULL or RELATIVE pathname of a directory, changes

* current directory to it.

*

* @param toDir Directory to which current directory is changed

* @throws NoSuchElementException if the directory does not exist

*/

public void cd(String toDir)

throws NoSuchElementException {



//fileSystem

//currentDirectory

//currentDirNode













/*** COMPLETE THIS METHOD ***/

/*** The currentDirNode and currentDirectory fields must be

updated to the new current directory. ***/



}//cd



/**

* Given the FULL or RELATIVE pathname of a directory, returns a

* ArrayList that consists of the BASE NAMES of the directories

* in the specified directory. If the RELATIVE pathname is null,

* it means contents of the current directory itself.

*

* @param dir Directory whose contents are listed

* @return Contents of the given directory, null if there is nothing

* in the current directory

* @throws NoSuchElementException if the directory does not exist

*/

public ArrayList%26lt;String%26gt; ls(String dir)

throws NoSuchElementException {



/*** COMPLETE THIS METHOD ***/































return null;



}//ls



/**

* Given the FULL or RELATIVE pathname of a directory, create it

* at the correct location.

* NOTE: All directories in the path name except for the last (new)

* one are assumed to already exist.

* Examples: (0) mkdir ';/usr'; will create the directory ';usr'; under root

* (1)FileTree.java very complex, can someone help me get started?
I highly recommend that you create JUnit tests for each of these methods. http://www.junit.org/



It will speed up your development time dramatically. (and your error checking).FileTree.java very complex, can someone help me get started?
haha, that looks long and boring.

No comments:

Post a Comment