hibernate - Criteria ilike mechanizm -


how write custom creteria api in order find unique result, matching longest sequence in database?

if have request string "v1234" should matched v123

v1234 -> v123 

if have request string "v12xxx" should matched v12

if have request string "v" should matched v

you can sort values length desc, , iterate these values check whether match, if matched break.

public static void main(string[] args) {     list<string> values = arrays.aslist("v", "v1", "v12", "v123");     collections.sort(values, new comparator<string>() {         @override         public int compare(string o1, string o2) {             return o2.compareto(o1);         }     });      string[] test = new string[]{"v123456", "v127896", "v1877", "v2394"};     (string s : test) {         (string str : values) {             if (s.contains(str)) {                 system.out.println(str);                 break;             }         }     } } 

Comments