Java Code Examples for io.reactivex.annotations.Nullable

The following are top voted examples for showing how to use io.reactivex.annotations.Nullable. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: RxJava2Debug   File: StackTraceUtils.java   Source Code and License 6 votes vote down vote up
/**
 * Extract StackTrace and filter to show an app-specific entry at its top
 *
 * @param exception RxJavaAssemblyException to be parsed
 * @return StackTrace, filtered so a app-specific line is at the top of it
 */
@NonNull
static StackTraceElement[] parseStackTrace(@NonNull RxJavaAssemblyException exception, @Nullable String[] basePackages) {
    String[] lines = exception.stacktrace()
            .split(NEW_LINE_REGEX);

    List<StackTraceElement> stackTrace = new ArrayList<StackTraceElement>();
    boolean filterIn = false;
    for (String line : lines) {
        filterIn = filterIn
                || basePackages == null
                || basePackages.length == 0
                || startsWithAny(line, basePackages);
        if (filterIn) {
            StackTraceElement element = parseStackTraceLine(line);
            if (element != null) {
                stackTrace.add(element);
            }
        }
    }

    return stackTrace.toArray(new StackTraceElement[0]);
}
 
Example 2
Project: delern   File: DeckViewHolder.java   Source Code and License 6 votes vote down vote up
/**
 * Set deck object currently associated with this ViewHolder.
 *
 * @param deck Deck or null if ViewHolder is being recycled.
 */
public void setDeck(@Nullable final Deck deck) {
    if (deck == null) {
        mResources.clear();
    } else {
        mDeckTextView.setText(deck.getName());
        mResources.add(deck.fetchDeckAccessOfUser().subscribe(v -> mDeckAccess = v));
        mResources.add(Deck.fetchCount(
                deck.fetchCardsToRepeatWithLimitQuery(CARDS_COUNTER_LIMIT + 1))
                .subscribe((final Long cardsCount) -> {
                    if (cardsCount <= CARDS_COUNTER_LIMIT) {
                        mCountToLearnTextView.setText(String.valueOf(cardsCount));
                    } else {
                        String tooManyCards = CARDS_COUNTER_LIMIT + "+";
                        mCountToLearnTextView.setText(tooManyCards);
                    }
                }));
    }
}
 
Example 3
Project: delern   File: CardViewHolder.java   Source Code and License 6 votes vote down vote up
/**
 * Set Card object currently associated with this ViewHolder.
 *
 * @param card Card or null if ViewHolder is being recycled.
 */
@SuppressWarnings("deprecation" /* fromHtml(String, int) not available before API 24 */)
public void setCard(@Nullable final Card card) {
    mCard = card;
    if (card != null) {
        if (card.getDeck().isMarkdown()) {
            mFrontTextView.setText(Html.fromHtml(card.getFront()));
            mBackTextView.setText(Html.fromHtml(card.getBack()));
        } else {
            mFrontTextView.setText(card.getFront());
            mBackTextView.setText(card.getBack());
        }
        mCardView.setCardBackgroundColor(ContextCompat.getColor(itemView.getContext(),
                CardColor.getColor(card.specifyContentGender())));
    }
}
 
Example 4
Project: RxJava2Debug   File: StackTraceUtils.java   Source Code and License 5 votes vote down vote up
/**
 * Parse string containing a <i>single line</i> of a StackTrace
 *
 * @param stackTraceLine string containing single line of a StackTrace
 * @return parsed StackTraceElement
 */
@Nullable
private static StackTraceElement parseStackTraceLine(@NonNull String stackTraceLine) {
    StackTraceElement retVal = null;

    Matcher matcher = STACK_TRACE_ELEMENT_PATTERN.matcher(stackTraceLine);
    if (matcher.matches()) {
        String clazz = matcher.group(1);
        String method = matcher.group(2);
        String filename = matcher.group(3);
        int line = Integer.valueOf(matcher.group(4));
        retVal = new StackTraceElement(clazz, method, filename, line);
    }
    return retVal;
}
 
Example 5
Project: RxJava2Debug   File: RxJava2Debug.java   Source Code and License 5 votes vote down vote up
/**
 * Obtain a copy of the original Throwable with an extended StackTrace
 * @param original Original Throwable
 * @return new Throwable with enhanced StackTrace if information was found. <i>null</i> otherwise
 */
