what-the-bank/sources/io/grpc/Attributes.java

155 lines
4.4 KiB
Java
Raw Normal View History

2024-07-27 18:17:47 +07:00
package io.grpc;
import com.google.common.base.Objects;
import com.google.common.base.Preconditions;
import java.util.Collections;
import java.util.IdentityHashMap;
import java.util.Map;
import java.util.Set;
/* loaded from: classes6.dex */
public final class Attributes {
static final boolean $assertionsDisabled = false;
public static final Attributes EMPTY = new Attributes(Collections.emptyMap());
private final Map<Key<?>, Object> data;
private Attributes(Map<Key<?>, Object> map) {
this.data = map;
}
public final <T> T get(Key<T> key) {
return (T) this.data.get(key);
}
@Deprecated
public final Set<Key<?>> keys() {
return Collections.unmodifiableSet(this.data.keySet());
}
final Set<Key<?>> keysForTest() {
return Collections.unmodifiableSet(this.data.keySet());
}
@Deprecated
public static Builder newBuilder(Attributes attributes) {
Preconditions.checkNotNull(attributes, "base");
return new Builder();
}
public static Builder newBuilder() {
return new Builder();
}
public final Builder toBuilder() {
return new Builder();
}
/* loaded from: classes6.dex */
public static final class Key<T> {
private final String debugString;
private Key(String str) {
this.debugString = str;
}
@Deprecated
public static <T> Key<T> of(String str) {
return new Key<>(str);
}
public static <T> Key<T> create(String str) {
return new Key<>(str);
}
public final String toString() {
return this.debugString;
}
}
public final String toString() {
return this.data.toString();
}
public final boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null || getClass() != obj.getClass()) {
return false;
}
Attributes attributes = (Attributes) obj;
if (this.data.size() != attributes.data.size()) {
return false;
}
for (Map.Entry<Key<?>, Object> entry : this.data.entrySet()) {
if (!attributes.data.containsKey(entry.getKey()) || !Objects.equal(entry.getValue(), attributes.data.get(entry.getKey()))) {
return false;
}
}
return true;
}
public final int hashCode() {
int i = 0;
for (Map.Entry<Key<?>, Object> entry : this.data.entrySet()) {
i += Objects.hashCode(entry.getKey(), entry.getValue());
}
return i;
}
/* loaded from: classes6.dex */
public static final class Builder {
static final boolean $assertionsDisabled = false;
private Attributes base;
private Map<Key<?>, Object> newdata;
private Builder(Attributes attributes) {
this.base = attributes;
}
private Map<Key<?>, Object> data(int i) {
if (this.newdata == null) {
this.newdata = new IdentityHashMap(i);
}
return this.newdata;
}
/* JADX WARN: Multi-variable type inference failed */
public final <T> Builder set(Key<T> key, T t) {
data(1).put(key, t);
return this;
}
public final <T> Builder discard(Key<T> key) {
if (this.base.data.containsKey(key)) {
IdentityHashMap identityHashMap = new IdentityHashMap(this.base.data);
identityHashMap.remove(key);
this.base = new Attributes(identityHashMap);
}
Map<Key<?>, Object> map = this.newdata;
if (map != null) {
map.remove(key);
}
return this;
}
public final Builder setAll(Attributes attributes) {
data(attributes.data.size()).putAll(attributes.data);
return this;
}
public final Attributes build() {
if (this.newdata != null) {
for (Map.Entry entry : this.base.data.entrySet()) {
if (!this.newdata.containsKey(entry.getKey())) {
this.newdata.put((Key) entry.getKey(), entry.getValue());
}
}
this.base = new Attributes(this.newdata);
this.newdata = null;
}
return this.base;
}
}
}