<commit_before>/*
 * Copyright (C) 2017 <NAME>
 * <p/>
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 * <p/>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p/>
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */
package com.anthonycr.bonsai;

import android.os.Looper;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;

/**
 * @param <ActionT>      The {@link ObservableAction} that will be provided
 *                       to the {@link OnSubscribeT} when the
 *                       consumer subscribes.
 * @param <OnSubscribeT> The {@link ObservableOnSubscribe} or type that
 *                       extends it that will be supplied when the consumer
 *                       subscribes.
 * @param <SubscriberT>  The {@link ObservableSubscriber} or type that
 *                       extends it that will be supplied to the {@link ObservableAction}
 *                       when the consumer subscribes.
 */
@SuppressWarnings("WeakerAccess")
public abstract class Observable<ActionT extends ObservableAction<SubscriberT>,
    OnSubscribeT extends ObservableOnSubscribe,
    SubscriberT extends ObservableSubscriber> {

    @NonNull private final ActionT action;
    @Nullable private Scheduler subscriberThread;
    @Nullable private Scheduler observerThread;
    @NonNull private final Scheduler defaultThread;

    protected Observable(@NonNull ActionT action) {
        this.action = action;
        this.defaultThread = getCurrentScheduler();
    }

    @NonNull
    private Scheduler getCurrentScheduler() {
        if (Looper.myLooper() == null) {
            Looper.prepare();
        }
        Looper looper = Looper.myLooper();
        Preconditions.checkNonNull(looper);

        return new ThreadScheduler(looper);
    }

    /**
     * Tells the observable what {@link Scheduler} that
     * the onSubscribe work should run on.
     *
     * @param subscribeScheduler the {@link Scheduler} to run the work on.
     */
    protected final void setActionScheduler(@NonNull Scheduler subscribeScheduler) {
        subscriberThread = subscribeScheduler;
    }

    /**
     * Tells the observable what {@link Scheduler} that
     * the onSubscribe should observe the work on.
     *
     * @param observerScheduler the {@link Scheduler} to run to callback on.
     */
    protected final void setObserverScheduler(@NonNull Scheduler observerScheduler) {
        observerThread = observerScheduler;<commit_msg>Replace getCurrentScheduler method with Schedulers.current which does the same thing<commit_after>/*
 * Copyright (C) 2017 <NAME>
 * <p/>
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 * <p/>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p/>
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */
package com.anthonycr.bonsai;

import android.os.Looper;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;

/**
 * @param <ActionT>      The {@link ObservableAction} that will be provided
 *                       to the {@link OnSubscribeT} when the
 *                       consumer subscribes.
 * @param <OnSubscribeT> The {@link ObservableOnSubscribe} or type that
 *                       extends it that will be supplied when the consumer
 *                       subscribes.
 * @param <SubscriberT>  The {@link ObservableSubscriber} or type that
 *                       extends it that will be supplied to the {@link ObservableAction}
 *                       when the consumer subscribes.
 */
@SuppressWarnings("WeakerAccess")
public abstract class Observable<ActionT extends ObservableAction<SubscriberT>,
    OnSubscribeT extends ObservableOnSubscribe,
    SubscriberT extends ObservableSubscriber> {

    @NonNull private final ActionT action;
    @Nullable private Scheduler subscriberThread;
    @Nullable private Scheduler observerThread;
    @NonNull private final Scheduler defaultThread;

    protected Observable(@NonNull ActionT action) {
        this.action = action;
        this.defaultThread = Schedulers.current();
    }

    /**
     * Tells the observable what {@link Scheduler} that
     * the onSubscribe work should run on.
     *
     * @param subscribeScheduler the {@link Scheduler} to run the work on.
     */
    protected final void setActionScheduler(@NonNull Scheduler subscribeScheduler) {
        subscriberThread = subscribeScheduler;
    }

    /**
     * Tells the observable what {@link Scheduler} that
     * the onSubscribe should observe the work on.
     *
     * @param observerScheduler the {@link Scheduler} to run to callback on.
     */
    protected final void setObserverScheduler(@NonNull Scheduler observerScheduler) {
        observerThread = observerScheduler;
{'fraction_non_alphanumeric': 0.07274539113104135, 'fraction_numerical': 0.0026573658860654377, 'mean_word_length': 3.0443250503693755, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '134900', 'n_tokens_mistral': 1501, 'n_tokens_neox': 1457, 'n_words': 597}