public static @Nullable Throwable getEnhancedStackTrace(Throwable original) {
    Throwable enhanced = original;

    RxJavaAssemblyException assembledException = RxJavaAssemblyException.find(original);
    if (assembledException != null) {
        StackTraceElement[] clearStack = parseStackTrace(assembledException, basePackages);
        Throwable clearException = new Throwable();
        clearException.setStackTrace(clearStack);
        enhanced = setRootCause(original, clearException);
    }

    return enhanced;
}
 
Example 6
Project: RxCommand   File: RxCommand.java   Source Code and License 5 votes vote down vote up
/**
 * If the receiver is enabled, this method will:
 * <p>
 * 1. Invoke the `func` given at the time of creation.
 * 2. Multicast the returned observable.
 * 3. Send the multicasted observable on {@link #executionObservables()}.
 * 4. Subscribe (connect) to the original observable on the main thread.
 *
 * @param input The input value to pass to the receiver's `func`. This may be null.
 * @return the multicasted observable, after subscription. If the receiver is not
 * enabled, returns a observable that will send an error.
 */
@MainThread
public final Observable<T> execute(@Nullable Object input) {
    boolean enabled = mImmediateEnabled.blockingFirst();
    if (!enabled) {
        return Observable.error(new IllegalStateException("The command is disabled and cannot be executed"));
    }
    try {
        Observable<T> observable = mFunc.apply(input);
        if (observable == null) {
            throw new RuntimeException(String.format("null Observable returned from observable func for value %s", input));
        }

        // This means that `executing` and `enabled` will send updated values before
        // the observable actually starts performing work.
        final ConnectableObservable<T> connection = observable
                .subscribeOn(AndroidSchedulers.mainThread())
                .replay();

        mAddedExecutionObservableSubject.onNext(connection);
        connection.connect();
        return connection;
    } catch (Exception e) {
        e.printStackTrace();
        return Observable.error(e);
    }
}
 
Example 7
Project: PSNine   File: HtmlImageGetter.java   Source Code and License 5 votes vote down vote up
public HtmlImageGetter(Context context, @Nullable TextView tv) {
    this.context = context;
    this.tv = tv;
    DisplayMetrics dm = context.getResources().getDisplayMetrics();
    w_screen = dm.widthPixels;
    h_screen = dm.heightPixels;
}
 
Example 8
Project: smart-lens   File: BaseButton.java   Source Code and License 5 votes vote down vote up
/**
 * Get the font based on the text style.
 *
 * @return font file name.
 */
String getFont(@Nullable Typeface typeface) {
    switch (typeface != null ? typeface.getStyle() : Typeface.NORMAL) {
        case Typeface.BOLD_ITALIC:
            return String.format(Locale.US, "fonts/%s", "OpenSans-BoldItalic.ttf");
        case Typeface.ITALIC:
            return String.format(Locale.US, "fonts/%s", "OpenSans-Italic.ttf");
        case Typeface.BOLD:
            return String.format(Locale.US, "fonts/%s", "OpenSans-Bold.ttf");
        default:
        case Typeface.NORMAL:
            return String.format(Locale.US, "fonts/%s", "OpenSans-Regular.ttf");
    }
}
 
Example 9
Project: ActivityRx   File: State.java   Source Code and License 5 votes vote down vote up
public State(
        @NonNull final String id,
        @NonNull final On on,
        @Nullable final A ui,
        @Nullable final Bundle arg) {
    this.id = id;
    this.on = on;
    this.ui = ui;
    this.arg = arg;
}
 
Example 10
Project: ActivityRx   File: Activities.java   Source Code and License 5 votes vote down vote up
@SuppressWarnings("unchecked")
private static void setState(
        @NonNull String id,
        @NonNull On on,
        @Nullable Activity activity,
        @Nullable Bundle bundle) {

    State<? extends Activity> newState = new State<>(id, on, activity, bundle);
    EVENTS.onNext(newState);

    Iterator<State<? extends Activity>> iterator = STATES.iterator();
    while (iterator.hasNext()) {
        if (iterator.next().id.equals(id)) {
            iterator.remove();
            break;
        }
    }
    if (newState.on != On.DESTROY) {
        STATES.add(newState);
    }

    for (Map.Entry<String, LinkedHashSet<ObservableEmitter>> subscription : EMITTERS.entrySet()) {
        if (subscription.getKey().equals(id)) {
            BUFFER.addAll(subscription.getValue());
        }
    }
    for (ObservableEmitter emitter : BUFFER) {
        emitter.onNext(newState);
    }
    BUFFER.clear();
}
 
