use of com.oath.cyclops.util.box.Mutable in project cyclops by aol.
the class MutableShortTest method externalMapInputObj.
@Test
public void externalMapInputObj() {
value = 0;
Mutable<Short> ext = MutableShort.fromExternal(() -> value, v -> this.value = v).mapInputToObj(s -> new Short((short) (s + ten)));
ext.set((short) 50);
assertThat(value, equalTo((short) 60));
}
use of com.oath.cyclops.util.box.Mutable in project cyclops by aol.
the class MutableByteTest method externalMapInputObj.
@Test
public void externalMapInputObj() {
value = 0;
Mutable<Byte> ext = MutableByte.fromExternal(() -> value, v -> this.value = v).mapInputToObj(s -> new Byte((byte) (s + ten)));
ext.set((byte) 50);
assertThat(value, equalTo((byte) 60));
}
use of com.oath.cyclops.util.box.Mutable in project cyclops by aol.
the class MutableFloatTest method externalMapInputObj.
@Test
public void externalMapInputObj() {
value = 0;
Mutable<Float> ext = MutableFloat.fromExternal(() -> value, v -> this.value = v).mapInputToObj(s -> new Float((float) (s + ten)));
ext.set((float) 50);
assertThat(value, equalTo((float) 60));
}
use of com.oath.cyclops.util.box.Mutable in project cyclops by aol.
the class Future method subscribe.
@Override
public final void subscribe(final Subscriber<? super T> sub) {
Mutable<Future<T>> future = Mutable.of(this);
sub.onSubscribe(new Subscription() {
AtomicBoolean running = new AtomicBoolean(true);
AtomicBoolean cancelled = new AtomicBoolean(false);
@Override
public void request(final long n) {
if (n < 1) {
sub.onError(new IllegalArgumentException("3.9 While the Subscription is not cancelled, Subscription.request(long n) MUST throw a java.lang.IllegalArgumentException if the argument is <= 0."));
}
if (!running.compareAndSet(true, false)) {
return;
}
future.mutate(f -> f.peek(sub::onNext).recover(t -> {
sub.onError(t);
return null;
}).peek(i -> sub.onComplete()));
}
@Override
public void cancel() {
cancelled.set(true);
future.get().cancel();
}
});
}
Aggregations