@Test public void takeTakesCorrectTimes() throws Exception { long long1 = 123; long long2 = 32; ObservableLong observed = new ObservableLong(long1); ObservableLong observing = Cinder.computeLong(()-> observed.get() , observed).take(2).immediate(); assertTrue(observing.get() == long1); observed.set(long2); assertTrue(observing.get() == long2); observed.set(long1); assertTrue(observing.get() == long2); }
@Test public void skipSkipsCorrectTimes() throws Exception { long long1 = 123; long long2 = 32; ObservableLong observed = new ObservableLong(); ObservableLong observing = Cinder.computeLong(()-> observed.get() , observed).skip(1); observed.set(long1); assertTrue(observing.get() == 0); observed.set(long2); assertTrue(observing.get() == long2); observed.set(long1); assertTrue(observing.get() == long1); }
Listener(final ObservableLong observableLong, final Observer<? super Long> observer) { this.observableLong = observableLong; this.onPropertyChangedCallback = new android.databinding.Observable.OnPropertyChangedCallback() { @Override public void onPropertyChanged(android.databinding.Observable observable, int ignoredPropertyId) { if (!isDisposed()) { ObservableLong observableLong = (ObservableLong) observable; observer.onNext(observableLong.get()); } } }; }
@Test public void computesLong() throws Exception { long long1 = 432; long long2 = 123415; ObservableLong obsLong = new ObservableLong(long1); ObservableLong computedLong = Cinder.computeLong(()->obsLong.get(), obsLong).immediate(); assertEquals(computedLong.get(), long1); obsLong.set(long2); assertEquals(computedLong.get(), long2); }
@Test public void onceTakesOnce() throws Exception { long long1 = 123; long long2 = 43; ObservableLong observed = new ObservableLong(long1); ObservableLong observing = Cinder.computeLong(()-> observed.get(), observed).once().immediate(); assertTrue(observing.get() == long1); observed.set(long2); assertTrue(observing.get() == long1); }
@Test public void filterFilters() throws Exception { long long1 = 123; long long2 = 32; ObservableLong observed = new ObservableLong(); ObservableLong observing = Cinder.computeLong(()-> observed.get() , observed).filter(()->observed.get() == long1); observed.set(long2); assertTrue(observing.get() == 0); observed.set(long1); assertTrue(observing.get() == long1); }
@Test public void takeWhileTakesWhileTrue() throws Exception { long long1 = 123; long long2 = 32; ObservableLong observed = new ObservableLong(); ObservableLong observing = Cinder.computeLong(()-> observed.get() , observed).takeWhile(()->observed.get() == long1); observed.set(long1); assertTrue(observing.get() == long1); observed.set(long2); assertTrue(observing.get() == long1); }
@Test public void skipWhileSkipsWhileTrue() throws Exception { long long1 = 123; long long2 = 32; ObservableLong observed = new ObservableLong(); ObservableLong observing = Cinder.computeLong(()-> observed.get() , observed).skipWhile(()->observed.get() == long1); observed.set(long1); assertTrue(observing.get() == 0); observed.set(long2); assertTrue(observing.get() == long2); }
@Test public void withDefaultAssignsDefault() throws Exception { long long1 = 12; ObservableLong observing = Cinder.computeLong(()->0 ).withDefault(long1); assertTrue(observing.get() == long1); }
@Test public void stopStops() throws Exception { long long1 = 123; long long2 = 43; ObservableLong observed = new ObservableLong(long1); CinderLong observing = Cinder.computeLong(()-> observed.get(), observed).immediate(); assertTrue(observing.get() == long1); observing.stop(); observed.set(long2); assertTrue(observing.get() == long1); }
@Test public void convertsObservableLongToRx() throws Exception { ObservableLong observableLong = new ObservableLong(); Observable<Long> rxLong = RxCinder.convert(observableLong); final String TEST_KEY = "TEST_KEY"; final ArrayMap<String, Long> testMap = new ArrayMap<>(); rxLong.subscribe((c)->{ testMap.put(TEST_KEY, c);}); final long TEST_LONG = 23; observableLong.set(TEST_LONG); assertTrue(testMap.get(TEST_KEY).equals(TEST_LONG)); }
@Test public void convertsRxLongToObservable() throws Exception { long TEST_LONG = 234; Observable<Long> rxLong = Observable.just(TEST_LONG); ObservableLong observableLong = RxCinder.convertLong(rxLong); assertTrue(observableLong.get() == TEST_LONG); }
ObservableLongObservable(ObservableLong observableLong) { this.observableLong = observableLong; }
public static Observable<Long> convert(ObservableLong observableLong){ return Observable.create((e)-> Cinder.observe(()->e.onNext(observableLong.get()), observableLong) ); }
public static ObservableLong convertLong(Observable<Long> observable){ ObservableLong observableLong = new ObservableLong(); observable.subscribe((l)->observableLong.set(l)); return observableLong; }
@NonNull public ObservableLong getElapsedTime() { return mElapsedTime; }
/** * Create an observable of property change events on {@code observableLong}. * <p> * <em>Warning:</em> The created observable keeps a strong reference to {@code observableLong}. * Unsubscribe to free this reference. */ @CheckResult @NonNull // public static Observable<Long> propertyChanges(@NonNull ObservableLong observableLong) { checkNotNull(observableLong, "observableLong == null"); return new ObservableLongObservable(observableLong); }