IntegerCodec class
Пакет: com.hypixel.hytale.codec.codecs.simple
Файл: com/hypixel/hytale/codec/codecs/simple/IntegerCodec.java
implements: Codec<Integer>, RawJsonCodec<Integer>, PrimitiveCodec
Поля (2)
| Модификаторы | Тип | Имя |
|---|---|---|
|
int |
var3 |
|
IntegerSchema |
var3 |
Методы (4)
| Модификаторы | Возврат | Сигнатура |
|---|---|---|
abstract |
return new |
BsonInt32return new BsonInt32(var1) |
abstract |
throw new |
IllegalArgumentExceptionthrow new IllegalArgumentException("Expected an int but got a decimal!") |
abstract |
return new |
IntegerSchemareturn new IntegerSchema() |
|
|
if if(var2 != null) |
Исходный код
Показать/скрыть
class="kw">package com.hypixel.hytale.codec.codecs.simple;
class="kw">import com.hypixel.hytale.codec.Codec;
class="kw">import com.hypixel.hytale.codec.ExtraInfo;
class="kw">import com.hypixel.hytale.codec.PrimitiveCodec;
class="kw">import com.hypixel.hytale.codec.RawJsonCodec;
class="kw">import com.hypixel.hytale.codec.schema.SchemaContext;
class="kw">import com.hypixel.hytale.codec.schema.config.IntegerSchema;
class="kw">import com.hypixel.hytale.codec.schema.config.Schema;
class="kw">import com.hypixel.hytale.codec.util.RawJsonReader;
class="kw">import java.io.IOException;
class="kw">import javax.annotation.Nonnull;
class="kw">import javax.annotation.Nullable;
class="kw">import org.bson.BsonInt32;
class="kw">import org.bson.BsonValue;
class="kw">public class IntegerCodec class="kw">implements Codec<Integer>, RawJsonCodec<Integer>, PrimitiveCodec {
class="kw">public IntegerCodec() {
}
@Nonnull
class="kw">public Integer decode(@Nonnull BsonValue var1, ExtraInfo var2) {
int var3 = var1.asNumber().intValue();
if (var3 != var1.asNumber().doubleValue()) {
throw new IllegalArgumentException("Expected an int but got a decimal!");
} else {
class="kw">return var3;
}
}
@Nonnull
class="kw">public BsonValue encode(Integer var1, ExtraInfo var2) {
class="kw">return new BsonInt32(var1);
}
@Nonnull
class="kw">public Integer decodeJson(@Nonnull RawJsonReader var1, ExtraInfo var2) class="kw">throws IOException {
class="kw">return var1.readIntValue();
}
@Nonnull
@Override
class="kw">public Schema toSchema(@Nonnull SchemaContext var1) {
class="kw">return new IntegerSchema();
}
@Nonnull
class="kw">public Schema toSchema(@Nonnull SchemaContext var1, @Nullable Integer var2) {
IntegerSchema var3 = new IntegerSchema();
if (var2 != null) {
var3.setDefault(var2);
}
class="kw">return var3;
}
}