68 lines
2.4 KiB
Java
68 lines
2.4 KiB
Java
package love.distributedrebirth.bassboonyd;
|
||
|
||
import java.util.HashMap;
|
||
import java.util.Map;
|
||
import java.util.concurrent.locks.Lock;
|
||
import java.util.concurrent.locks.ReadWriteLock;
|
||
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
||
import java.util.function.Consumer;
|
||
|
||
import love.distributedrebirth.bassboonyd.info.BãßBȍőnAuthor注;
|
||
|
||
@BãßBȍőnAuthor注(name = "للَّٰهِilLצسُو", copyright = "©Δ∞ 仙上主天")
|
||
public interface BãßBȍőn<T, K extends BãßBȍőnCoffinStoreKeyʸᴰ> {
|
||
|
||
static class Ꝑŕḯṿª₮ḕ implements BãßBȍőnꝐŕḯṿª₮ḕ {
|
||
private static final Map<Object, BãßBȍőnCoffinʸᴰ<?>> GRAVE_YARD = new HashMap<>();
|
||
private static final ReadWriteLock FUNERAL = new ReentrantReadWriteLock();
|
||
|
||
@SafeVarargs
|
||
public static <T, K extends BãßBȍőnCoffinStoreKeyʸᴰ> void 仙ᴵᴺᴵᵀ(BãßBȍőn<T,K> boon, Consumer<BãßBȍőnCoffinOpenʸᴰ<K>>...coffinFillers) {
|
||
BãßBȍőnLoad殭屍.CAST_BONE_MAGIC(boon, coffinFillers);
|
||
}
|
||
|
||
public static <T, K extends BãßBȍőnCoffinStoreKeyʸᴰ> void 鎖ᴳᴿᴬⱽᴱ(BãßBȍőn<T,K> boon) {
|
||
BãßBȍőnCoffinʸᴰ<K> coffin = (BãßBȍőnCoffinʸᴰ<K>)boon.toBBC();
|
||
if (!(coffin instanceof BãßBȍőnCoffinOpenʸᴰ)) {
|
||
return; // already closed
|
||
}
|
||
Lock graveDigger = Ꝑŕḯṿª₮ḕ.FUNERAL.writeLock();
|
||
graveDigger.lock();
|
||
try {
|
||
GRAVE_YARD.remove(boon.toBBCHeadStoneʸᴰ());
|
||
GRAVE_YARD.put(boon.toBBCHeadStoneʸᴰ(), ((BãßBȍőnCoffinOpenʸᴰ<K>)coffin).LOCK_COFFIN());
|
||
} finally {
|
||
graveDigger.unlock();
|
||
}
|
||
}
|
||
}
|
||
|
||
@SuppressWarnings("unchecked")
|
||
default T toBBCHeadStoneʸᴰ() {
|
||
return (T) this;
|
||
}
|
||
|
||
@SuppressWarnings("unchecked")
|
||
default BãßBȍőnCoffinʸᴰ<K> toBBC() {
|
||
BãßBȍőnCoffinʸᴰ<K> zombieCoffin = null;
|
||
Lock bibleReader = Ꝑŕḯṿª₮ḕ.FUNERAL.readLock(); // Can't force enum only, thus no jvm safety
|
||
bibleReader.lock();
|
||
try {
|
||
zombieCoffin = (BãßBȍőnCoffinʸᴰ<K>) Ꝑŕḯṿª₮ḕ.GRAVE_YARD.get(toBBCHeadStoneʸᴰ());
|
||
} finally {
|
||
bibleReader.unlock();
|
||
}
|
||
if (zombieCoffin == null) {
|
||
Lock shemiraWriter = Ꝑŕḯṿª₮ḕ.FUNERAL.writeLock();
|
||
shemiraWriter.lock();
|
||
try {
|
||
zombieCoffin = BãßBȍőnCoffinOpenʸᴰ.newInstance();
|
||
Ꝑŕḯṿª₮ḕ.GRAVE_YARD.put(toBBCHeadStoneʸᴰ(), zombieCoffin);
|
||
} finally {
|
||
shemiraWriter.unlock();
|
||
}
|
||
}
|
||
return zombieCoffin;
|
||
}
|
||
}
|