Spring.xml中的HashBasedTable

时间:2014-08-04 15:06:40

标签: java spring guava

我已成功写入spring.xml中的表,如下所示。

<bean id="kpTable" class="com.kp.util.MultiMapToTableConverter" factory-method="createTableFactory"
        scope="prototype">
        <constructor-arg name="map">
            <util:map>
                <entry key="usa">
                    <util:map>
                        <entry key="alabama" value="Montgomery" />
                        <entry key="Arizona" value="Phoenix" />
                        <entry key="Arkansas" value="Little Rock" />
                        <entry key="California" value="Sacramento" />
                        <entry key="Colorado" value="Denver" />
                    </util:map>
                </entry>
                <entry key="uk">
                    <util:map>
                        <entry key="Yorkshire" value="York" />
                        <entry key="Norfolk" value="Norwich" />
                        <entry key="Oxfordshire " value="Oxford" />
                        <entry key="Northamptonshire " value="Northampton" />
                        <entry key="Nottinghamshire " value="Nottingham" />
                    </util:map>
                </entry>
                <entry key="in">
                    <util:map>
                        <entry key="maharashtra" value="mumbai" />
                        <entry key="karnataka" value="bangalore" />
                        <entry key="tamil nadu" value="chennai" />
                        <entry key="west bengal " value="kolkata" />
                    </util:map>
                </entry>
            </util:map>
        </constructor-arg>
    </bean>

MultiMapToTableConverter.java

public class MultiMapToTableConverter {

    public static Table<String, String, String> createTableFactory(Map<String, Map<String, String>> map) {

        Table<String, String, String> table = HashBasedTable.create();

        for (Map.Entry<String, Map<String, String>> outerEntrySet : map.entrySet()) {

            for (Map.Entry<String, String> innerEntrySet : outerEntrySet.getValue().entrySet()) {
                table.put(outerEntrySet.getKey(), innerEntrySet.getKey(), innerEntrySet.getValue());
            }
        }
        return table;
    }

}

MyTest类

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={"classpath*:spring-kp-context.xml"})
public class KPTableTest {

    @Autowired
    private Table<String, String, String> table;

    @Test
    public void kpTest(){
        System.out.println(table.get("usa", "alabama"));
        System.out.println(table.get("in", "karnataka"));
        System.out.println(table.get("in", "tamil nadu"));
}

现在我有一些基于实施的问题

  1. 如下link所述,答案被低估了。有什么问题。
  2. 实施中是否存在任何瓶颈,我知道HashBasedTable未被删除但我没有任何问题。我知道我的桌子不会改变。
  3. 从效果角度来看,Map<String,Map<String,String>> Vs HashBasedTable
  4. 更好。{
  5. 这可能是一个更广泛的问题,但HashBasedTable是否存在任何限制?

0 个答案:

没有答案