Example 11
Project: webtrekk-android-sdk   File: WebtrekkBaseSDKTest.java   Source Code and License 5 votes vote down vote up
protected void waitForFinishedCampaignProcess(@Nullable final Runnable callback){
    Completable.create(new CompletableOnSubscribe() {
        @Override
        public void subscribe(@NonNull CompletableEmitter completableEmitter) throws Exception {
            while (!isCampaignProcessFinished()){
                InstrumentationRegistry.getInstrumentation().waitForIdleSync();
            }
            if (callback != null) {
                callback.run();
            }
            completableEmitter.onComplete();
        }
    }).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread())
            .blockingAwait(130, TimeUnit.SECONDS);
}
 
Example 12
Project: delern   File: UserDeckAccessViewHolder.java   Source Code and License 5 votes vote down vote up
/**
 * Set DeckAccess for this item.
 *
 * @param deckAccess DeckAccess or null if the view is being recycled.
 */
public void setDeckAccess(@Nullable final DeckAccess deckAccess) {
    if (deckAccess == null) {
        mUserDisposable.dispose();
    } else {
        mUserDisposable = deckAccess.fetchChild(
                deckAccess.getChildReference(User.class), User.class)
                .subscribe((final User user) -> {
                    mNameTextView.setText(user.getName());
                    Context context = itemView.getContext();
                    Picasso.with(context)
                            .load(user.getPhotoUrl())
                            .error(android.R.color.holo_green_dark)
                            .placeholder(R.drawable.splash_screen)
                            .into(mProfilePhoto);
                    if ("owner".equals(deckAccess.getAccess())) {
                        mSharingPermissionsSpinner
                                .setType(R.array.owner_access_spinner_text,
                                        R.array.owner_access_spinner_img);
                    } else {
                        mSharingPermissionsSpinner
                                .setType(R.array.user_permissions_spinner_text,
                                        R.array.share_permissions_spinner_img);
                        mSharingPermissionsSpinner
                                .setSelection(mPresenter
                                        .setUserAccessPositionForSpinner(deckAccess));
                        mSharingPermissionsSpinner
                                .setOnItemSelectedListener(access ->
                                        mPresenter.changeUserPermission(access, deckAccess));
                    }
                });
    }
}
 
Example 13
Project: delern   File: Model.java   Source Code and License 5 votes vote down vote up
/**
 * Parse model from a database snapshot using getValue().
 *
 * @param snapshot a snapshot pointing to model data (not the list of models).
 * @param cls      a model class, e.g. Card.class or card.getClass().
 * @param parent   a parent model. See Model constructor for limitations.
 * @param <T>      an Model subclass.
 * @return an instance of T with key and parent set, or null.
 */
@Nullable
public static <T extends Model> T fromSnapshot(final DataSnapshot snapshot,
                                               final Class<T> cls,
                                               final Model parent) {
    T model = snapshot.getValue(cls);
    if (model != null) {
        model.setKey(snapshot.getKey());
        model.setParent(parent);
        model.setReference(snapshot.getRef());
    }
    return model;
}
 
Example 14
Project: delern   File: Card.java   Source Code and License 5 votes vote down vote up
/**
 * Get the ScheduledCard this Card is associated with.
 *
 * @return Model parent casted to ScheduledCard (if set).
 */
@Exclude
@Nullable
public ScheduledCard getScheduledCard() {
    Model parent = getParent();
    if (parent instanceof ScheduledCard) {
        return (ScheduledCard) parent;
    }
    return null;
}
 
Example 15
Project: rxfirebase   File: RxValue.java   Source Code and License 5 votes vote down vote up
/**
 * @param emitter
 * @param function
 * @return
 */
