From 966bf8bf51d1a96ddd15d44a349a4a010275c6b3 Mon Sep 17 00:00:00 2001 From: Luck Date: Fri, 23 Feb 2018 14:20:30 +0000 Subject: [PATCH] Replace deprecated method usage in NodeTools --- .../java/me/lucko/luckperms/api/Contexts.java | 10 +--- .../lucko/luckperms/common/model/NodeMap.java | 5 +- .../common/model/PermissionHolder.java | 8 ++-- .../luckperms/common/node/NodeTools.java | 48 +++---------------- 4 files changed, 15 insertions(+), 56 deletions(-) diff --git a/api/src/main/java/me/lucko/luckperms/api/Contexts.java b/api/src/main/java/me/lucko/luckperms/api/Contexts.java index 1979efde..57e69031 100644 --- a/api/src/main/java/me/lucko/luckperms/api/Contexts.java +++ b/api/src/main/java/me/lucko/luckperms/api/Contexts.java @@ -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. diff --git a/common/src/main/java/me/lucko/luckperms/common/model/NodeMap.java b/common/src/main/java/me/lucko/luckperms/common/model/NodeMap.java index 4f0532a2..f61be7dd 100644 --- a/common/src/main/java/me/lucko/luckperms/common/model/NodeMap.java +++ b/common/src/main/java/me/lucko/luckperms/common/model/NodeMap.java @@ -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(); diff --git a/common/src/main/java/me/lucko/luckperms/common/model/PermissionHolder.java b/common/src/main/java/me/lucko/luckperms/common/model/PermissionHolder.java index 5f33ba29..4c3928d4 100644 --- a/common/src/main/java/me/lucko/luckperms/common/model/PermissionHolder.java +++ b/common/src/main/java/me/lucko/luckperms/common/model/PermissionHolder.java @@ -366,7 +366,7 @@ public abstract class PermissionHolder { List nodes = new LinkedList<>(); accumulateInheritancesTo(nodes, contexts); - NodeTools.removeAlmostEqual(nodes.iterator()); + NodeTools.removeEqual(nodes.iterator(), StandardNodeEquality.IGNORE_EXPIRY_TIME_AND_VALUE); SortedSet ret = new TreeSet<>(NodeWithContextComparator.reverse()); ret.addAll(nodes); return ret; @@ -376,7 +376,7 @@ public abstract class PermissionHolder { List nodes = new LinkedList<>(); accumulateInheritancesTo(nodes, contexts); - NodeTools.removeIgnoreValueOrTemp(nodes.iterator()); + NodeTools.removeEqual(nodes.iterator(), StandardNodeEquality.IGNORE_VALUE_OR_IF_TEMPORARY); SortedSet ret = new TreeSet<>(NodeWithContextComparator.reverse()); ret.addAll(nodes); return ret; @@ -404,7 +404,7 @@ public abstract class PermissionHolder { List nodes = new LinkedList<>(); accumulateInheritancesTo(nodes); - NodeTools.removeAlmostEqual(nodes.iterator()); + NodeTools.removeEqual(nodes.iterator(), StandardNodeEquality.IGNORE_EXPIRY_TIME_AND_VALUE); SortedSet ret = new TreeSet<>(NodeWithContextComparator.reverse()); ret.addAll(nodes); return ret; @@ -414,7 +414,7 @@ public abstract class PermissionHolder { List nodes = new LinkedList<>(); accumulateInheritancesTo(nodes); - NodeTools.removeIgnoreValueOrTemp(nodes.iterator()); + NodeTools.removeEqual(nodes.iterator(), StandardNodeEquality.IGNORE_VALUE_OR_IF_TEMPORARY); SortedSet ret = new TreeSet<>(NodeWithContextComparator.reverse()); ret.addAll(nodes); return ret; diff --git a/common/src/main/java/me/lucko/luckperms/common/node/NodeTools.java b/common/src/main/java/me/lucko/luckperms/common/node/NodeTools.java index 038bcb6e..0ec9ff7f 100644 --- a/common/src/main/java/me/lucko/luckperms/common/node/NodeTools.java +++ b/common/src/main/java/me/lucko/luckperms/common/node/NodeTools.java @@ -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 void removeAlmostEqual(Iterator it) { + public static void removeEqual(Iterator it, NodeEqualityPredicate equalityPredicate) { List 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 void removeIgnoreValue(Iterator it) { - List 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 void removeIgnoreValueOrTemp(Iterator it) { - List 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 void removeSamePermission(Iterator it) { Set alreadyIn = new HashSet<>(); - while (it.hasNext()) { T next = it.next(); - if (!alreadyIn.add(next.getPermission())) { it.remove(); }