1 package com.github.davidmoten.rx2;
2
3 import java.util.concurrent.atomic.AtomicBoolean;
4 import java.util.concurrent.atomic.AtomicInteger;
5
6 import io.reactivex.functions.Action;
7
8 public final class Actions {
9
10 private Actions() {
11
12 }
13
14 public static Action setToTrue(final AtomicBoolean b) {
15 return new Action() {
16
17 @Override
18 public void run() throws Exception {
19 b.set(true);
20 }
21
22 };
23 }
24
25 public static Action throwing(final Exception e) {
26 return new Action() {
27
28 @Override
29 public void run() throws Exception {
30 throw e;
31 }
32
33 };
34 }
35
36 public static Action doNothing() {
37 return DoNothingHolder.DO_NOTHING;
38 }
39
40 private static final class DoNothingHolder {
41 static final Action DO_NOTHING = new Action() {
42 @Override
43 public void run() throws Exception {
44
45 }
46 };
47 }
48
49 public static Action increment(final AtomicInteger x) {
50
51 return new Action() {
52
53 @Override
54 public void run() throws Exception {
55 x.incrementAndGet();
56 }
57 };
58 }
59
60 }