Java Code Examples for it.unimi.dsi.fastutil.objects.Object2ObjectMap#containsKey()

The following examples show how to use it.unimi.dsi.fastutil.objects.Object2ObjectMap#containsKey() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RequestScopedMdc.java    From armeria with Apache License 2.0 6 votes vote down vote up
/**
 * Unbinds the specified request-scoped {@link MDC} property from the specified {@link RequestContext}.
 *
 * @param ctx the {@link RequestContext}
 * @param key the key of the request-scoped {@link MDC} property to unbind
 */
public static void remove(RequestContext ctx, String key) {
    requireNonNull(ctx, "ctx");
    requireNonNull(key, "key");

    synchronized (ctx) {
        final Object2ObjectMap<String, String> oldMap = getMap(ctx);
        if (!oldMap.containsKey(key)) {
            return;
        }

        final Object2ObjectMap<String, String> newMap;
        if (oldMap.size() == 1) {
            newMap = Object2ObjectMaps.emptyMap();
        } else {
            final Object2ObjectOpenHashMap<String, String> tmp = new Object2ObjectOpenHashMap<>(oldMap);
            tmp.remove(key);
            newMap = Object2ObjectMaps.unmodifiable(tmp);
        }
        ctx.setAttr(MAP, newMap);
    }
}
 
Example 2
Source File: NpcClothingFeature.java    From MineLittlePony with MIT License 5 votes vote down vote up
public <K> VillagerResourceMetadata.HatType getHatType(Object2ObjectMap<K, HatType> cache, String type, DefaultedRegistry<K> registry, K key) {
    if (cache.containsKey(key)) {
        return cache.get(key); // People often complain that villagers cause lag,
                               // so let's do better than Mojang and rather NOT go
                               // through all the lambda generations if we can avoid it.
    }
    return loadHatType(cache, type, registry, key);
}