public class

Optional<T>

extends java.lang.Object

implements java.io.Serializable

 java.lang.Object

↳androidx.test.espresso.core.internal.deps.guava.base.Optional<T>

Gradle dependencies

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

  • groupId: androidx.test.espresso
  • artifactId: espresso-core
  • version: 3.6.1

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

Androidx artifact mapping:

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

Overview

Redefinition of Guava's Optional, created to avoid compatibilty breakages for users of EspressoOptional.

Summary

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

public booleanequals(java.lang.Object object)

public static Optional<java.lang.Object>fromNullable(java.lang.Object value)

public java.lang.Objectget()

public inthashCode()

public booleanisPresent()

public static Optional<java.lang.Object>of(java.lang.Object value)

public Optional<java.lang.Object>or(Optional<java.lang.Object> other)

public java.lang.Objector(Supplier<java.lang.Object> supplier)

public java.lang.Objector(java.lang.Object other)

public java.lang.ObjectorNull()

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

public Optional<java.lang.Object>transform(Function<java.lang.Object, java.lang.Object> function)

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

Methods

public static Optional<java.lang.Object> fromNullable(java.lang.Object value)

public static Optional<java.lang.Object> of(java.lang.Object value)

public int hashCode()

public Optional<java.lang.Object> or(Optional<java.lang.Object> other)

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

public java.lang.Object or(java.lang.Object other)

public Optional<java.lang.Object> transform(Function<java.lang.Object, java.lang.Object> function)

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

public java.lang.Object get()

public java.lang.Object orNull()

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

public boolean isPresent()

public boolean equals(java.lang.Object object)

Source

/*
 * Copyright (C) 2022 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.core.internal.deps.guava.base;

import static androidx.test.internal.util.Checks.checkNotNull;
import static java.util.Collections.emptySet;
import static java.util.Collections.singleton;

import androidx.annotation.Nullable;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;

/**
 * Redefinition of Guava's Optional, created to avoid compatibilty breakages for users of
 * EspressoOptional.
 *
 * @deprecated use androidx.annotation.Nullable instead
 */
@Deprecated
public class Optional<T> implements java.io.Serializable {

  @Nullable private final T value;

  private Optional(T value) {
    this.value = value;
  }

  public static <T> Optional<T> fromNullable(@Nullable T value) {
    return new Optional<>(value);
  }

  public static <T> Optional<T> of(T value) {
    return new Optional<>(checkNotNull(value));
  }

  @Override
  public int hashCode() {
    // copy the Guava implementation
    return isPresent() ? 0x598df91c + value.hashCode() : 0x79a31aac;
  }

  public Optional<T> or(Optional<T> other) {
    return isPresent() ? this : other;
  }

  public T or(Supplier<T> supplier) {
    return or(supplier.get());
  }

  public T or(T other) {
    return isPresent() ? value : other;
  }

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

  public static <T> Iterable<T> presentInstances(
      final Iterable<? extends Optional<? extends T>> optionals) {
    List<T> list = new ArrayList<>();
    for (Optional<? extends T> optional : optionals) {
      if (optional.isPresent()) {
        list.add(optional.get());
      }
    }
    return list;
  }

  public T get() {
    return checkNotNull(value);
  }

  public T orNull() {
    return value;
  }

  public Set<T> asSet() {
    return isPresent() ? singleton(value) : emptySet();
  }

  public boolean isPresent() {
    return value != null;
  }

  @Override
  public boolean equals(Object object) {
    if (object instanceof Optional) {
      Optional<?> other = (Optional<?>) object;
      if (isPresent()) {
        return value.equals(other.get());
      } else if (!other.isPresent()) {
        return true;
      }
    }
    return false;
  }

  private static final long serialVersionUID = 0;
}