在Java中实现一种键值对(实际上不是HashMap)

在Java中实现以下场景的最佳方法是什么:

一种键值对机制,但它看起来像这样:

param1 + param2 + param3 -> output1 param1 + * + !param3 -> output2 param1 + text containing value param2 + * -> output3 '*' => any parameter !param => any value other than this parameter text containing value 'param' => any data which contains the value 'param'. ex: aaaaa,bbb,param,ccc or aaaparambbb 

在我看来,HashMap使得实现这种类型的映射变得困难。 实现这样的映射的最佳方法是什么?
我也在考虑将这些放在Oracle表中并尝试编写一个过程,但在Java中可能有更好的方法。

实现这一目标的方法可以是三重嵌套哈希映射。 或者是散列图的散列图的散列图。

用于查询的伪代码将是这样的:

 //You would call this method to search. string query(string param1, string param2, string param3) { // The essence of the logic is, if you give a value for param3, // then it will do the subquery of the hashMap that param3 // is the key of, if you don't supply a value (or provide the wildcard) // it will search all the different hashmaps of the parent hashmap. // See below for an example if param1 != WILDCARD then subquery1(hashmap[param1], string param2, string param3); else for each x in hashmap, subquery1(x,string param2, string param3) } string subquery1(hashmap[hashmap[]] maps, string param2, string param3) { // The essence of the logic is, if you give a value for param2, // then it will do the subquery of the hashMap that param2 // is the key of, if you don't supply a value (or provide the wildcard) // it will search all the different hashmaps of the parent hashmap. if param2 != WILDCARD then subquery2(maps[param2], string param3); else for each x in maps, subquery2(x, string param3) } string subquery2(hashmap[] maps, string param3) { if param3 != WILDCARD then return maps[param3] else for each x in maps, return maps[param3] } 

显然,您需要定义是否允许返回多个值以及您希望如何解决此问题。 你还需要确定param 3是否可以为空? 问题陈述很模糊,但我已尽力回答我认为你的问题。

例如,如果您已将以下值添加到hashmap中。
key1,key2,key3 = value1
key1,key2,key4 = value2
如果您搜索了key1,*,key3,则会返回value1。
如果您搜索了key1,*,*,您将获得value1,并返回value2。

更新:
当你打电话询问(“key1”,“ ”,“key3”);
由于param1有效(不是通配符),我们调用subquery1(hashmap [“key1”],“ ”,“key3”);
在我们到达subquery1之前,会对hashMap [“key1”]进行求值,但它会返回另一个hashmap,
让我们调用这个hashmap hashmap2 []。 所以subquery1实际上是用(hashmap2 [],“*”,“key3”)调用的;

现在我们在subquery1。
由于param2是“*”,我们然后遍历hashmap2 []的所有值,
对于hashmap2 []中的每个hashmap3 [],我们调用subquery3(hashmap3 [],“key3”);

此时由于param3有效,我们调用hashmap3 [“key3”]并返回value1;

听起来你拥有/需要的是一个NFA,其中你的params是符号。

http://en.wikipedia.org/wiki/Nondeterministic_finite-state_machine

您应该使用trie来表示值。 这样您就可以快速轻松地浏览您的结构,并快速管理您的任何条件。 你可以在这里找到一个。