LookupTableAssetMap.java
package com.hypixel.hytale.assetstore.map;
import com.hypixel.hytale.assetstore.codec.AssetCodec;
import java.nio.file.Path;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.locks.ReentrantLock;
import java.util.function.IntFunction;
import java.util.function.IntSupplier;
import java.util.function.ToIntFunction;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
public class LookupTableAssetMap<K, T extends JsonAssetWithMap<K, LookupTableAssetMap<K, T>>> extends AssetMapWithIndexes<K, T> {
@Nonnull
private final IntFunction<T[]> arrayProvider;
private final ToIntFunction<K> indexGetter;
private final IntSupplier maxIndexGetter;
private final ReentrantLock arrayLock = new ReentrantLock();
private T[] array;
public LookupTableAssetMap(@Nonnull IntFunction<T[]> arrayProvider, ToIntFunction<K> indexGetter, IntSupplier maxIndexGetter) {
.arrayProvider = arrayProvider;
.indexGetter = indexGetter;
.maxIndexGetter = maxIndexGetter;
.array = (JsonAssetWithMap[])arrayProvider.apply();
}
T {
(T)(index >= && index < .array.length ? .array[index] : );
}
T {
(T)(index >= && index < .array.length ? .array[index] : def);
}
{
.clear();
.arrayLock.lock();
{
.array = (JsonAssetWithMap[]).arrayProvider.apply();
} {
.arrayLock.unlock();
}
}
{
.putAll(packKey, codec, loadedAssets, loadedKeyToPathMap, loadedAssetChildren);
.arrayLock.lock();
{
.resize();
(Map.Entry<K, T> entry : loadedAssets.entrySet()) {
(K)entry.getKey();
.indexGetter.applyAsInt(key);
(index < ) {
();
}
(index >= .array.length) {
();
}
(T)(entry.getValue());
.array[index] = value;
.putAssetTag(codec, key, index, value);
}
} {
.arrayLock.unlock();
}
}
Set<K> {
Set<K> remove = .remove(keys);
.remove0(keys);
remove;
}
Set<K> {
Set<K> remove = .remove(packKey, keys, pathsToReload);
.remove0(keys);
remove;
}
{
.arrayLock.lock();
{
(K key : keys) {
.indexGetter.applyAsInt(key);
(blockId != -) {
.array[blockId] = ;
.indexedTagStorage.forEachWithInt((_k, value, id) -> value.remove(id), blockId);
}
}
.resize();
} {
.arrayLock.unlock();
}
}
{
.maxIndexGetter.getAsInt();
(length < ) {
();
} {
(length > .array.length) {
T[] newArray = (JsonAssetWithMap[]).arrayProvider.apply(length);
System.arraycopy(.array, , newArray, , .array.length);
.array = newArray;
} (length < .array.length) {
( length; i < .array.length; ++i) {
(.array[i] != ) {
();
}
}
T[] newArray = (JsonAssetWithMap[]).arrayProvider.apply(length);
System.arraycopy(.array, , newArray, , newArray.length);
.array = newArray;
}
}
}
{
;
}
}