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

com.github.leeonky.util.PropertyWriter Maven / Gradle / Ivy

The newest version!
package com.github.leeonky.util;

import java.util.function.BiConsumer;

public interface PropertyWriter extends PropertyAccessor {

    BiConsumer setter();

    default void setValue(T bean, Object value) {
        try {
            setter().accept(bean, value);
        } catch (CannotSetElementByIndexException e) {
            throw e;
        } catch (IllegalArgumentException e) {
            String propertyName = getBeanType().isCollection() ? "[" + getName() + "]" : "." + getName();
            throw new IllegalArgumentException(String.format("Can not set %s to property %s%s<%s>",
                    value == null ? "null" : Classes.getClassName(value) + "[" + value + "]",
                    getBeanType().getName(), propertyName, getType().getName()), e);
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy