Java Traversal list fuzzy query with

Source: Internet
Author: User

Java Traversal list fuzzy query with

1 /**2 * Filter List3      * @paramList to filter by list4      * @paramKey filtered by key5      * @param<T>6      * @return7      */8     Private<T> list<t> Search (list<t>list, String key) {9         //if the value of the query is not empty, walk in and return the value after the search, otherwise return the original valueTen         if(List! =NULL&& list.size () > 0) { One             //New Container Alist<t> area =NewArraylist<>(); -             BooleanisOK; -             //Cyclic olist Collection the              for(T t:list) { -                 //judge a inside if contains the value of the search, there is added, no otherwise will not add (will find the property name) -                 //if (t.tostring (). toUpperCase (). indexOf (str)! =-1) -                 //Area.add (t); +isOK =false; -                 //traversing entity classes, getting property names and property values +                  for(Field field:t.getclass (). Getdeclaredfields ()) { AField.setaccessible (true); at                     //Here are the properties that you specify to check -                     //item_firstletter item_name item_col1 -                     Switch(Field.getname ()) { -                          Case"Item_firstletter": -                             Try { -isOK =Field.get (t). ToString (). Contains (key); in}Catch(illegalaccessexception e) { - e.printstacktrace (); to                             } +                              Break; -                          Case"Item_name": the                             Try { *isOK =Field.get (t). ToString (). Contains (key); $}Catch(illegalaccessexception e) {Panax Notoginseng e.printstacktrace (); -                             } the                              Break; +                          Case"Item_col1": A                             Try { theisOK =Field.get (t). ToString (). Contains (key); +}Catch(illegalaccessexception e) { - e.printstacktrace (); $                             } $                              Break; -                     } -                     if(isOK) the                          Break; -                 }Wuyi                 if(isOK) the Area.add (t); -             } Wu             returnArea ; -}Else { About             return NewArrayList (); $         } -}

Java Traversal list fuzzy query with

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.