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

com.github.sinjar.common.base.IGetter Maven / Gradle / Ivy

There is a newer version: 1.3
Show newest version
package com.github.sinjar.common.base;

import java.util.Date;
import java.util.function.Function;

public interface IGetter {

    Object get(String key);

    default  T get(String key, Class returnClass) {
        return returnClass.cast(get(key));
    }

    default String getString(String key) {
        return (String) get(key);
    }

    default Date getDate(String key) {
        return (Date) get(key);
    }

    default Integer getInteger(String key) {
        return (Integer) get(key);
    }

    default Object getDefault(String key, Object defaultObj) {
        Object o = get(key);
        if (o == null) {
            return defaultObj;
        }
        return o;
    }

    default  T getDefault(String key, Class returnClass, T defaultObj){
        Object o = get(key);
        if (o == null) {
            return defaultObj;
        }
        return returnClass.cast(o);
    }

    default  R get(String key, Function function){
        Object o = get(key);
        return function.apply(o);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy