Parallel map from property files

This is a continuation of my previous question (found here ). So far, my property files are made up of simple key-value pairs such as ints and Strings. Now I would like to use it to place more complex structures in it, in particular, I need a map <A, Integer>, where A is the class that I defined, for example:

foo=bar,5;baz,10

Is it possible? If so, how should I format the file and analyze the card, respectively?

Are there perhaps better ways to solve this problem?

+3
source share
4 answers

Have you considered using split () and trim ().

See below:

ResourceBundle rb = ResourceBundle.getBundle(Prop.class.getName());

    String fooValue = rb.getString("foo");
    String[] firstSplit = fooValue.split(";");
    for(String first : firstSplit){
        String firstTrim = first.trim();

        String[] intAndString = firstTrim.split(",");
        if(intAndString.length == 2){
            String intString = intAndString[0].trim();
            String stringVal = intAndString[1].trim();

            //TODO add entries here or return value.

        }
    }
+3

, , , , Spring Framework.

, , , .

Spring

Spring

<beans>
    <bean id="foo" class="x.y.Foo">
        <property name="accounts">
            <map>
                <entry key="one" value="9.99"/>
                <entry key="two" value="2.75"/>
                <entry key="six" value="3.99"/>
            </map>
        </property>
    </bean>
</beans>
+1

XML , , , .

, JIBX XML Beans, .

+1

. /,

= 5 = 10

, . , .

- . /. , , , , ? , XML - . , , . CSV. , , , .

+1

Source: https://habr.com/ru/post/1716913/


All Articles