@NonNull
@CheckReturnValue
public static Transaction.Handler transaction(
        @NonNull final SingleEmitter<DataSnapshot> emitter,
        @NonNull final Function<MutableData, Transaction.Result> function) {
    return new Transaction.Handler() {
        @Override
        public Transaction.Result doTransaction(MutableData mutableData) {
            try {
                return function.apply(mutableData);
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }

        @Override
        public void onComplete(@Nullable DatabaseError databaseError,
                               boolean committed,
                               @NonNull DataSnapshot dataSnapshot) {
            if (!emitter.isDisposed()) {
                if (null == databaseError) {
                    emitter.onSuccess(dataSnapshot);
                } else {
                    emitter.onError(databaseError.toException());
                }
            }
        }
    };
}
 
Example 16
Project: rxfirebase   File: RxFirebaseStorage.java   Source Code and License 5 votes vote down vote up
/**
 * @see StorageReference#putFile(Uri, StorageMetadata, Uri)
 */
@CheckReturnValue
@NonNull
public static Single<UploadTask.TaskSnapshot> putFile(
        @NonNull final StorageReference ref,
        @NonNull final Uri uri,
        @Nullable final StorageMetadata storageMetadata,
        @Nullable final Uri existingUploadUri) {
    return RxTask.single(new Callable<Task<UploadTask.TaskSnapshot>>() {
        @Override
        public Task<UploadTask.TaskSnapshot> call() throws Exception {
            return ref.putFile(uri, storageMetadata, existingUploadUri);
        }
    });
}
 
Example 17
Project: RxDownloader   File: RxDownloader.java   Source Code and License 5 votes vote down vote up
private DownloadManager.Request createRequest(@NonNull String url,
                                              @NonNull String filename,
                                              @Nullable String destinationPath,
                                              @NonNull String mimeType,
                                              boolean inPublicDir,
                                              boolean showCompletedNotification) {

    DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
    request.setDescription(filename);
    request.setMimeType(mimeType);

    if (destinationPath == null) {
        destinationPath = Environment.DIRECTORY_DOWNLOADS;
    }

    File destinationFolder = inPublicDir
            ? Environment.getExternalStoragePublicDirectory(destinationPath)
            : new File(context.getFilesDir(), destinationPath);

    createFolderIfNeeded(destinationFolder);
    removeDuplicateFileIfExist(destinationFolder, filename);

    if (inPublicDir) {
        request.setDestinationInExternalPublicDir(destinationPath, filename);
    } else {
        request.setDestinationInExternalFilesDir(context, destinationPath, filename);
    }

    request.setNotificationVisibility(showCompletedNotification
            ? DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED
            : DownloadManager.Request.VISIBILITY_VISIBLE);

    return request;
}
 
Example 18
Project: commcare-core   File: FormController.java   Source Code and License 5 votes vote down vote up
/**
 * Retrieves the index of the Group which hosts child index and is marked with given appearanceTag, null otherwise
 */
@Nullable
private FormIndex getHostWithAppearance(FormIndex child, String appearanceTag) {
    int event = mFormEntryController.getModel().getEvent(child);

    if (event == FormEntryController.EVENT_QUESTION || event == FormEntryController.EVENT_GROUP || event == FormEntryController.EVENT_REPEAT) {
        // caption[0..len-1]
        // caption[len-1] == the event itself
        // caption[len-2] == the groups containing this group
        FormEntryCaption[] captions = mFormEntryController.getModel().getCaptionHierarchy(child);

        //This starts at the beginning of the heirarchy, so it'll catch the top-level
        //host index.
        for (FormEntryCaption caption : captions) {
            FormIndex parentIndex = caption.getIndex();
            if (mFormEntryController.isHostWithAppearance(parentIndex, appearanceTag)) {
                return parentIndex;
            }
        }

        //none of this node's parents are marked with appearanceTag
        return null;

    } else {
        // Non-host elements can't have hosts marked as appearanceTag .
        return null;
    }
}
 
Example 19
Project: commcare-core   File: XPathAccumulatingAnalyzer.java   Source Code and License 5 votes vote down vote up
@Nullable
public Set<T> accumulate(XPathAnalyzable rootExpression) {
    try {
        rootExpression.applyAndPropagateAnalyzer(this);
        Set<T> set = new HashSet<>();
        for (T item : aggregateResults(new ArrayList<T>())) {
            set.add(item);
        }
        return set;
    } catch (AnalysisInvalidException e) {
        return null;
    }
}
 
Example 20
Project: commcare-core   File: XPathAccumulatingAnalyzer.java   Source Code and License 5 votes vote down vote up
@Nullable
public List<T> accumulateAsList(XPathAnalyzable rootExpression) {
    try {
        rootExpression.applyAndPropagateAnalyzer(this);
        return aggregateResults(new ArrayList<T>());
    } catch (AnalysisInvalidException e) {
        return null;
    }
}
 
Example 21
Project: Blackboard   File: Blackboard.java   Source Code and License 4 votes vote down vote up
/**
 * @return the current url prefix, or null if none has been set
 */
@Nullable
public String getUrl() {
    return prefs.getString(PREF_URL, null);
}
 
Example 22
Project: RxRedux   File: Result.java   Source Code and License 4 votes vote down vote up
@Nullable
static <B> Result<B> loadingResult() {
    return new Result<>(true, null, false, Pair.<String, B>create("", null));
}
 
Example 23
Project: RxRedux   File: Result.java   Source Code and License 4 votes vote down vote up
@Nullable
static <B> Result<B> throwableResult(Throwable error) {
    return new Result<>(false, error, false, Pair.<String, B>create("", null));
}
 
Example 24
Project: KotlinKomparisons   File: LoginDetails.java   Source Code and License 4 votes vote down vote up
public LoginDetails(@Nullable final String email, @Nullable final String username) {
    this.email = email;
    this.username = username;
}
 
Example 25
Project: KotlinKomparisons   File: LoginDetails.java   Source Code and License 4 votes vote down vote up
public @Nullable String getEmail() {
    return email;
}
 
Example 26
Project: KotlinKomparisons   File: LoginDetails.java   Source Code and License 4 votes vote down vote up
public @Nullable String getUsername() {
    return username;
}
 
Example 27
Project: rxtools   File: Optional.java   Source Code and License 4 votes vote down vote up
@SuppressWarnings("unchecked")
public static <T> Optional<T> ofNullable(@Nullable T value)
{
    return value == null ? (Optional<T>) empty() : of(value);
}
 
Example 28
Project: pandroid   File: RxLifecycleDelegate.java   Source Code and License 4 votes vote down vote up
@RxModel(targets = {PandroidDelegateProvider.class})
public static <T> MainObserverTransformer<T> bindLifecycleObserveOnMain(@Nullable PandroidDelegateProvider provider) {
    return new MainObserverTransformer<>(provider);
}
 
Example 29
Project: RxJava2Extensions   File: RxJavaProtocolValidator.java   Source Code and License 4 votes vote down vote up
/**
 * Returns the current custom violation callback handler.
 * @return the current custom violation callback handler or null if not set
 */
@Nullable
public static PlainConsumer<ProtocolNonConformanceException> getOnViolationHandler() {
    return onViolation;
}
 
Example 30
Project: EasyMVP   File: SingleUseCase.java   Source Code and License 4 votes vote down vote up
@Override
public Single<R> execute(@Nullable Q param) {
    return interact(param).compose(getSchedulersTransformer());
}
 
Example 31
Project: EasyMVP   File: SingleUseCase.java   Source Code and License 4 votes vote down vote up
@Override
protected abstract Single<R> interact(@Nullable Q param);
 
Example 32
Project: rx-mqtt   File: RxMqtt.java   Source Code and License 4 votes vote down vote up
public static Maybe<IMqttToken> reconnect(
        @NonNull final MqttAndroidClient client,
        @NonNull final MqttConnectOptions options,
        @Nullable final DisconnectedBufferOptions bufferOptions) {
    return connect(client, options, bufferOptions);
}
 
Example 33
Project: rx-mqtt   File: RxMqtt.java   Source Code and License 4 votes vote down vote up
@Nullable
@Override
public MqttException getException() {
    // nothing
    return null;
}
 
Example 34
Project: rx-mqtt   File: RxMqtt.java   Source Code and License 4 votes vote down vote up
@Override
@Nullable
public IMqttActionListener getActionCallback() {
    // nothing
    return null;
}
 
Example 35
Project: rx-mqtt   File: RxMqtt.java   Source Code and License 4 votes vote down vote up
@Override
@Nullable
public IMqttAsyncClient getClient() {
    // nothing
    return null;
}
 
Example 36
Project: rx-mqtt   File: RxMqtt.java   Source Code and License 4 votes vote down vote up
@Override
@Nullable
public String[] getTopics() {
    // nothing
    return new String[0];
}
 
Example 37
Project: rx-mqtt   File: RxMqtt.java   Source Code and License 4 votes vote down vote up
@Override
@Nullable
public Object getUserContext() {
    // nothing
    return null;
}
 
Example 38
Project: rx-mqtt   File: RxMqtt.java   Source Code and License 4 votes vote down vote up
@Override
@Nullable
public int[] getGrantedQos() {
    // nothing
    return new int[0];
}
 
Example 39
Project: rx-mqtt   File: RxMqtt.java   Source Code and License 4 votes vote down vote up
@Override
@Nullable
public MqttWireMessage getResponse() {
    // nothing
    return null;
}
 
Example 40
Project: rxfirebase   File: ChildAddEvent.java   Source Code and License 4 votes vote down vote up
@Nullable
public String previousChildName() {
    return previousChildName;
}