@Override public Connection connect (Listener<? super T> listener) { return addConnection(listener); } @Override public Connection connectNotify (Listener<? super T> listener) {
/** * Updates the value contained in this instance and notifies registered listeners. * @param force if true, the listeners will always be notified, if false the will be notified * only if the new value is not equal to the old value (per {@link #areEqual}). * @return the previously contained value. */ protected T updateAndNotify (T value, boolean force) { checkMutate(); T ovalue = updateLocal(value); if (force || !areEqual(value, ovalue)) { emitChange(value, ovalue); } return ovalue; }
@Override public Connection connectNotify (SignalView.Listener<? super T> listener) { return connectNotify(wrap(listener)); } private static <T> Listener<T> wrap (final SignalView.Listener<? super T> listener) {
@Override public Connection connectNotify (Listener<? super T> listener) { // connect before calling emit; if the listener changes the value in the body of onEmit, it // will expect to be notified of that change; however if onEmit throws a runtime exception, // we need to take care of disconnecting the listener because the returned connection // instance will never reach the caller Connection conn = connect(listener); try { listener.onChange(get(), null); return conn; } catch (RuntimeException re) { conn.close(); throw re; } catch (Error e) { conn.close(); throw e; } }
@Override protected Connection connect () { return outer.connect(new Listener<T>() { @Override public void onChange (T value, T ovalue) { notifyChange(func.apply(value), func.apply(ovalue)); } }); } };
@Override public int hashCode () { T value = get(); return (value == null) ? 0 : value.hashCode(); }
@Override protected void connectionAdded () { super.connectionAdded(); if (_conn == null) _conn = connect(); }
@Override protected void connectionRemoved () { super.connectionRemoved(); if (!hasConnections()) disconnect(); }
@Override public Connection connectNotify (Slot<? super T> slot) { return connectNotify((Listener<? super T>)slot); }
@Override public Connection connectNotify (SignalView.Listener<? super T> listener) { return connectNotify(wrap(listener)); } private static <T> Listener<T> wrap (final SignalView.Listener<? super T> listener) {
@Override public Connection connectNotify (Listener<? super T> listener) { // connect before calling emit; if the listener changes the value in the body of onEmit, it // will expect to be notified of that change; however if onEmit throws a runtime exception, // we need to take care of disconnecting the listener because the returned connection // instance will never reach the caller Connection conn = connect(listener); try { listener.onChange(get(), null); return conn; } catch (RuntimeException re) { conn.close(); throw re; } catch (Error e) { conn.close(); throw e; } }
@Override protected Connection connect () { return outer.connect(new ValueView.Listener<T>() { @Override public void onChange (T value, T oldValue) { notifyEmit(value); } }); } };
@Override public int hashCode () { T value = get(); return (value == null) ? 0 : value.hashCode(); }
@Override protected void connectionAdded () { super.connectionAdded(); if (_conn == null) _conn = connect(); }
@Override protected void connectionRemoved () { super.connectionRemoved(); if (!hasConnections()) disconnect(); }