/*
 * Copyright 2015-2020 OpenCB
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.opencb.cellbase.core.api.queries;

import org.apache.commons.beanutils.BeanUtils;
import org.slf4j.Logger;

import javax.ws.rs.core.MultivaluedMap;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

public class AbstractQuery extends QueryOptions {

    protected Logger logger;

    final static int DEFAULT_LIMIT = 10;
    final static int DEFAULT_SKIP = 0;

    public AbstractQuery() {
    }

    public static Object of(MultivaluedMap<String, String> map, Class clazz)
            throws NoSuchFieldException, IllegalAccessException, InstantiationException, InvocationTargetException {
        Object query = clazz.newInstance();
        for (Map.Entry<String, List<String>> entry : map.entrySet()) {
            String fieldName = entry.getKey();
            List<String> values = entry.getValue();
            Field field = clazz.getField(fieldName);
            if (field.getType().equals("Boolean")) {
                Boolean bool = Boolean.parseBoolean(values.get(0));
                BeanUtils.setProperty(query, fieldName, bool);
            } else if (field.getType().equals("Integer")) {
                Integer intValue = Integer.parseInt(values.get(0));
                BeanUtils.setProperty(query, fieldName, intValue);
            } else if (field.getType().equals("List")) {
                List<String> valuesArray = Arrays.asList(values.get(0).split(","));
                BeanUtils.setProperty(query, fieldName, valuesArray);
            } else {
                BeanUtils.setProperty(query, fieldName, values.get(0));
            }
        }
        return query;
    }

}

@@ -1575,18 +1575,22 @@
         
-if
+switch
  (field.
@@ -1599,23 +1599,51 @@
 tType().
-equals(
+toString()) %7B%0A                case 
 %22Boolean
@@ -1643,21 +1643,20 @@
 Boolean%22
-)) %7B%0A
+:%0A  
         
@@ -1663,16 +1663,18 @@
         
+  
 Boolean 
@@ -1709,32 +1709,36 @@
 values.get(0));%0A
+    
                 
@@ -1800,42 +1800,44 @@
     
-%7D else if (field.getType().equals(
+        break;%0A                case 
 %22Int
@@ -1841,21 +1841,22 @@
 Integer%22
-)) %7B%0A
+:%0A    
         
@@ -1923,32 +1923,36 @@
                 
+    
 BeanUtils.setPro
@@ -2002,53 +2002,56 @@
     
-%7D else if (field.getType().equals(%22List%22)) %7B%0A
+        break;%0A                case %22List%22:%0A    
     
@@ -2138,32 +2138,36 @@
                 
+    
 BeanUtils.setPro
@@ -2220,17 +2220,52 @@
     
+     
-%7D else %7B%0A
+   break;%0A                default:%0A    
     
@@ -2324,32 +2324,59 @@
 values.get(0));%0A
+                    break;%0A
             %7D%0A  

change to switch statement