RelativeIntegerRange class
Пакет: com.hypixel.hytale.server.core.command.system.arguments.types
Файл: com/hypixel/hytale/server/core/command/system/arguments/types/RelativeIntegerRange.java
Методы (1)
| Модификаторы | Возврат | Сигнатура |
|---|---|---|
public |
int |
getNumberInRangeint getNumberInRange(int var1) |
Исходный код
Показать/скрыть
class="kw">package com.hypixel.hytale.server.core.command.system.arguments.types;
class="kw">import com.hypixel.hytale.codec.KeyedCodec;
class="kw">import com.hypixel.hytale.codec.builder.BuilderCodec;
class="kw">import com.hypixel.hytale.codec.validation.Validators;
class="kw">import java.util.concurrent.ThreadLocalRandom;
class="kw">import javax.annotation.Nonnull;
class="kw">public class RelativeIntegerRange {
@Nonnull
class="kw">public class="kw">static class="kw">final BuilderCodec<RelativeIntegerRange> CODEC = BuilderCodec.builder(RelativeIntegerRange.class, RelativeIntegerRange::new)
.append(new KeyedCodec<>("Min", RelativeInteger.CODEC), (var0, var1) -> var0.min = var1, var0 -> var0.min)
.addValidator(Validators.nonNull())
.add()
.<RelativeInteger>append(new KeyedCodec<>("Max", RelativeInteger.CODEC), (var0, var1) -> var0.max = var1, var0 -> var0.max)
.addValidator(Validators.nonNull())
.add()
.build();
class="kw">private RelativeInteger min;
class="kw">private RelativeInteger max;
class="kw">public RelativeIntegerRange(@Nonnull RelativeInteger var1, @Nonnull RelativeInteger var2) {
this.min = var1;
this.max = var2;
}
class="kw">protected RelativeIntegerRange() {
}
class="kw">public RelativeIntegerRange(int var1, int var2) {
this.min = new RelativeInteger(var1, false);
this.max = new RelativeInteger(var2, false);
}
class="kw">public int getNumberInRange(int var1) {
class="kw">return this.min.getRawValue() == this.max.getRawValue()
? this.min.resolve(var1)
: ThreadLocalRandom.current().nextInt(this.min.resolve(var1), this.max.resolve(var1) + 1);
}
@Nonnull
@Override
class="kw">public String toString() {
class="kw">return "{ Minimum: " + this.min + ", Maximum: " + this.max + " }";
}
}