Deferred class
Пакет: com.hypixel.hytale.codec.lookup
Файл: com/hypixel/hytale/codec/lookup/Deferred.java
Поля (6)
| Модификаторы | Тип | Имя |
|---|---|---|
|
Object |
var1 |
|
|
var1 |
|
|
var1 |
|
BsonDocument |
var1 |
|
BsonValue |
var2 |
|
BuilderCodec |
var3 |
Методы (9)
| Модификаторы | Возврат | Сигнатура |
|---|---|---|
|
|
if if(var1 != null) |
|
|
if if(var1 != null) |
|
|
if if(var1 != null) |
|
|
if if(var1 == null) |
public |
boolean |
isEmptyboolean isEmpty() |
public |
void |
setvoid set(@Nonnull T var1) |
|
|
synchronized synchronized(this) |
|
|
synchronized synchronized(this) |
abstract |
|
this this(var1, null) |
Исходный код
Показать/скрыть
class="kw">package com.hypixel.hytale.codec.lookup;
class="kw">import com.hypixel.hytale.codec.ExtraInfo;
class="kw">import com.hypixel.hytale.codec.builder.BuilderCodec;
class="kw">import java.util.Objects;
class="kw">import javax.annotation.Nonnull;
class="kw">import javax.annotation.Nullable;
class="kw">import org.bson.BsonDocument;
class="kw">import org.bson.BsonValue;
class="kw">public class="kw">final class Deferred<T> {
@Nonnull
class="kw">private class="kw">final BuilderCodecMapCodec<T> codec;
@Nullable
class="kw">private class="kw">volatile BsonDocument document;
@Nullable
class="kw">private class="kw">volatile T value;
class="kw">public Deferred(@Nonnull BuilderCodecMapCodec<T> var1) {
this(var1, null);
}
Deferred(@Nonnull BuilderCodecMapCodec<T> var1, @Nullable BsonDocument var2) {
this.codec = var1;
this.document = var2;
}
@Nullable
class="kw">public T get() {
Object var1 = this.value;
if (var1 != null) {
class="kw">return var1;
}
class="kw">synchronized (this) {
var1 = this.value;
if (var1 != null) {
class="kw">return var1;
}
var1 = this.decode();
this.value = var1;
if (var1 != null) {
this.document = null;
}
class="kw">return var1;
}
}
class="kw">public void set(@Nonnull T var1) {
Objects.requireNonNull(var1, "value parameter can't be null");
class="kw">synchronized (this) {
this.value = var1;
this.document = null;
}
}
class="kw">public boolean isEmpty() {
class="kw">return this.document == null && this.value == null && this.codec.getDefaultCodec() == null;
}
@Nullable
BsonDocument getDocument() {
class="kw">return this.value == null ? this.document : null;
}
@Nullable
class="kw">private T decode() {
BsonDocument var1 = this.document;
if (var1 == null) {
BuilderCodec var3 = this.codec.getDefaultCodec();
class="kw">return (T)(var3 == null ? null : var3.getDefaultValue());
} else {
BsonValue var2 = var1.get(this.codec.getKey());
if (var2 != null && this.codec.getCodecFor(var2.asString().getValue()) == null) {
throw new IllegalStateException(
"No codec is registered for the type \"" + var2.asString().getValue() + "\" that \"" + this.codec.getKey() + "\" names"
);
} else {
class="kw">return this.codec.decode(var1, ExtraInfo.THREAD_LOCAL.get());
}
}
}
}