package com.shundaojia.variable;

import android.support.annotation.NonNull;
import android.support.annotation.Nullable;

import io.reactivex.Observable;
import io.reactivex.subjects.BehaviorSubject;
import io.reactivex.subjects.Subject;

/**
 * Created by listen on 2017/9/24.
 */

public class Variable<T> {

    private  T val;

    private final Subject<T> subject;

    public Variable(@NonNull T initial) {
        val = initial;
        BehaviorSubject<T> subject = BehaviorSubject.create();
        this.subject = subject.toSerialized();
    }

    @Nullable
    public T value() {
        synchronized (this) {
            return val;
        }
    }

    public void setValue(@NonNull T value) {
        synchronized (this) {
            this.val = value;
        }
        subject.onNext(value);
    }

    public Observable<T> asObservable() {
        return subject;
    }

}

@@ -304,16 +304,199 @@
 e%3CT%3E %7B%0A%0A
+    private final static Object INSTANCE = new Object();%0A%0A    public static %3CT%3E T NULL() %7B%0A        @SuppressWarnings(%22unchecked%22)%0A        T t =  (T)INSTANCE;%0A        return t;%0A    %7D%0A%0A
     priv
@@ -982,32 +982,101 @@
 (value);%0A    %7D%0A%0A
+    public boolean isNULL() %7B%0A        return INSTANCE == val;%0A    %7D%0A%0A
     public Obser

update variable