public final class

EspressoOptional<T>

extends java.lang.Object

 java.lang.Object

↳androidx.test.espresso.util.EspressoOptional<T>

Gradle dependencies

compile group: 'androidx.test.espresso', name: 'espresso-core', version: '3.5.0-alpha06'

  • groupId: androidx.test.espresso
  • artifactId: espresso-core
  • version: 3.5.0-alpha06

Artifact androidx.test.espresso:espresso-core:3.5.0-alpha06 it located at Google repository (https://maven.google.com/)

Androidx artifact mapping:

androidx.test.espresso:espresso-core com.android.support.test.espresso:espresso-core

Androidx class mapping:

androidx.test.espresso.util.EspressoOptional android.support.test.espresso.util.EspressoOptional

Overview

This class is a wrapper around in order to avoid having public references to Guava API.

Summary

Methods
public static EspressoOptional<java.lang.Object>absent()

public java.util.Set<java.lang.Object>asSet()

public booleanequals(java.lang.Object object)

public static EspressoOptional<java.lang.Object>fromNullable(java.lang.Object nullableReference)

public java.lang.Objectget()

public inthashCode()

public booleanisPresent()

public static EspressoOptional<java.lang.Object>of(java.lang.Object reference)

public <any>or(<any> secondChoice)

public java.lang.Objector(<any> supplier)

public java.lang.ObjectorNull()

public static java.lang.Iterable<java.lang.Object>presentInstances(java.lang.Iterable<> optionals)

public java.lang.StringtoString()

public <any>transform(<any> function)

from java.lang.Objectclone, finalize, getClass, notify, notifyAll, wait, wait, wait

Methods

public static EspressoOptional<java.lang.Object> of(java.lang.Object reference)

public static EspressoOptional<java.lang.Object> absent()

public static EspressoOptional<java.lang.Object> fromNullable(java.lang.Object nullableReference)

public boolean isPresent()

public java.lang.Object get()

public <any> or(<any> secondChoice)

public java.lang.Object or(<any> supplier)

public java.lang.Object orNull()

public java.util.Set<java.lang.Object> asSet()

public boolean equals(java.lang.Object object)

public int hashCode()

public java.lang.String toString()

public <any> transform(<any> function)

public static java.lang.Iterable<java.lang.Object> presentInstances(java.lang.Iterable<> optionals)

Source

/*
 * Copyright (C) 2018 The Android Open Source Project
 *
 * Licensed 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
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * 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 androidx.test.espresso.util;

import com.google.common.annotations.Beta;
import com.google.common.base.Function;
import com.google.common.base.Optional;
import com.google.common.base.Supplier;
import java.util.Set;

/**
 * This class is a wrapper around {@link com.google.common.base.Optional} in order to avoid having
 * public references to Guava API.
 *
 * @param <T> the type of instance that can be contained. {@code Optional} is naturally covariant on
 *     this type, so it is safe to cast an {@code Optional<T>} to {@code Optional<S>} for any
 *     supertype {@code S} of {@code T}.
 * @see com.google.common.base.Optional
 */
public final class EspressoOptional<T> {

  private final Optional<T> delegate;

  public static <T> EspressoOptional<T> of(T reference) {
    return new EspressoOptional<>(Optional.of(reference));
  }

  public static <T> EspressoOptional<T> absent() {
    return new EspressoOptional<T>(Optional.absent());
  }

  public static <T> EspressoOptional<T> fromNullable(T nullableReference) {
    return new EspressoOptional<>(Optional.fromNullable(nullableReference));
  }

  private EspressoOptional(Optional<T> op) {
    delegate = op;
  }

  public boolean isPresent() {
    return delegate.isPresent();
  }

  public T get() {
    return delegate.get();
  }

  public Optional<T> or(Optional<? extends T> secondChoice) {
    return delegate.or(secondChoice);
  }

  public T or(Supplier<? extends T> supplier) {
    return delegate.or(supplier);
  }

  public T or(T defaultValue) {
    return delegate.or(defaultValue);
  }

  public T orNull() {
    return delegate.orNull();
  }

  public Set<T> asSet() {
    return delegate.asSet();
  }

  @Override
  public boolean equals(Object object) {
    if (object instanceof EspressoOptional) {
      EspressoOptional<?> other = (EspressoOptional<?>) object;
      return other.delegate.equals(this.delegate);
    }
    return false;
  }

  @Override
  public int hashCode() {
    return delegate.hashCode();
  }

  @Override
  public String toString() {
    return delegate.toString();
  }

  public <V> Optional<V> transform(Function<? super T, V> function) {
    return delegate.transform(function);
  }

  @Beta
  public static <T> Iterable<T> presentInstances(
      final Iterable<? extends Optional<? extends T>> optionals) {
    return Optional.presentInstances(optionals);
  }

  private static final long serialVersionUID = 0;
}