Note that there are some explanatory texts on larger screens.

plurals
  1. PODataStructure for implementing something like nested Maps?
    text
    copied!<p>I want to have a map that permits a tree-like behaviour. I want to be able to define a Map from string to an object, that can be another map, or a string:</p> <pre><code> Map&lt;String,(String OR Map)&gt; </code></pre> <p>The only way I think I know how to do it is through the Visitor Pattern. Is there an already made data structure that implements this?</p> <p>UPDATE: Here is the context: I want to parse form submitted through a post request. The form is multilevel and can have an arbitrary number of fields(chosen by the user). What I decided to do is to name the fields in the form with numbers as such:</p> <ol> <li>User|name</li> <li>processor|1|speed</li> <li>processor|1!name</li> <li>processor|2|speed</li> <li>disk|1|name</li> <li>disk|2|name</li> </ol> <p>I decided to break it up at | and then create a tree like structure so itwould look something like this:</p> <ul> <li>User <ul> <li>name = whatever the user inputs</li> </ul></li> <li>Processor <ul> <li>1 <ul> <li>speed = whatever the user inputs</li> <li>name = whatever the user inputs</li> </ul></li> <li>2 <ul> <li>speed = whatever the user inputs</li> </ul></li> </ul></li> <li>Disk <ul> <li>1 <ul> <li>name = whatever the user inputs</li> </ul></li> <li>2 <ul> <li>name = whatever the user inputs</li> </ul></li> </ul></li> </ul> <p>Only the last leaves would contain strings. There is not that many fields so I had a feeling using a Map may be a bit of an overkill, but honestly I really didn't know how to do this with anything else.</p>
 

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