Use a lista para implementar o tipo de banco de dados, entre, métodos de pesquisa precisos
A cópia do código é a seguinte:
Public Final Class CommonlocalQuery <t estende mapa <string, objeto >> {
// Lista de retorno depois de passar na consulta de dados, o primeiro parâmetro: a lista de consultas, o segundo parâmetro: a condição de consulta
Lista pública <T> Querydata (Lista final <T> Malllist, Final Hashhashmap <Política, String, String> Map) {
if (Malllist == null | map == null) {
devolver novo ArrayList <T> ();
}
if (Malllist.isEmpty ()) {
Retornar Malllist;
}
/* Encontre as condições de consulta correspondentes com base nas necessidades reais*/
SET <Policy> key1 = map.getfirstkeys ();
para (Política Política: Key1) {
ConcurrentHashMap <String, String> tempmap = map.get (Policy);
Set <string> key2 = tempmap.keyset ();
para (chave de string: key2) {
if (key.startswith ("-") || tempmap.get (key) == null ||
(tempmap.get (key)! = null && tempmap.get (key) .equals (""))) {
tempmap.remove (chave);
}
}
}
// Encontre o padrão de design da cadeia de responsabilidade
Filtrar filterormal, filtro intermediário, filtrofuzzy;
FilterMal = new FilterMal ();
filtro intermediário = new FilterBetween ();
filtrofuzzy = new filterfuzzy ();
FilterMal.setFilter (Filterbetween);
filtretween.setFilter (filtrofuzzy);
SET <Policy> endKey1 = map.getfirstkeys ();
List <T> listresult = new ArrayList <T> ();
para (t Resmap: Malllist) {
para (Política Política: EndKey1) {
ConcurrentHashMap <String, String> Querymap = map.get (Policy);
if (filterormal.dofilter (Resmap, Policy, Querymap) && listresult.contains (resmap)) {
listresult.add (resmap);
}
}
}
Retornar Listresult;
}
Política de enum estática pública {Normal, entre, difusa}
}
/*========= Cadeia de responsabilidade Class
classe abstrata filtro {
Filtro filtro;
public void setFilter (filtro filtro) {
this.filter = filtro;
}
public filter getFilter () {
retorno filtro;
}
abstrato Dofilter booleano (mapa <string, objeto> resmap, política de política, mapa <string, string> querymap);
}
// Método de pesquisa preciso
classe filterormal estende o filtro {
@Override
Dofilter booleano (mapa <string, objeto> resmap, política de política, mapa <string, string> querymap) {
// TODO Method Stub
if (policy.name (). Equalsignorecase (Policy.Normal.Name ())) {
Iterator <entradas <string, string >> iterator = querymap.entryset (). Iterator ();
while (iterator.hasnext ()) {
Entrada <string, string> entradas = iterator.Next ();
if (! Resmap.get (Entry.getKey ()). ToString ().
retornar falso;
}
}
} else if (filtro! = null) {
retornar filtro.dofilter (Resmap, Política, Querymap);
}
retornar true;
}
}
// entre o método de pesquisa
classe Filterbetween estende o filtro {
@Override
Dofilter booleano (mapa <string, objeto> resmap, política de política, mapa <string, string> querymap) {
// TODO Method Stub
if (policy.name (). Equalsignorecase (Policy.between.name ())) {
Iterator <entradas <string, string >> iterator = querymap.entryset (). Iterator ();
while (iterator.hasnext ()) {
Entrada <string, string> entradas = iterator.Next ();
if (! Pattern.Matches (".+? φ.+?", Entry.getValue ())))
jogue novo desconhecido ("os valores devem ser.+? φ.+? padrão");
String FirstValue = Entry.getValue (). Split ("φ") [0];
String SecondValue = Entry.getValue (). Split ("φ") [1];
if (resmap.get (entrada.getKey ()). tostring (). compareto (FirstValue) <0
||.
retornar falso;
}
}
} else if (filtro! = null) {
retornar filtro.dofilter (Resmap, Política, Querymap);
}
retornar true;
}
}
// Método de pesquisa difusa
classe filterfuzzy estende o filtro {
@Override
Dofilter booleano (mapa <string, objeto> resmap, política de política, mapa <string, string> querymap) {
// TODO Method Stub
if (policy.name (). Equalsignorecase (Policy.fuzzy.name ())) {
String tempstr = resmap.Values (). ToString (). Substituir ("", "") .Place ("," "" ");
Iterator <entradas <string, string >> iterator = querymap.entryset (). Iterator ();
while (iterator.hasnext ()) {
Entrada <string, string> entradas = iterator.Next ();
if (tempstr.substring (1, tempstr.length ()-1) .contains (Entry.getValue ())) {
retornar true;
}
}
} else if (filtro! = null) {
retornar filtro.dofilter (Resmap, Política, Querymap);
}
retornar true;
}
}
// Ajuda a classe implementa K1-K2-V
classe pública hashhashmap <k1, k2, v> {
Private ConcurrenthashMap <K1, ConcurrentHashMap <K2, V >> K1K2VMAP;
public hashhashmap () {
this.k1k2vmap = new concursonthashmap <k1, concorrentehashmap <k2, v >> ();
}
public void put (k1 key1, k2 key2, v valor) {
if (k1k2vmap.containskey (key1)) {
Concurrenthashmap <k2, v> k2vmap = k1k2vmap.get (key1);
k2vmap.put (key2, valor);
} outro {
Concurrenthashmap <k2, v> k2vmap = new concursonthashmap <k2, v> ();
k2vmap.put (key2, valor);
k1k2vmap.put (key1, k2vmap);
}
}
Public Set <K1> getfirstkeys () {
return k1k2vmap.keyset ();
}
public v get (k1 key1, k2 key2) {
Concurrenthashmap <k2, v> k2_v = k1k2vmap.get (key1);
retornar k2_v == NULL?
}
public concorrentehashmap <k2, v> get (k1 key1) {
retornar k1k2vmap.get (key1);
}
Public boolean containsKey (k1 key1, k2 key2) {
if (k1k2vmap.containskey (key1)) {
retornar k1k2vmap.get (key1) .containsKey (key2);
}
retornar falso;
}
public boolean containsKey (k1 key1) {
retornar k1k2vmap.containsKey (KEY1);
}
public void clear () {
if (k1k2vmap.size ()> 0) {
para (Concurrenthashmap <k2, v> k2vmap: k1k2vmap.values ()) {
k2vmap.clear ();
}
k1k2vmap.clear ();
}
}
}
// Método de uso específico
HASHHASHMAP <Política, String, String> Map = new HashHashmap <CommonlocalQuery.policy, String, String> ();
for (int i = 0; i <querykey.length; i ++) {
map.put (Policy.Normal, QueryKey [i], QueryValue [i]);
}
Lista <map <string, objeto >> mtemplist = new CommonlocalQuery <hashmap <string, objeto >> (