地图数据结构地图 [英] Map of Maps data structure

查看:88
本文介绍了地图数据结构地图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

MultiValueMap 类(Apache commons collections)可以方便地处理值为Collections的Map。我正在寻找一个类,使它很容易处理一个地图的键是对象,值是地图。



我使用Java 1.4,所以可以'

解决方案

地图的地图实际上是一个没有单根节点的树型结构



您可以查看复合模式,广泛用于实现树结构(如果它们的组件具有相同的类型,而我感觉不是这样)。



<另一个解决方案是实现一个简单的域模型。它会更清楚地阅读和容易维护像:

  school.getPupil(John Doe)getMark (Math)

  school.get(John Doe)。get(Math)


The MultiValueMap class (Apache commons collections) makes it easy to work with a Map whose values are Collections. I'm looking for a a class that makes it easy to work with a Map whose keys are objects and values are Maps.

I'm using Java 1.4, so can't use Google Collections or generics.

解决方案

Map of maps is actually a tree-type structure without single root node (as well as map of maps of maps...).

You can look at Composite pattern which is widely used for implementing tree structures (if their components has the same type which is not the case as I feel).

Another solution is to implement a simple domain model. It'll be much clearer to read and easy to maintain something like:

school.getPupil ("John Doe").getMark ("Math")

than

school.get ("John Doe").get ("Math")

这篇关于地图数据结构地图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