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

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

问题描述

MultiValueMap 类(Apache commons collections) 使得使用值为 Collections 的 Map 变得容易.我正在寻找一个类,它可以轻松处理键是对象而值是 Map 的 Map.

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.

我使用的是 Java 1.4,因此无法使用 Google 集合或泛型.

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

推荐答案

Map of maps 实际上是一个没有单根节点的树型结构(以及map of maps的map...).

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")

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

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

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