/* * Decompiled with CFR 0.152. * * Could not load the following classes: * com.google.common.collect.Sets * com.google.common.collect.Sets$SetView * org.jetbrains.annotations.Contract * org.jspecify.annotations.Nullable */ package net.minecraft.util.context; import com.google.common.collect.Sets; import java.util.IdentityHashMap; import java.util.Map; import java.util.NoSuchElementException; import net.minecraft.util.context.ContextKey; import net.minecraft.util.context.ContextKeySet; import org.jetbrains.annotations.Contract; import org.jspecify.annotations.Nullable; public class ContextMap { private final Map, Object> params; private ContextMap(Map, Object> params) { this.params = params; } public boolean has(ContextKey key) { return this.params.containsKey(key); } public T getOrThrow(ContextKey key) { Object value = this.params.get(key); if (value == null) { throw new NoSuchElementException(key.name().toString()); } return (T)value; } public @Nullable T getOptional(ContextKey key) { return (T)this.params.get(key); } @Contract(value="_,!null->!null; _,_->_") public @Nullable T getOrDefault(ContextKey param, @Nullable T _default) { return (T)this.params.getOrDefault(param, _default); } public static class Builder { private final Map, Object> params = new IdentityHashMap(); public Builder withParameter(ContextKey param, T value) { this.params.put(param, value); return this; } public Builder withOptionalParameter(ContextKey param, @Nullable T value) { if (value == null) { this.params.remove(param); } else { this.params.put(param, value); } return this; } public T getParameter(ContextKey param) { Object value = this.params.get(param); if (value == null) { throw new NoSuchElementException(param.name().toString()); } return (T)value; } public @Nullable T getOptionalParameter(ContextKey param) { return (T)this.params.get(param); } public ContextMap create(ContextKeySet paramSet) { Sets.SetView notAllowed = Sets.difference(this.params.keySet(), paramSet.allowed()); if (!notAllowed.isEmpty()) { throw new IllegalArgumentException("Parameters not allowed in this parameter set: " + String.valueOf(notAllowed)); } Sets.SetView missingRequired = Sets.difference(paramSet.required(), this.params.keySet()); if (!missingRequired.isEmpty()) { throw new IllegalArgumentException("Missing required parameters: " + String.valueOf(missingRequired)); } return new ContextMap(this.params); } } }