Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Create a Folder object to store the data, then build these objects as you read from the database. Once you have built all the Folder objects, do a final loop to bind each Folder to its parent class. Perhaps something like this:</p> <pre><code>class Folder { private String name; private int id; private int parentId; private List&lt;Folder&gt; children = new ArrayList&lt;Folder&gt;(); public Folder(String name, int id, int parentId) { this.name = name; this.id = id; this.parentId = parentId; } public void addChildFolder(Folder folder) { this.children.add(folder); } public List&lt;Folder&gt; getChildren() { return Collections.unmodifiableList(children); } public int getParentFolderId() { parentId; } public String getName() { return name; } public int getId() { return id; } } </code></pre> <p>Now as you read the data from the database, you create these Folder objects (with no children) and add them to the map with:</p> <pre><code>Map&lt;Integer, Folder&gt; data = new HashMap&lt;Integer, Folder&gt;(); ... loop through your result set getting folder data... Folder newFolder = new Folder(nameString, id, parentId); data.put(newFolder.getId(), newFolder); </code></pre> <p>Use Integer.valueOf(String) to convert String to int.</p> <p>Once you have the created all the Folders, you can make one final loop to connect the parent folders to the children, like this:</p> <pre><code>for(Folder folder : data.values()) { int parentId = folder.getParentFolderId(); Folder parentFolder = data.get(parentId); if(parentFolder != null) parentFolder.addChildFolder(folder); } </code></pre> <p>Finally, just grab the folder with id 0 and start building your Files on the disk, using folder.getChildren() as a convenient way to move down the tree. Check out the javadoc on the File object, you will particularly want to use the mkdirs() method.</p> <p>Hope that helps.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload