a list of Boolean operators
The source of the original data is Boolean operation, after the Boolean operation, the receiver is the data received by the Observer is a Boolean value.
name |
parsing |
All () |
To determine whether all data items meet a condition |
Contains () |
To determine whether observable will emit a specified value |
IsEmpty () |
To determine if observable fired a value. |
SequenceEqual () |
To determine if the sequence of two observables launches is equal. |
Two, Boolean operators
2.1 All operator
The data of the transmitting source is received in all, and if the false is returned, the launch is terminated and the observer is fired. Return true to wait for the launch source to launch the real to the observer.
/**
* Determines whether all data items meet a certain condition/
private void Testall () {
observable.just ("1", "2")
. All (New predicate <String> () {
@Override public
boolean test (@NonNull String s) throws Exception {
log.e (TAG, ' all: ' +s) ;
return false;
return true;
}
}). Subscribe (new consumer<boolean> () {
@Override public
void Accept (@NonNull Boolean Aboolean) throws Exception {
log.e (TAG, "Accept:" +aboolean);
}
);
All returns the output of the true time
03-02 18:31:06.762 23478-23478/cn.com.minstone.rxjavalearn e/booleanactivity@@: all:1
03-02 18:31:06.762 23478-23478/cn.com.minstone.rxjavalearn e/booleanactivity@@: All:2
03-02 18:31:06.762 23478-23478/ Cn.com.minstone.rxjavalearn e/booleanactivity@@: Accept:true
All returns are the output of the false time:
03-02 18:31:06.762 23478-23478/cn.com.minstone.rxjavalearn e/booleanactivity@@: all:1
03-02 18:31:06.762 23478-23478/cn.com.minstone.rxjavalearn e/booleanactivity@@: Accept:false
2.2 contains operator
To judge the launch of the data there is no specified data, there will be launched really slightly, not fake slightly.
private void Testcontains () {
observable.just ("1", "2")
. Contains ("2")
. Subscribe (New consumer< Boolean> () {
@Override public
void Accept (@NonNull Boolean Aboolean) throws Exception {
log.e (TAG, " Accept: "+aboolean);}"
;}
Output:
03-02 18:34:30.393 23937-23937/cn.com.minstone.rxjavalearn e/booleanactivity@@: accept:true
2.3 IsEmpty operator
To determine whether the data fired is empty
private void Testisempty () {
observable.just ("1", "2")
. IsEmpty ()
. Subscribe (New Consumer<boolean > () {
@Override public
void Accept (@NonNull Boolean Aboolean) throws Exception {
log.e (TAG, "Accept:" + Aboolean);}}
Output:
03-02 18:39:56.288 24787-24787/cn.com.minstone.rxjavalearn e/booleanactivity@@: Accept:false
If the following is the case, the output is true:
private void Testisempty () {
observable.empty ()
. IsEmpty ().
Subscribe (new consumer<boolean> () {
@Override public
void Accept (@NonNull Boolean Aboolean) throws Exception {
log.e (TAG, "Accept:" +aboolean) ;
}
});
}
2.4 sequenceequal operator
Determine whether the sequence of two observables launches is equal.
private void Testsequenceequal () {
observable.sequenceequal (observable.just ("1"), Observable.just ("1"))
. Subscribe (New consumer<boolean> () {
@Override public
void Accept (@NonNull Boolean Aboolean) throws Exception {
log.e (TAG, "Accept:" +aboolean);
}
);
The above code output is true:
03-02 18:42:48.074 25535-25535/cn.com.minstone.rxjavalearn e/booleanactivity@@: accept:true
The following is the output of false:
private void Testsequenceequal () {
observable.sequenceequal (observable.just ("1"), Observable.just ("1", "2"))
. Subscribe (New consumer<boolean> () {
@Override public
void Accept (@NonNull Boolean Aboolean) Throws Exception {
log.e (TAG, "Accept: +aboolean";}
}
);