Rabbit-R1/switch port/java/sources/com/google/common/base/Present.java
2024-05-21 17:08:36 -04:00

80 lines
2.4 KiB
Java

package com.google.common.base;
import java.util.Collections;
import java.util.Set;
import javax.annotation.CheckForNull;
/* JADX INFO: Access modifiers changed from: package-private */
@ElementTypesAreNonnullByDefault
/* loaded from: classes2.dex */
public final class Present<T> extends Optional<T> {
private static final long serialVersionUID = 0;
private final T reference;
@Override // com.google.common.base.Optional
public T get() {
return this.reference;
}
@Override // com.google.common.base.Optional
public boolean isPresent() {
return true;
}
@Override // com.google.common.base.Optional
public T orNull() {
return this.reference;
}
/* JADX INFO: Access modifiers changed from: package-private */
public Present(T t) {
this.reference = t;
}
@Override // com.google.common.base.Optional
public T or(T t) {
Preconditions.checkNotNull(t, "use Optional.orNull() instead of Optional.or(null)");
return this.reference;
}
@Override // com.google.common.base.Optional
public Optional<T> or(Optional<? extends T> optional) {
Preconditions.checkNotNull(optional);
return this;
}
@Override // com.google.common.base.Optional
public T or(Supplier<? extends T> supplier) {
Preconditions.checkNotNull(supplier);
return this.reference;
}
@Override // com.google.common.base.Optional
public Set<T> asSet() {
return Collections.singleton(this.reference);
}
@Override // com.google.common.base.Optional
public <V> Optional<V> transform(Function<? super T, V> function) {
return new Present(Preconditions.checkNotNull(function.apply(this.reference), "the Function passed to Optional.transform() must not return null."));
}
@Override // com.google.common.base.Optional
public boolean equals(@CheckForNull Object obj) {
if (obj instanceof Present) {
return this.reference.equals(((Present) obj).reference);
}
return false;
}
@Override // com.google.common.base.Optional
public int hashCode() {
return this.reference.hashCode() + 1502476572;
}
@Override // com.google.common.base.Optional
public String toString() {
String valueOf = String.valueOf(this.reference);
return new StringBuilder(String.valueOf(valueOf).length() + 13).append("Optional.of(").append(valueOf).append(")").toString();
}
}