// Path: 2016-07-12_rxjava_in_action/src/main/java/com/androidhuman/example/rxjavainaction/error/ContentRatingError.java
// public final class ContentRatingError extends Error {
// 
// }


import com.androidhuman.example.rxjavainaction.error.ContentRatingError;
import com.androidhuman.example.rxjavainaction.model.Content;
import com.androidhuman.example.rxjavainaction.model.User;
import rx.Observable;
import rx.Subscriber;
package com.androidhuman.example.rxjavainaction.rx;



final class ChecksContentRatingOnSubscribe implements Observable.OnSubscribe<Void> {

    private final Content content;

    private final User user;

    ChecksContentRatingOnSubscribe(Content content, User user) {
        this.content = content;
        this.user = user;
    }

    @Override
    public void call(Subscriber<? super Void> subscriber) {
        if (!subscriber.isUnsubscribed()) {
            if (content.isAdult() && user.isAdult()) {
                // Content is available
                subscriber.onNext(null);
                subscriber.onCompleted();
            } else {
                // Content is not available; Rating is not suitable for user
// Path: 2016-07-12_rxjava_in_action/src/main/java/com/androidhuman/example/rxjavainaction/error/ContentRatingError.java
// public final class ContentRatingError extends Error {
// 
// }


// Path: 2016-07-12_rxjava_in_action/src/main/java/com/androidhuman/example/rxjavainaction/rx/ChecksContentRatingOnSubscribe.java
import com.androidhuman.example.rxjavainaction.error.ContentRatingError;
import com.androidhuman.example.rxjavainaction.model.Content;
import com.androidhuman.example.rxjavainaction.model.User;
import rx.Observable;
import rx.Subscriber;

package com.androidhuman.example.rxjavainaction.rx;



final class ChecksContentRatingOnSubscribe implements Observable.OnSubscribe<Void> {

    private final Content content;

    private final User user;

    ChecksContentRatingOnSubscribe(Content content, User user) {
        this.content = content;
        this.user = user;
    }

    @Override
    public void call(Subscriber<? super Void> subscriber) {
        if (!subscriber.isUnsubscribed()) {
            if (content.isAdult() && user.isAdult()) {
                // Content is available
                subscriber.onNext(null);
                subscriber.onCompleted();
            } else {
                // Content is not available; Rating is not suitable for user
                subscriber.onError(new ContentRatingError());