Advertisement
What_Ever

Untitled

Jun 10th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.51 KB | None | 0 0
  1. private LinkedHashMap<String, ArrayList<String>> parseCondition() {
  2.         if (searchTextField.getText().trim().isEmpty()) {
  3.             return null;
  4.         }
  5.         LinkedHashMap<String, ArrayList<String>> cond = new LinkedHashMap<>();
  6.  
  7.         String text = searchTextField.getText().trim();
  8.  
  9.         String[] queries = text.split(",");
  10.  
  11.         for (String query : queries) {
  12.             if (query.contains(":")) {
  13.                 String[] components = query.split(":");
  14.                 if (components.length != 2) {
  15.                     return null;
  16.                 }
  17.                 String key = components[0].trim();
  18.                 String value = components[1].trim();
  19.  
  20.                 System.out.println(key + " " + value);
  21.  
  22.                 if (!searchColumns.containsKey(key.toLowerCase()) || value.isEmpty()) {
  23.                     return null;
  24.                 }
  25.                 String colName = searchColumns.get(key);
  26.                 if (!cond.containsKey(colName)) {
  27.                     cond.put(colName, new ArrayList<>());
  28.                 }
  29.                 cond.get(colName).add(value);
  30.             } else {
  31.                 if (query.trim().isEmpty()) {
  32.                     return null;
  33.                 }
  34.  
  35.                 if (!cond.containsKey(Book.BOOK_TITLE_COLNAME)) {
  36.                     cond.put(Book.BOOK_TITLE_COLNAME, new ArrayList<>());
  37.                 }
  38.                 cond.get(Book.BOOK_TITLE_COLNAME).add(query.trim());
  39.             }
  40.         }
  41.  
  42.         return cond;
  43.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement