4

For instance, how would you declare a triple map like-

Map<String, Map<String, Map<Boolean, String>>>, with the keys being someKey1, someKey2, and someKey3 (true/false)?

I know until this-

<util:map
     id="someMap"
    map-class="java.util.HashMap"
    key-type="java.lang.String"
    value-type="java.lang.String">
        <entry key="someKey1" value="someValue" />
</util:map>

EDIT:

Ok, this is what I want to do to reduce tons of if statements.

123: //some key 1

  abc: //some key 2

     true:  //some key 3

        a  //some value

     false: //some key 3

        b  //some value


 456: 

  def: 

     true:  

        c

     false: 

        d

Thanks a bunch.

0

2 Answers 2

6

Perhaps this would work:

<util:map id="someMap">
    <entry key="123">
        <value>
            <map>
                <entry key="abc">
                    <value>
                        <map key-type="java.lang.Boolean">
                            <entry key="true" value="a"/>
                            <entry key="false" value="b"/>
                        </map>
                    </value>
                </entry>
            </map>
        </value>
    </entry>
    <entry key="456">
        <value>
            <map>
                <entry key="def">
                    <value>
                        <map key-type="java.lang.Boolean">
                            <entry key="true" value="c"/>
                            <entry key="false" value="d"/>
                        </map>
                    </value>
                </entry>
            </map>
        </value>
    </entry>
</util:map>
Sign up to request clarification or add additional context in comments.

2 Comments

Map<String, Map<String, Map<Boolean, String> But isn't it from this structure, the value for the first key is also a map and same goes for the second one where in your code snippet, the value is a String for the first map?
Whoops, I forgot to remove that "value-type" attribute off the first map. Is this a little more like what you're looking for?
5

Did you really get Adam's code to compile? I had to remove the outer value-tags to make it work.

<util:map id="someMap">
    <entry key="123">        
        <map>
            <entry key="abc">
                <map key-type="java.lang.Boolean">
                    <entry key="true" value="a"/>
                    <entry key="false" value="b"/>
                </map>        
            </entry>
        </map>        
    </entry>
    <entry key="456">
        <map>
            <entry key="def">
                 <map key-type="java.lang.Boolean">
                     <entry key="true" value="c"/>
                     <entry key="false" value="d"/>
                 </map>
            </entry>
        </map>
    </entry>
</util:map>

Or am I missing something? =)

1 Comment

Agreed, I had to get rid of the outer value tags as well. Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.