InternalReferenceResolver class
Пакет: com.hypixel.hytale.server.npc.asset.builder
Файл: com/hypixel/hytale/server/npc/asset/builder/InternalReferenceResolver.java
Поля (7)
| Модификаторы | Тип | Имя |
|---|---|---|
final |
List<BuilderInstructionReference> |
builders |
|
int |
var2 |
|
|
var2 |
|
BuilderInstructionReference |
var4 |
|
IntIterator |
var4 |
|
int |
var5 |
|
BuilderInstructionReference |
var6 |
Методы (16)
| Модификаторы | Возврат | Сигнатура |
|---|---|---|
abstract |
throw new |
IllegalArgumentExceptionthrow new IllegalArgumentException("Slot for putting builder must be >= 0 and < the size of the list") |
abstract |
throw new |
IllegalArgumentExceptionthrow new IllegalArgumentException("Internal references are currently only supported for instruction list") |
public |
void |
addBuildervoid addBuilder(int var1, BuilderInstructionReference var2) |
abstract |
|
for for(int var3 = 0; var3 < this.builders.size() |
public |
<T> Builder<T> |
getBuilder<T> Builder<T> getBuilder(int var1, Class<?> var2) |
public |
int |
getOrCreateIndexint getOrCreateIndex(String var1) |
|
|
if if(var2 == Integer.MIN_VALUE) |
|
|
if if(this.recordedDependencies != null) |
|
|
if if(var4 == null) |
|
|
if if(var6 == null) |
|
|
if if(var2 != Instruction.class) |
public |
void |
optimisevoid optimise() |
public |
void |
setRecordDependenciesvoid setRecordDependencies() |
public |
void |
stopRecordingDependenciesvoid stopRecordingDependencies() |
public |
void |
validateInternalReferencesvoid validateInternalReferences(String var1, @Nonnull List<String> var2) |
private |
void |
validateNoCyclesvoid validateNoCycles(@Nonnull BuilderInstructionReference var1, int var2, @Nonnull IntArrayList var3) |
Исходный код
Показать/скрыть
class="kw">package com.hypixel.hytale.server.npc.asset.builder;
class="kw">import com.hypixel.hytale.server.npc.instructions.Instruction;
class="kw">import com.hypixel.hytale.server.npc.instructions.builders.BuilderInstructionReference;
class="kw">import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
class="kw">import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
class="kw">import it.unimi.dsi.fastutil.ints.IntArrayList;
class="kw">import it.unimi.dsi.fastutil.ints.IntIterator;
class="kw">import it.unimi.dsi.fastutil.ints.IntOpenHashSet;
class="kw">import it.unimi.dsi.fastutil.ints.IntSet;
class="kw">import it.unimi.dsi.fastutil.objects.Object2IntMap;
class="kw">import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
class="kw">import it.unimi.dsi.fastutil.objects.ObjectArrayList;
class="kw">import java.util.List;
class="kw">import java.util.Objects;
class="kw">import javax.annotation.Nonnull;
class="kw">import javax.annotation.Nullable;
class="kw">public class InternalReferenceResolver {
class="kw">private class="kw">final List<BuilderInstructionReference> builders = new ObjectArrayList();
@Nullable
class="kw">private Object2IntMap<String> indexMap;
@Nullable
class="kw">private Int2ObjectMap<String> nameMap = new Int2ObjectOpenHashMap();
@Nullable
class="kw">private IntSet recordedDependencies;
class="kw">public InternalReferenceResolver() {
this.indexMap = new Object2IntOpenHashMap();
this.indexMap.defaultReturnValue(Integer.MIN_VALUE);
}
class="kw">public int getOrCreateIndex(String var1) {
int var2 = this.indexMap.getInt(var1);
if (var2 == Integer.MIN_VALUE) {
var2 = this.builders.size();
this.indexMap.put(var1, var2);
this.nameMap.put(var2, var1);
this.builders.add(null);
}
if (this.recordedDependencies != null) {
this.recordedDependencies.add(var2);
}
class="kw">return var2;
}
class="kw">public void setRecordDependencies() {
this.recordedDependencies = new IntOpenHashSet();
}
@Nullable
class="kw">public IntSet getRecordedDependenices() {
class="kw">return this.recordedDependencies;
}
class="kw">public void stopRecordingDependencies() {
this.recordedDependencies = null;
}
class="kw">public void addBuilder(int var1, BuilderInstructionReference var2) {
Objects.requireNonNull(var2, "Builder cannot be null when adding as a reference");
if (var1 < 0 || var1 >= this.builders.size()) {
throw new IllegalArgumentException("Slot for putting builder must be >= 0 and < the size of the list");
}
if (this.builders.get(var1) != null) {
throw new IllegalStateException(String.format("Duplicate internal reference builder with name: %s", this.nameMap.get(var1)));
}
this.builders.set(var1, var2);
}
class="kw">public void validateInternalReferences(String var1, @Nonnull List<String> var2) {
for (int var3 = 0; var3 < this.builders.size(); var3++) {
BuilderInstructionReference var4 = this.builders.get(var3);
if (var4 == null) {
var2.add(var1 + ": Internal reference builder: " + (String)this.nameMap.get(var3) + " doesn't exist");
} else {
try {
this.validateNoCycles(var4, var3, new IntArrayList());
} catch (IllegalArgumentException var6) {
var2.add(var1 + ": " + var6.getMessage());
}
}
}
}
class="kw">private void validateNoCycles(@Nonnull BuilderInstructionReference var1, int var2, @Nonnull IntArrayList var3) {
if (var3.contains(var2)) {
throw new IllegalArgumentException("Cyclic reference detected for internal component reference: " + (String)this.nameMap.get(var2));
}
var3.add(var2);
IntIterator var4 = var1.getInternalDependencies().iterator();
while (var4.hasNext()) {
int var5 = var4.nextInt();
BuilderInstructionReference var6 = this.builders.get(var5);
if (var6 == null) {
throw new IllegalStateException("Reference to internal reference builder: " + (String)this.nameMap.get(var5) + " which doesn't exist");
}
this.validateNoCycles(var6, var5, var3);
}
var3.removeInt(var3.size() - 1);
}
class="kw">public <T> Builder<T> getBuilder(int var1, Class<?> var2) {
if (var2 != Instruction.class) {
throw new IllegalArgumentException("Internal references are currently only supported for instruction list");
} else {
class="kw">return this.builders.get(var1);
}
}
class="kw">public void optimise() {
this.indexMap = null;
this.nameMap = null;
}
}