com.mineteria.ignite.api.util.BlackboardMap Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ignite-api Show documentation
Show all versions of ignite-api Show documentation
Bootstraps the Minecraft Server with ModLauncher to apply Mixins and Access Transformers from mods.
The newest version!
/*
* This file is part of Ignite, licensed under the MIT License (MIT).
*
* Copyright (c) Mineteria
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.mineteria.ignite.api.util;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import java.util.Objects;
import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicLong;
import java.util.function.Function;
public final class BlackboardMap {
private final ConcurrentHashMap, Object> blackboardMap = new ConcurrentHashMap<>();
private final ConcurrentHashMap> blackboardKeys = new ConcurrentHashMap<>();
public BlackboardMap() {}
public @NonNull Optional get(final @NonNull Key key) {
return Optional.ofNullable(key.type.cast(this.blackboardMap.get(key)));
}
public @Nullable V computeIfAbsent(final @NonNull Key key, final @NonNull Function super Key, ? extends V> valueFunction) {
return computeIfAbsent(this.blackboardMap, key, valueFunction);
}
@SuppressWarnings("unchecked")
private V computeIfAbsent(final ConcurrentHashMap map, final Key key, final Function super Key, ? extends V> valueFunction) {
return (V) map.computeIfAbsent((C1) key, (Function super C1, ? extends C2>) valueFunction);
}
private ConcurrentHashMap> getKeys() {
return this.blackboardKeys;
}
/**
* Unique blackboard key
*/
public static final class Key implements Comparable> {
@SuppressWarnings("unchecked")
public static @NonNull Key getOrCreate(final @NonNull BlackboardMap owner, final @NonNull String name, final @NonNull Class super V> clazz) {
final Key result = (Key) owner.getKeys().computeIfAbsent(name, (n) -> new Key<>(n, (Class