Introducing a kind of key-value pair (not essentially a HashMap) in Java

What is the best way to implement the following script in Java:

Kind of a key-value pair mechanism, but it looks like this:

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  

In my opinion, HashMap makes it difficult to implement this type of mapping. What is the best way to implement such a mapping?
I also considered placing them in an Oracle table and trying to write a procedure, but in Java there might be a better way.

+3
source share
3 answers

One way to achieve this can be a triple nested hash map. Or a hashmap of hashmaps of hashmaps.

The pseudo-code for the request will be something like this:

//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]
}

, , . , 3 ? , , , , , .

, .
key1, key2, key3 = value1
key1, key2, key4 = value2
key1, *, key3, value1.
key1, *, *, 1, value2 .

Update:
( "1", "," 3"),
param1 ( ), subquery1 (hashmap [ "key1" ], "," key3");
, 1, hashMap [ "key1" ] , hashmap,
hashmap hashmap2 []. , 1 (hashmap2 [], "*", "key3" );

1.
param2 "*", hashmap2 [],
hashmap3 [] hashmap2 [], subquery3 (hashmap3 [], "key3" );

, param3 , hashmap3 [ "key3" ], value1;

+2

You must use trie to represent values. This will allow you to quickly and easily move around your structure, as well as quickly manage any, not conditions. Here you can find.

0
source

Source: https://habr.com/ru/post/1786574/


All Articles