All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.sigopt.model.Utils Maven / Gradle / Ivy

There is a newer version: 6.3.0
Show newest version
package com.sigopt.model;

import java.util.List;
import java.util.Map;

class Utils {
    public static Integer asInteger (Object jsonObject) {
        if (jsonObject == null) {
            return null;
        }
        Double d = (Double) jsonObject;
        return d.intValue();
    }

    public static  T mergeInto(T t, Object jsonObject) {
        if (jsonObject == null) {
            return null;
        }
        Map toSet = (Map) jsonObject;
        t.setAll(toSet);
        return t;
    }

    public static  List mergeIntoList(List list, Object jsonObject, Class klass) {
        List> storedList = (List>) jsonObject;
        if (storedList == null) {
            return null;
        }
        for (Map storedObj : storedList) {
            T t;
            try {
                t = klass.newInstance();
            } catch (InstantiationException e) {
                throw new RuntimeException(e);
            } catch (IllegalAccessException e) {
                throw new RuntimeException(e);
            }
            t.setAll(storedObj);
            list.add(t);
        }
        return list;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy