Search in sources :

Example 1 with NonWeakListener

use of com.revolsys.beans.NonWeakListener in project com.revolsys.open by revolsys.

the class Property method getPropertyChangeListener.

@SuppressWarnings("unchecked")
static PropertyChangeListener getPropertyChangeListener(final Object listener) {
    if (listener instanceof PropertyChangeListener) {
        final PropertyChangeListener propertyChangeListener = (PropertyChangeListener) listener;
        if (propertyChangeListener instanceof NonWeakListener) {
            return propertyChangeListener;
        } else {
            final WeakPropertyChangeListener weakListener = new WeakPropertyChangeListener(propertyChangeListener);
            return weakListener;
        }
    } else if (listener instanceof Consumer) {
        final Consumer<Object> consumer = (Consumer<Object>) listener;
        return (e) -> {
            final Object object = e.getNewValue();
            consumer.accept(object);
        };
    } else {
        return null;
    }
}
Also used : WeakPropertyChangeListener(com.revolsys.beans.WeakPropertyChangeListener) ProxyPropertyChangeListener(com.revolsys.beans.ProxyPropertyChangeListener) PropertyChangeListener(java.beans.PropertyChangeListener) BiConsumer(java.util.function.BiConsumer) Consumer(java.util.function.Consumer) WeakPropertyChangeListener(com.revolsys.beans.WeakPropertyChangeListener) NonWeakListener(com.revolsys.beans.NonWeakListener)

Aggregations

NonWeakListener (com.revolsys.beans.NonWeakListener)1 ProxyPropertyChangeListener (com.revolsys.beans.ProxyPropertyChangeListener)1 WeakPropertyChangeListener (com.revolsys.beans.WeakPropertyChangeListener)1 PropertyChangeListener (java.beans.PropertyChangeListener)1 BiConsumer (java.util.function.BiConsumer)1 Consumer (java.util.function.Consumer)1