Replace deprecated method usage in NodeTools

This commit is contained in:
Luck 2018-02-23 14:20:30 +00:00
parent 63ff3c34b3
commit 966bf8bf51
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B
4 changed files with 15 additions and 56 deletions

View File

@ -58,15 +58,7 @@ public class Contexts {
*
* 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
);
private static final Contexts GLOBAL = new Contexts(ContextSet.empty(), true, true, true, true, true, false);
/**
* Gets the {@link FullySatisfiedContexts} instance.

View File

@ -32,6 +32,7 @@ import com.google.common.collect.SortedSetMultimap;
import me.lucko.luckperms.api.LocalizedNode;
import me.lucko.luckperms.api.Node;
import me.lucko.luckperms.api.StandardNodeEquality;
import me.lucko.luckperms.api.context.ContextSet;
import me.lucko.luckperms.api.context.ImmutableContextSet;
import me.lucko.luckperms.common.buffers.Cache;
@ -218,9 +219,9 @@ public final class NodeMap {
this.lock.lock();
try {
ImmutableContextSet context = node.getFullContexts().makeImmutable();
this.map.get(context).removeIf(e -> e.almostEquals(node));
this.map.get(context).removeIf(e -> e.equals(node, StandardNodeEquality.IGNORE_EXPIRY_TIME_AND_VALUE));
if (node.isGroupNode()) {
this.inheritanceMap.get(context).removeIf(e -> e.almostEquals(node));
this.inheritanceMap.get(context).removeIf(e -> e.equals(node, StandardNodeEquality.IGNORE_EXPIRY_TIME_AND_VALUE));
}
} finally {
this.lock.unlock();

View File

@ -366,7 +366,7 @@ public abstract class PermissionHolder {
List<LocalizedNode> nodes = new LinkedList<>();
accumulateInheritancesTo(nodes, contexts);
NodeTools.removeAlmostEqual(nodes.iterator());
NodeTools.removeEqual(nodes.iterator(), StandardNodeEquality.IGNORE_EXPIRY_TIME_AND_VALUE);
SortedSet<LocalizedNode> ret = new TreeSet<>(NodeWithContextComparator.reverse());
ret.addAll(nodes);
return ret;
@ -376,7 +376,7 @@ public abstract class PermissionHolder {
List<LocalizedNode> nodes = new LinkedList<>();
accumulateInheritancesTo(nodes, contexts);
NodeTools.removeIgnoreValueOrTemp(nodes.iterator());
NodeTools.removeEqual(nodes.iterator(), StandardNodeEquality.IGNORE_VALUE_OR_IF_TEMPORARY);
SortedSet<LocalizedNode> ret = new TreeSet<>(NodeWithContextComparator.reverse());
ret.addAll(nodes);
return ret;
@ -404,7 +404,7 @@ public abstract class PermissionHolder {
List<LocalizedNode> nodes = new LinkedList<>();
accumulateInheritancesTo(nodes);
NodeTools.removeAlmostEqual(nodes.iterator());
NodeTools.removeEqual(nodes.iterator(), StandardNodeEquality.IGNORE_EXPIRY_TIME_AND_VALUE);
SortedSet<LocalizedNode> ret = new TreeSet<>(NodeWithContextComparator.reverse());
ret.addAll(nodes);
return ret;
@ -414,7 +414,7 @@ public abstract class PermissionHolder {
List<LocalizedNode> nodes = new LinkedList<>();
accumulateInheritancesTo(nodes);
NodeTools.removeIgnoreValueOrTemp(nodes.iterator());
NodeTools.removeEqual(nodes.iterator(), StandardNodeEquality.IGNORE_VALUE_OR_IF_TEMPORARY);
SortedSet<LocalizedNode> ret = new TreeSet<>(NodeWithContextComparator.reverse());
ret.addAll(nodes);
return ret;

View File

@ -26,6 +26,7 @@
package me.lucko.luckperms.common.node;
import me.lucko.luckperms.api.Node;
import me.lucko.luckperms.api.NodeEqualityPredicate;
import java.util.ArrayList;
import java.util.HashSet;
@ -35,50 +36,17 @@ import java.util.Set;
public final class NodeTools {
public static <T extends Node> void removeAlmostEqual(Iterator<T> it) {
public static <T extends Node> void removeEqual(Iterator<T> it, NodeEqualityPredicate equalityPredicate) {
List<T> alreadyIn = new ArrayList<>();
iter:
iterate:
while (it.hasNext()) {
T next = it.next();
for (T n : alreadyIn) {
if (next.almostEquals(n)) {
for (T other : alreadyIn) {
if (next.equals(other, equalityPredicate)) {
it.remove();
continue iter;
}
}
alreadyIn.add(next);
}
}
public static <T extends Node> void removeIgnoreValue(Iterator<T> it) {
List<T> alreadyIn = new ArrayList<>();
iter:
while (it.hasNext()) {
T next = it.next();
for (T n : alreadyIn) {
if (next.equalsIgnoringValue(n)) {
it.remove();
continue iter;
}
}
alreadyIn.add(next);
}
}
public static <T extends Node> void removeIgnoreValueOrTemp(Iterator<T> it) {
List<T> alreadyIn = new ArrayList<>();
iter:
while (it.hasNext()) {
T next = it.next();
for (T n : alreadyIn) {
if (next.equalsIgnoringValueOrTemp(n)) {
it.remove();
continue iter;
continue iterate;
}
}
@ -88,10 +56,8 @@ public final class NodeTools {
public static <T extends Node> void removeSamePermission(Iterator<T> it) {
Set<String> alreadyIn = new HashSet<>();
while (it.hasNext()) {
T next = it.next();
if (!alreadyIn.add(next.getPermission())) {
it.remove();
}