所以我正在尝试用 MapDB 做一些事情,但我遇到了障碍。我会尽力描述它:
我有四个数据,我们会说它是这样的:
1) String action; //the name of the action itself
2) String categoryOfAction; //the category of the action
3) Integer personWhoPerformedAction; //the person that did the action
4) Long timeOfOccurrence; //the time the action was done
相同的动作可以在这个数据库中由不同的人在不同的时间以及不同的类别中多次执行。我想要三个独立的地图,每个地图都将数据组织成这样的东西:
String[] actionOccurances = map1.get(action); //returns every occurrence of that action (possibly in an array), including who did that occurrence, time the occurrence occurred, and the category of that occurrence
Long latestOccurance = map2.get(action); //returns the latest occurrence of that action
String[] actionsPerformedByPerson = map3.get(personWhoPerformedAction); //returns every action that this person has done, including the category of that action, the time they performed that action, and the name of the action itself
所以,我想尽可能高效地做到这一点。我知道我可以做这样的事情:
DB thedb = DBMaker.newTempFileDB().make();
NavigableSet<Object[]> map1 = thedb.createTreeSet("actionOccurences").comparator(Fun.COMPARABLE_ARRAY_COMPARATOR).make();
HTreeMap<String, Long> map2 = thedb.getHashMap("lastOccurrence");
NavigableSet<Object[]> map3 = thedb.createTreeSet("actionsPerformedByPerson").comparator(Fun.COMPARABLE_ARRAY_COMPARATOR).make();
但我觉得那是错误的。必须有一种更有效的方法,我不必多次存储相同的数据,是吗?
我已经玩了很多 Bind 类及其函数(secondaryValues、mapInverse 等),但我似乎无法找到将这组数据映射成我想要的样子的方法。
有什么帮助吗?谢谢。