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

uk.co.caeldev.builder4test.DefaultLookUp Maven / Gradle / Ivy

package uk.co.caeldev.builder4test;

import java.util.HashMap;
import java.util.Map;
import java.util.Optional;

import static java.util.Objects.isNull;

public class DefaultLookUp extends LookUp {

    private Map values;

    protected DefaultLookUp() {
        this.values = new HashMap<>();
    }

    protected DefaultLookUp(Map values) {
        this.values = values;
    }

    @Override
    protected  void put(Field field, V value) {
        values.put(field, Optional.ofNullable(value));
    }

    @Override
    public  V get(Field field, V defaultValue) {
        Optional optValue = values.get(field);

        if (isNull(optValue)) {
            return defaultValue;
        }

        if (optValue.isPresent()) {
            return (V) optValue.get();
        }

        return null;
    }

    @Override
    public  V get(Field field) {
        return get(field, field.getDefaultValue());
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy