what-the-bank/sources/com/google/common/base/Present.java

83 lines
2.5 KiB
Java
Raw Permalink Normal View History

2024-07-27 18:17:47 +07:00
package com.google.common.base;
import java.util.Collections;
import java.util.Set;
/* JADX INFO: Access modifiers changed from: package-private */
/* 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 final boolean isPresent() {
return true;
}
/* JADX INFO: Access modifiers changed from: package-private */
public Present(T t) {
this.reference = t;
}
@Override // com.google.common.base.Optional
public final 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 final Optional<T> or(Optional<? extends T> optional) {
Preconditions.checkNotNull(optional);
return this;
}
@Override // com.google.common.base.Optional
public final T or(Supplier<? extends T> supplier) {
Preconditions.checkNotNull(supplier);
return this.reference;
}
@Override // com.google.common.base.Optional
public final Set<T> asSet() {
return Collections.singleton(this.reference);
}
@Override // com.google.common.base.Optional
public final <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 final boolean equals(Object obj) {
if (obj instanceof Present) {
return this.reference.equals(((Present) obj).reference);
}
return false;
}
@Override // com.google.common.base.Optional
public final int hashCode() {
return this.reference.hashCode() + 1502476572;
}
@Override // com.google.common.base.Optional
public final String toString() {
String valueOf = String.valueOf(this.reference);
StringBuilder sb = new StringBuilder(String.valueOf(valueOf).length() + 13);
sb.append("Optional.of(");
sb.append(valueOf);
sb.append(")");
return sb.toString();
}
@Override // com.google.common.base.Optional
public final T orNull() {
return this.reference;
}
@Override // com.google.common.base.Optional
public final T get() {
return this.reference;
}
}