Remove usage of the now-redundant ExtractedContexts class, other misc cleanup

This commit is contained in:
Luck
2017-10-15 14:23:51 +01:00
Unverified
parent 28961b1cfa
commit b26fc69e73
56 changed files with 443 additions and 487 deletions
@@ -25,22 +25,46 @@
package me.lucko.luckperms.api;
import com.google.common.base.Preconditions;
import me.lucko.luckperms.api.context.ContextSet;
import me.lucko.luckperms.api.context.ImmutableContextSet;
import javax.annotation.Nonnull;
/**
* Context and options for a permission lookup.
* Encapsulates the options and settings for a permission lookup.
*
* <p>All values are immutable.</p>
* <p>This class is immutable.</p>
*
* @since 2.11
*/
public class Contexts {
/**
* The context key used to denote the subjects server
*/
public static final String SERVER_KEY = "server";
/**
* The context key used to denote the subjects world
*/
public static final String WORLD_KEY = "world";
private static final Contexts GLOBAL = new Contexts(ContextSet.empty(), true, true, true, true, true, false);
/**
* A 'global' or default contexts instance.
*
* Simply passes an empty context set, with all accumulation settings set to true.
*/
private static final Contexts GLOBAL = new Contexts(
ContextSet.empty(),
true,
true,
true,
true,
true,
false
);
/**
* Gets the {@link FullySatisfiedContexts} instance.
@@ -69,12 +93,12 @@ public class Contexts {
/**
* The contexts that apply for this lookup
* The keys for servers and worlds are defined as static values.
*/
private final ContextSet context;
private final ImmutableContextSet context;
/**
* The mode to parse defaults on Bukkit
* If the target subject is OP. This is used to parse defaults on Bukkit,
* and is ignored on all other platforms.
*
* @since 2.12
*/
@@ -105,18 +129,18 @@ public class Contexts {
*/
private final boolean applyGlobalWorldGroups;
public Contexts(@Nonnull ContextSet context, boolean includeGlobal, boolean includeGlobalWorld, boolean applyGroups, boolean applyGlobalGroups, boolean applyGlobalWorldGroups, boolean op) {
if (context == null) {
throw new NullPointerException("context");
}
// cache hashcode - this class is immutable, and is used as an index in the permission cache.
private final int hashCode;
this.context = context.makeImmutable();
public Contexts(@Nonnull ContextSet context, boolean includeGlobal, boolean includeGlobalWorld, boolean applyGroups, boolean applyGlobalGroups, boolean applyGlobalWorldGroups, boolean op) {
this.context = Preconditions.checkNotNull(context, "context").makeImmutable();
this.includeGlobal = includeGlobal;
this.includeGlobalWorld = includeGlobalWorld;
this.applyGroups = applyGroups;
this.applyGlobalGroups = applyGlobalGroups;
this.applyGlobalWorldGroups = applyGlobalWorldGroups;
this.op = op;
this.hashCode = calculateHashCode();
}
/**
@@ -131,7 +155,8 @@ public class Contexts {
}
/**
* Gets if OP defaults should be included
* Gets if the target subject is OP. This is used to parse defaults on Bukkit,
* and is ignored on all other platforms.
*
* @return true if op defaults should be included
*/
@@ -198,10 +223,6 @@ public class Contexts {
")";
}
/*
* Ugly auto-generated lombok code
*/
@Override
public boolean equals(Object o) {
if (o == this) return true;
@@ -218,8 +239,7 @@ public class Contexts {
this.isApplyGlobalWorldGroups() == other.isApplyGlobalWorldGroups();
}
@Override
public int hashCode() {
private int calculateHashCode() {
final int PRIME = 59;
int result = 1;
final Object contexts = this.getContexts();
@@ -233,4 +253,8 @@ public class Contexts {
return result;
}
@Override
public int hashCode() {
return hashCode;
}
}
@@ -55,7 +55,7 @@ public enum DataMutateResult {
*/
FAIL(false, RuntimeException::new);
private boolean value;
private final boolean value;
private final Supplier<? extends Exception> exceptionSupplier;
DataMutateResult(boolean value, Supplier<? extends Exception> exceptionSupplier) {
@@ -104,6 +104,7 @@ public enum DataMutateResult {
sneakyThrow0(t);
}
@SuppressWarnings("unchecked")
private static <T extends Throwable> void sneakyThrow0(Throwable t) throws T {
throw (T) t;
}
@@ -48,6 +48,8 @@ import javax.annotation.Nonnull;
* @since 3.3
*/
public final class FullySatisfiedContexts extends Contexts {
// singleton
private static final FullySatisfiedContexts INSTANCE = new FullySatisfiedContexts();
@Nonnull
@@ -62,16 +64,18 @@ public final class FullySatisfiedContexts extends Contexts {
@Nonnull
@Override
public String toString() {
return "FullySatisfiedContexts";
return "FullySatisfiedContexts()";
}
@Override
public boolean equals(Object o) {
// this class is a singleton, so we can use object comparison to check equality.
return o == this;
}
@Override
public int hashCode() {
// just use the system hashcode - we need to override the hashcode impl in super
return System.identityHashCode(this);
}
}
@@ -426,8 +426,8 @@ public class LogEntry implements Comparable<LogEntry> {
* @param <B> the log builder type
*/
public static abstract class AbstractLogEntryBuilder<T extends LogEntry, B extends AbstractLogEntryBuilder<T, B>> {
private T obj;
private B thisObj;
private final T obj;
private final B thisObj;
public AbstractLogEntryBuilder() {
obj = createEmptyLog();
@@ -48,6 +48,7 @@ import javax.annotation.Nullable;
* <p>Any changes made to permission holding objects will be lost unless the
* instance is saved back to the {@link Storage}.</p>
*/
@SuppressWarnings("RedundantThrows")
public interface PermissionHolder {
/**
@@ -36,6 +36,7 @@ import javax.annotation.Nullable;
/**
* An ordered chain of {@link Group}s.
*/
@SuppressWarnings("RedundantThrows")
public interface Track {
/**
@@ -58,6 +58,9 @@ public final class MetaContexts {
private final MetaStackDefinition prefixStackDefinition;
private final MetaStackDefinition suffixStackDefinition;
// cache hashcode - this class is immutable, and is used as an index in the permission cache.
private final int hashCode;
/**
* Creates a new meta contexts instance
*
@@ -69,6 +72,7 @@ public final class MetaContexts {
this.contexts = Preconditions.checkNotNull(contexts, "contexts");
this.prefixStackDefinition = Preconditions.checkNotNull(prefixStackDefinition, "prefixStackDefinition");
this.suffixStackDefinition = Preconditions.checkNotNull(suffixStackDefinition, "suffixStackDefinition");
this.hashCode = calculateHashCode();
}
@Nonnull
@@ -106,8 +110,7 @@ public final class MetaContexts {
this.getSuffixStackDefinition().equals(other.getSuffixStackDefinition());
}
@Override
public int hashCode() {
private int calculateHashCode() {
final int PRIME = 59;
int result = 1;
result = result * PRIME + this.getContexts().hashCode();
@@ -115,4 +118,9 @@ public final class MetaContexts {
result = result * PRIME + this.getSuffixStackDefinition().hashCode();
return result;
}
@Override
public int hashCode() {
return hashCode;
}
}