Java 类javafx.collections.WeakSetChangeListener 实例源码

项目:reta    文件:ObservableSetBuffering.java   
/**
 * @param newBeanType
 *            bean type
 * @param newPropertyName
 *            bean property name
 * @param newSubject
 *            property value
 */
public ObservableSetBuffering(final Class<?> newBeanType, final String newPropertyName,
        final ObservableSet<E> newSubject)
{
    super(FXCollections.observableSet(new HashSet<>(newSubject != null ? newSubject.size() : 0)));

    if (newBeanType != null || !(newSubject instanceof ReadOnlyProperty<?>))
    {
        beanType = newBeanType;
    }
    else
    {
        final Object bean = ((ReadOnlyProperty<?>) newSubject).getBean();
        beanType = (bean != null ? bean.getClass() : null);
    }

    if (newPropertyName != null || !(newSubject instanceof ReadOnlyProperty<?>))
    {
        propertyName = newPropertyName;
    }
    else
    {
        propertyName = ((ReadOnlyProperty<?>) newSubject).getName();
    }

    subject = Objects.requireNonNull(newSubject);

    addAll(subject);

    thisListener = c -> {
        if (equalsBuffering)
        {
            buffering.setValue(!equalsSubject());
        }
        else
        {
            buffering.setValue(true);
        }
        validate();
    };

    subjectListener = c -> {
        if (!buffering.getValue())
        {
            revert();
        }
    };

    addListener(thisListener);

    weakSubjectListener = new WeakSetChangeListener<E>(subjectListener);
    subject.addListener(weakSubjectListener);

    validate();
}