@Test public void takeTakesCorrectTimes() throws Exception { double double1 = 123; double double2 = 32; ObservableDouble observed = new ObservableDouble(double1); ObservableDouble observing = Cinder.computeDouble(()-> observed.get() , observed).take(2).immediate(); assertTrue(observing.get() == double1); observed.set(double2); assertTrue(observing.get() == double2); observed.set(double1); assertTrue(observing.get() == double2); }
@Test public void skipSkipsCorrectTimes() throws Exception { double double1 = 123; double double2 = 32; ObservableDouble observed = new ObservableDouble(); ObservableDouble observing = Cinder.computeDouble(()-> observed.get() , observed).skip(1); observed.set(double1); assertTrue(observing.get() == 0); observed.set(double2); assertTrue(observing.get() == double2); observed.set(double1); assertTrue(observing.get() == double1); }
Listener(final ObservableDouble observableDouble, final Observer<? super Double> observer) { this.observableDouble = observableDouble; this.onPropertyChangedCallback = new android.databinding.Observable.OnPropertyChangedCallback() { @Override public void onPropertyChanged(android.databinding.Observable observable, int ignoredPropertyId) { if (!isDisposed()) { ObservableDouble observableDouble = (ObservableDouble) observable; observer.onNext(observableDouble.get()); } } }; }
@Test public void computesDouble() throws Exception { double double1 = 0.35; double double2 = 234.09; ObservableDouble obsDouble = new ObservableDouble(double1); ObservableDouble computedDouble = Cinder.computeDouble(()->obsDouble.get(), obsDouble).immediate(); assertEquals(computedDouble.get(), double1, 0.001); obsDouble.set(double2); assertEquals(computedDouble.get(), double2, 0.001); }
@Test public void onceTakesOnce() throws Exception { double double1 = 123; double double2 = 43; ObservableDouble observed = new ObservableDouble(double1); ObservableDouble observing = Cinder.computeDouble(()-> observed.get(), observed).once().immediate(); assertTrue(observing.get() == double1); observed.set(double2); assertTrue(observing.get() == double1); }
@Test public void filterFilters() throws Exception { double double1 = 123; double double2 = 32; ObservableDouble observed = new ObservableDouble(); ObservableDouble observing = Cinder.computeDouble(()-> observed.get() , observed).filter(()->observed.get() == double1); observed.set(double2); assertTrue(observing.get() == 0); observed.set(double1); assertTrue(observing.get() == double1); }
@Test public void takeWhileTakesWhileTrue() throws Exception { double double1 = 123; double double2 = 32; ObservableDouble observed = new ObservableDouble(); ObservableDouble observing = Cinder.computeDouble(()-> observed.get() , observed).takeWhile(()->observed.get() == double1); observed.set(double1); assertTrue(observing.get() == double1); observed.set(double2); assertTrue(observing.get() == double1); }
@Test public void skipWhileSkipsWhileTrue() throws Exception { double double1 = 123; double double2 = 32; ObservableDouble observed = new ObservableDouble(); ObservableDouble observing = Cinder.computeDouble(()-> observed.get() , observed).skipWhile(()->observed.get() == double1); observed.set(double1); assertTrue(observing.get() == 0); observed.set(double2); assertTrue(observing.get() == double2); }
@Test public void withDefaultAssignsDefault() throws Exception { double double1 = 12; ObservableDouble observing = Cinder.computeDouble(()->0 ).withDefault(double1); assertTrue(observing.get() == double1); }
@Test public void stopStops() throws Exception { double double1 = 123; double double2 = 43; ObservableDouble observed = new ObservableDouble(double1); CinderDouble observing = Cinder.computeDouble(()-> observed.get(), observed).immediate(); assertTrue(observing.get() == double1); observing.stop(); observed.set(double2); assertTrue(observing.get() == double1); }
@Test public void convertsObservableDoubleToRx() throws Exception { ObservableDouble observableDouble = new ObservableDouble(); Observable<Double> rxDouble = RxCinder.convert(observableDouble); final String TEST_KEY = "TEST_KEY"; final ArrayMap<String, Double> testMap = new ArrayMap<>(); rxDouble.subscribe((c)->{ testMap.put(TEST_KEY, c);}); final double TEST_DOUBLE = 23; observableDouble.set(TEST_DOUBLE); assertTrue(testMap.get(TEST_KEY).equals(TEST_DOUBLE)); }
@Test public void convertsRxDoubleToObservable() throws Exception { double TEST_DOUBLE = 234; Observable<Double> rxDouble = Observable.just(TEST_DOUBLE); ObservableDouble observableDouble = RxCinder.convertDouble(rxDouble); assertTrue(observableDouble.get() == TEST_DOUBLE); }
ObservableDoubleObservable(ObservableDouble observableDouble) { this.observableDouble = observableDouble; }
public static Observable<Double> convert(ObservableDouble observableDouble){ return Observable.create((e)-> Cinder.observe(()->e.onNext(observableDouble.get()), observableDouble) ); }
public static ObservableDouble convertDouble(Observable<Double> observable){ ObservableDouble observableDouble = new ObservableDouble(); observable.subscribe((d)->observableDouble.set(d)); return observableDouble; }
/** * Create an observable of property change events on {@code observableDouble}. * <p> * <em>Warning:</em> The created observable keeps a strong reference to {@code observableDouble}. * Unsubscribe to free this reference. */ @CheckResult @NonNull // public static Observable<Double> propertyChanges(@NonNull ObservableDouble observableDouble) { checkNotNull(observableDouble, "observableDouble == null"); return new ObservableDoubleObservable(observableDouble); }