Reduce usage of outdated Predicate class
This commit is contained in:
parent
65b635718f
commit
5cfd609478
@ -8,12 +8,11 @@ import com.massivecraft.massivecore.engine.EngineMassiveCoreCommandRegistration;
|
|||||||
import com.massivecraft.massivecore.entity.MassiveCoreMConf;
|
import com.massivecraft.massivecore.entity.MassiveCoreMConf;
|
||||||
import com.massivecraft.massivecore.mixin.Mixin;
|
import com.massivecraft.massivecore.mixin.Mixin;
|
||||||
import com.massivecraft.massivecore.mixin.MixinMessage;
|
import com.massivecraft.massivecore.mixin.MixinMessage;
|
||||||
import com.massivecraft.massivecore.predicate.Predicate;
|
|
||||||
import com.massivecraft.massivecore.predicate.PredicateAnd;
|
|
||||||
import com.massivecraft.massivecore.predicate.PredicateIsClassSingleton;
|
import com.massivecraft.massivecore.predicate.PredicateIsClassSingleton;
|
||||||
import com.massivecraft.massivecore.store.Coll;
|
import com.massivecraft.massivecore.store.Coll;
|
||||||
import com.massivecraft.massivecore.store.migrator.MigratorRoot;
|
import com.massivecraft.massivecore.store.migrator.MigratorRoot;
|
||||||
import com.massivecraft.massivecore.test.Test;
|
import com.massivecraft.massivecore.test.Test;
|
||||||
|
import com.massivecraft.massivecore.util.MUtil;
|
||||||
import com.massivecraft.massivecore.util.ReflectionUtil;
|
import com.massivecraft.massivecore.util.ReflectionUtil;
|
||||||
import com.massivecraft.massivecore.util.Txt;
|
import com.massivecraft.massivecore.util.Txt;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
@ -27,6 +26,7 @@ import java.util.Arrays;
|
|||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.function.Predicate;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
@ -355,7 +355,7 @@ public abstract class MassivePlugin extends JavaPlugin implements Listener, Name
|
|||||||
return getClassesActive("nms", Mixin.class, new Predicate<Class<?>>()
|
return getClassesActive("nms", Mixin.class, new Predicate<Class<?>>()
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
public boolean apply(Class<?> clazz)
|
public boolean test(Class<?> clazz)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -427,7 +427,7 @@ public abstract class MassivePlugin extends JavaPlugin implements Listener, Name
|
|||||||
packageName = packageName == null ? "" : "." + packageName;
|
packageName = packageName == null ? "" : "." + packageName;
|
||||||
packageName = this.getClass().getPackage().getName() + packageName;
|
packageName = this.getClass().getPackage().getName() + packageName;
|
||||||
|
|
||||||
Predicate predicateCombined = PredicateAnd.get(predicates);
|
Predicate predicateCombined = MUtil.predicatesAnd(predicates);
|
||||||
Predicate<Class<?>> predicateNotAbstract = type -> !Modifier.isAbstract(type.getModifiers());
|
Predicate<Class<?>> predicateNotAbstract = type -> !Modifier.isAbstract(type.getModifiers());
|
||||||
Predicate<Class<?>> predicateSubclass = type -> !Modifier.isAbstract(type.getModifiers());
|
Predicate<Class<?>> predicateSubclass = type -> !Modifier.isAbstract(type.getModifiers());
|
||||||
Predicate<Class<?>> predicateSingleton = PredicateIsClassSingleton.get();
|
Predicate<Class<?>> predicateSingleton = PredicateIsClassSingleton.get();
|
||||||
|
@ -14,7 +14,6 @@ import com.massivecraft.massivecore.command.type.Type;
|
|||||||
import com.massivecraft.massivecore.command.type.enumeration.TypeEnum;
|
import com.massivecraft.massivecore.command.type.enumeration.TypeEnum;
|
||||||
import com.massivecraft.massivecore.mixin.MixinMessage;
|
import com.massivecraft.massivecore.mixin.MixinMessage;
|
||||||
import com.massivecraft.massivecore.mson.Mson;
|
import com.massivecraft.massivecore.mson.Mson;
|
||||||
import com.massivecraft.massivecore.predicate.Predicate;
|
|
||||||
import com.massivecraft.massivecore.predicate.PredicateLevenshteinClose;
|
import com.massivecraft.massivecore.predicate.PredicateLevenshteinClose;
|
||||||
import com.massivecraft.massivecore.predicate.PredicateStartsWithIgnoreCase;
|
import com.massivecraft.massivecore.predicate.PredicateStartsWithIgnoreCase;
|
||||||
import com.massivecraft.massivecore.util.MUtil;
|
import com.massivecraft.massivecore.util.MUtil;
|
||||||
@ -412,7 +411,7 @@ public class MassiveCommand implements Active, PluginIdentifiableCommand
|
|||||||
|
|
||||||
// Prepare
|
// Prepare
|
||||||
token = token.toLowerCase();
|
token = token.toLowerCase();
|
||||||
Predicate<String> predicate = levenshtein ? PredicateLevenshteinClose.get(token) : PredicateStartsWithIgnoreCase.get(token);
|
java.util.function.Predicate<String> predicate = levenshtein ? PredicateLevenshteinClose.get(token) : PredicateStartsWithIgnoreCase.get(token);
|
||||||
|
|
||||||
// Fill Ret
|
// Fill Ret
|
||||||
// Go through each child command
|
// Go through each child command
|
||||||
@ -431,7 +430,7 @@ public class MassiveCommand implements Active, PluginIdentifiableCommand
|
|||||||
if (ret.contains(child)) continue;
|
if (ret.contains(child)) continue;
|
||||||
|
|
||||||
// ... matches ...
|
// ... matches ...
|
||||||
if (!predicate.apply(alias)) continue;
|
if (!predicate.test(alias)) continue;
|
||||||
|
|
||||||
// ... and put in ret.
|
// ... and put in ret.
|
||||||
ret.add(child);
|
ret.add(child);
|
||||||
|
@ -2,16 +2,15 @@ package com.massivecraft.massivecore.engine;
|
|||||||
|
|
||||||
import com.massivecraft.massivecore.Engine;
|
import com.massivecraft.massivecore.Engine;
|
||||||
import com.massivecraft.massivecore.MassiveCore;
|
import com.massivecraft.massivecore.MassiveCore;
|
||||||
import com.massivecraft.massivecore.entity.MassiveCoreMConf;
|
|
||||||
import com.massivecraft.massivecore.SenderPresence;
|
import com.massivecraft.massivecore.SenderPresence;
|
||||||
import com.massivecraft.massivecore.SenderType;
|
import com.massivecraft.massivecore.SenderType;
|
||||||
|
import com.massivecraft.massivecore.entity.MassiveCoreMConf;
|
||||||
import com.massivecraft.massivecore.event.EventMassiveCoreAfterPlayerRespawn;
|
import com.massivecraft.massivecore.event.EventMassiveCoreAfterPlayerRespawn;
|
||||||
import com.massivecraft.massivecore.event.EventMassiveCoreAfterPlayerTeleport;
|
import com.massivecraft.massivecore.event.EventMassiveCoreAfterPlayerTeleport;
|
||||||
import com.massivecraft.massivecore.event.EventMassiveCorePermissionDeniedFormat;
|
import com.massivecraft.massivecore.event.EventMassiveCorePermissionDeniedFormat;
|
||||||
import com.massivecraft.massivecore.event.EventMassiveCorePlayerToRecipientChat;
|
import com.massivecraft.massivecore.event.EventMassiveCorePlayerToRecipientChat;
|
||||||
import com.massivecraft.massivecore.mixin.MixinMessage;
|
import com.massivecraft.massivecore.mixin.MixinMessage;
|
||||||
import com.massivecraft.massivecore.mixin.MixinVisibility;
|
import com.massivecraft.massivecore.mixin.MixinVisibility;
|
||||||
import com.massivecraft.massivecore.predicate.Predicate;
|
|
||||||
import com.massivecraft.massivecore.predicate.PredicateStartsWithIgnoreCase;
|
import com.massivecraft.massivecore.predicate.PredicateStartsWithIgnoreCase;
|
||||||
import com.massivecraft.massivecore.util.IdUtil;
|
import com.massivecraft.massivecore.util.IdUtil;
|
||||||
import com.massivecraft.massivecore.util.MUtil;
|
import com.massivecraft.massivecore.util.MUtil;
|
||||||
@ -35,6 +34,7 @@ import java.util.Map;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.TreeSet;
|
import java.util.TreeSet;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
public class EngineMassiveCoreMain extends Engine
|
public class EngineMassiveCoreMain extends Engine
|
||||||
{
|
{
|
||||||
@ -129,7 +129,7 @@ public class EngineMassiveCoreMain extends Engine
|
|||||||
// TODO: Should this only be players? Would a player actually want to tab-complete @console?
|
// TODO: Should this only be players? Would a player actually want to tab-complete @console?
|
||||||
for (String senderName : IdUtil.getNames(SenderPresence.ONLINE, SenderType.ANY))
|
for (String senderName : IdUtil.getNames(SenderPresence.ONLINE, SenderType.ANY))
|
||||||
{
|
{
|
||||||
if ( ! predicate.apply(senderName)) continue;
|
if ( ! predicate.test(senderName)) continue;
|
||||||
if (current.contains(senderName)) continue;
|
if (current.contains(senderName)) continue;
|
||||||
if ( ! MixinVisibility.get().isVisible(senderName, watcher)) continue;
|
if ( ! MixinVisibility.get().isVisible(senderName, watcher)) continue;
|
||||||
|
|
||||||
|
@ -70,7 +70,7 @@ public class EventMassiveCoreLorePriority extends EventMassiveCore
|
|||||||
// UTILITY SORT
|
// UTILITY SORT
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
|
||||||
public void setPriorityByPredicate(Predicate<String> predicate, int priority)
|
public void setPriorityByPredicate(java.util.function.Predicate<String> predicate, int priority)
|
||||||
{
|
{
|
||||||
// Look over all the lore ...
|
// Look over all the lore ...
|
||||||
for (Entry<String, Integer> loreEntry : this.getLore())
|
for (Entry<String, Integer> loreEntry : this.getLore())
|
||||||
@ -78,34 +78,29 @@ public class EventMassiveCoreLorePriority extends EventMassiveCore
|
|||||||
String line = loreEntry.getKey();
|
String line = loreEntry.getKey();
|
||||||
|
|
||||||
// ... and if predicate matches ...
|
// ... and if predicate matches ...
|
||||||
if ( ! predicate.apply(line)) continue;
|
if ( ! predicate.test(line)) continue;
|
||||||
|
|
||||||
// ... set priority.
|
// ... set priority.
|
||||||
loreEntry.setValue(priority);
|
loreEntry.setValue(priority);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
|
public void setPriorityByPredicate(Predicate<String> predicate, int priority)
|
||||||
|
{
|
||||||
|
setPriorityByPredicate((java.util.function.Predicate<String>) predicate, priority);
|
||||||
|
}
|
||||||
|
|
||||||
public void setPriorityByPrefix(final String prefix, int priority)
|
public void setPriorityByPrefix(final String prefix, int priority)
|
||||||
{
|
{
|
||||||
Predicate<String> predicate = new Predicate<String>()
|
java.util.function.Predicate<String> predicate = prefix::startsWith;
|
||||||
{
|
|
||||||
@Override public boolean apply(String type)
|
|
||||||
{
|
|
||||||
return type.startsWith(prefix);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
this.setPriorityByPredicate(predicate, priority);
|
this.setPriorityByPredicate(predicate, priority);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPriorityByRegex(final Pattern pattern, int priority)
|
public void setPriorityByRegex(final Pattern pattern, int priority)
|
||||||
{
|
{
|
||||||
Predicate<String> predicate = new Predicate<String>()
|
pattern.asPredicate();
|
||||||
{
|
java.util.function.Predicate<String> predicate = pattern.asPredicate();
|
||||||
@Override public boolean apply(String type)
|
|
||||||
{
|
|
||||||
return pattern.matcher(type).matches();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
this.setPriorityByPredicate(predicate, priority);
|
this.setPriorityByPredicate(predicate, priority);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,31 +48,46 @@ public interface EntityContainer<E>
|
|||||||
|
|
||||||
Collection<E> getAll();
|
Collection<E> getAll();
|
||||||
|
|
||||||
List<E> getAll(Iterable<?> oids, Predicate<? super E> where, Comparator<? super E> orderby, Integer limit, Integer offset);
|
List<E> getAll(Iterable<?> oids, java.util.function.Predicate<? super E> where, Comparator<? super E> orderby, Integer limit, Integer offset);
|
||||||
List<E> getAll(Iterable<?> oids, Predicate<? super E> where, Comparator<? super E> orderby, Integer limit);
|
List<E> getAll(Iterable<?> oids, java.util.function.Predicate<? super E> where, Comparator<? super E> orderby, Integer limit);
|
||||||
List<E> getAll(Iterable<?> oids, Predicate<? super E> where, Comparator<? super E> orderby);
|
List<E> getAll(Iterable<?> oids, java.util.function.Predicate<? super E> where, Comparator<? super E> orderby);
|
||||||
List<E> getAll(Iterable<?> oids, Predicate<? super E> where, Integer limit, Integer offset);
|
List<E> getAll(Iterable<?> oids, java.util.function.Predicate<? super E> where, Integer limit, Integer offset);
|
||||||
List<E> getAll(Iterable<?> oids, Predicate<? super E> where, Integer limit);
|
List<E> getAll(Iterable<?> oids, java.util.function.Predicate<? super E> where, Integer limit);
|
||||||
List<E> getAll(Iterable<?> oids, Comparator<? super E> orderby, Integer limit, Integer offset);
|
List<E> getAll(Iterable<?> oids, Comparator<? super E> orderby, Integer limit, Integer offset);
|
||||||
List<E> getAll(Iterable<?> oids, Comparator<? super E> orderby, Integer limit);
|
List<E> getAll(Iterable<?> oids, Comparator<? super E> orderby, Integer limit);
|
||||||
List<E> getAll(Iterable<?> oids, Predicate<? super E> where);
|
List<E> getAll(Iterable<?> oids, java.util.function.Predicate<? super E> where);
|
||||||
List<E> getAll(Iterable<?> oids, Comparator<? super E> orderby);
|
List<E> getAll(Iterable<?> oids, Comparator<? super E> orderby);
|
||||||
List<E> getAll(Iterable<?> oids, Integer limit, Integer offset);
|
List<E> getAll(Iterable<?> oids, Integer limit, Integer offset);
|
||||||
List<E> getAll(Iterable<?> oids, Integer limit);
|
List<E> getAll(Iterable<?> oids, Integer limit);
|
||||||
List<E> getAll(Iterable<?> oids);
|
List<E> getAll(Iterable<?> oids);
|
||||||
|
|
||||||
List<E> getAll(Predicate<? super E> where, Comparator<? super E> orderby, Integer limit, Integer offset);
|
List<E> getAll(java.util.function.Predicate<? super E> where, Comparator<? super E> orderby, Integer limit, Integer offset);
|
||||||
List<E> getAll(Predicate<? super E> where, Comparator<? super E> orderby, Integer limit);
|
List<E> getAll(java.util.function.Predicate<? super E> where, Comparator<? super E> orderby, Integer limit);
|
||||||
List<E> getAll(Predicate<? super E> where, Comparator<? super E> orderby);
|
List<E> getAll(java.util.function.Predicate<? super E> where, Comparator<? super E> orderby);
|
||||||
List<E> getAll(Predicate<? super E> where, Integer limit, Integer offset);
|
List<E> getAll(java.util.function.Predicate<? super E> where, Integer limit, Integer offset);
|
||||||
List<E> getAll(Predicate<? super E> where, Integer limit);
|
List<E> getAll(java.util.function.Predicate<? super E> where, Integer limit);
|
||||||
List<E> getAll(Comparator<? super E> orderby, Integer limit, Integer offset);
|
List<E> getAll(Comparator<? super E> orderby, Integer limit, Integer offset);
|
||||||
List<E> getAll(Comparator<? super E> orderby, Integer limit);
|
List<E> getAll(Comparator<? super E> orderby, Integer limit);
|
||||||
List<E> getAll(Predicate<? super E> where);
|
List<E> getAll(java.util.function.Predicate<? super E> where);
|
||||||
List<E> getAll(Comparator<? super E> orderby);
|
List<E> getAll(Comparator<? super E> orderby);
|
||||||
List<E> getAll(Integer limit, Integer offset);
|
List<E> getAll(Integer limit, Integer offset);
|
||||||
List<E> getAll(Integer limit);
|
List<E> getAll(Integer limit);
|
||||||
|
|
||||||
|
// OLD PREDICATE
|
||||||
|
@Deprecated List<E> getAll(Predicate<? super E> where, Comparator<? super E> orderby, Integer limit, Integer offset);
|
||||||
|
@Deprecated List<E> getAll(Predicate<? super E> where, Comparator<? super E> orderby, Integer limit);
|
||||||
|
@Deprecated List<E> getAll(Predicate<? super E> where, Comparator<? super E> orderby);
|
||||||
|
@Deprecated List<E> getAll(Predicate<? super E> where, Integer limit, Integer offset);
|
||||||
|
@Deprecated List<E> getAll(Predicate<? super E> where, Integer limit);
|
||||||
|
@Deprecated List<E> getAll(Predicate<? super E> where);
|
||||||
|
|
||||||
|
@Deprecated List<E> getAll(Iterable<?> oids, Predicate<? super E> where, Comparator<? super E> orderby, Integer limit, Integer offset);
|
||||||
|
@Deprecated List<E> getAll(Iterable<?> oids, Predicate<? super E> where, Comparator<? super E> orderby, Integer limit);
|
||||||
|
@Deprecated List<E> getAll(Iterable<?> oids, Predicate<? super E> where, Comparator<? super E> orderby);
|
||||||
|
@Deprecated List<E> getAll(Iterable<?> oids, Predicate<? super E> where, Integer limit, Integer offset);
|
||||||
|
@Deprecated List<E> getAll(Iterable<?> oids, Predicate<? super E> where, Integer limit);
|
||||||
|
@Deprecated List<E> getAll(Iterable<?> oids, Predicate<? super E> where);
|
||||||
|
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
// BEHAVIOR
|
// BEHAVIOR
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
package com.massivecraft.massivecore.store;
|
package com.massivecraft.massivecore.store;
|
||||||
|
|
||||||
import com.massivecraft.massivecore.Named;
|
import com.massivecraft.massivecore.Named;
|
||||||
import com.massivecraft.massivecore.predicate.Predicate;
|
|
||||||
import com.massivecraft.massivecore.predicate.PredicateEqualsIgnoreCase;
|
|
||||||
import com.massivecraft.massivecore.util.MUtil;
|
import com.massivecraft.massivecore.util.MUtil;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -11,6 +9,7 @@ import java.util.Collections;
|
|||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
// Calls fixId when necessary
|
// Calls fixId when necessary
|
||||||
public abstract class EntityContainerAbstract<E extends EntityInternal<E>> implements EntityContainer<E>
|
public abstract class EntityContainerAbstract<E extends EntityInternal<E>> implements EntityContainer<E>
|
||||||
@ -122,7 +121,6 @@ public abstract class EntityContainerAbstract<E extends EntityInternal<E>> imple
|
|||||||
{
|
{
|
||||||
// Return Create
|
// Return Create
|
||||||
List<E> ret = new ArrayList<>();
|
List<E> ret = new ArrayList<>();
|
||||||
|
|
||||||
// Return Fill
|
// Return Fill
|
||||||
for (Object oid : oids)
|
for (Object oid : oids)
|
||||||
{
|
{
|
||||||
@ -147,6 +145,21 @@ public abstract class EntityContainerAbstract<E extends EntityInternal<E>> imple
|
|||||||
@Override public List<E> getAll(Integer limit, Integer offset) { return MUtil.transform(this.getAll(), limit, offset); }
|
@Override public List<E> getAll(Integer limit, Integer offset) { return MUtil.transform(this.getAll(), limit, offset); }
|
||||||
@Override public List<E> getAll(Integer limit) { return MUtil.transform(this.getAll(), limit); }
|
@Override public List<E> getAll(Integer limit) { return MUtil.transform(this.getAll(), limit); }
|
||||||
|
|
||||||
|
// OLD PREDICATE
|
||||||
|
@Override public List<E> getAll(Iterable<?> oids, com.massivecraft.massivecore.predicate.Predicate<? super E> where, Comparator<? super E> orderby, Integer limit, Integer offset) { return MUtil.transform(this.getAll(oids), where, orderby, limit, offset); }
|
||||||
|
@Override public List<E> getAll(Iterable<?> oids, com.massivecraft.massivecore.predicate.Predicate<? super E> where, Comparator<? super E> orderby, Integer limit) { return MUtil.transform(this.getAll(oids), where, orderby, limit); }
|
||||||
|
@Override public List<E> getAll(Iterable<?> oids, com.massivecraft.massivecore.predicate.Predicate<? super E> where, Comparator<? super E> orderby) { return MUtil.transform(this.getAll(oids), where, orderby); }
|
||||||
|
@Override public List<E> getAll(Iterable<?> oids, com.massivecraft.massivecore.predicate.Predicate<? super E> where, Integer limit, Integer offset) { return MUtil.transform(this.getAll(oids), where, limit, offset); }
|
||||||
|
@Override public List<E> getAll(Iterable<?> oids, com.massivecraft.massivecore.predicate.Predicate<? super E> where, Integer limit) { return MUtil.transform(this.getAll(oids), where, limit); }
|
||||||
|
@Override public List<E> getAll(Iterable<?> oids, com.massivecraft.massivecore.predicate.Predicate<? super E> where) { return MUtil.transform(this.getAll(oids), where); }
|
||||||
|
|
||||||
|
@Override public List<E> getAll(com.massivecraft.massivecore.predicate.Predicate<? super E> where, Comparator<? super E> orderby, Integer limit, Integer offset) { return MUtil.transform(this.getAll(), where, orderby, limit, offset); }
|
||||||
|
@Override public List<E> getAll(com.massivecraft.massivecore.predicate.Predicate<? super E> where, Comparator<? super E> orderby, Integer limit) { return MUtil.transform(this.getAll(), where, orderby, limit); }
|
||||||
|
@Override public List<E> getAll(com.massivecraft.massivecore.predicate.Predicate<? super E> where, Comparator<? super E> orderby) { return MUtil.transform(this.getAll(), where, orderby); }
|
||||||
|
@Override public List<E> getAll(com.massivecraft.massivecore.predicate.Predicate<? super E> where, Integer limit, Integer offset) { return MUtil.transform(this.getAll(), where, limit, offset); }
|
||||||
|
@Override public List<E> getAll(com.massivecraft.massivecore.predicate.Predicate<? super E> where, Integer limit) { return MUtil.transform(this.getAll(), where, limit); }
|
||||||
|
@Override public List<E> getAll(com.massivecraft.massivecore.predicate.Predicate<? super E> where) { return MUtil.transform(this.getAll(), where); }
|
||||||
|
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
// BEHAVIOR
|
// BEHAVIOR
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
@ -398,7 +411,7 @@ public abstract class EntityContainerAbstract<E extends EntityInternal<E>> imple
|
|||||||
{
|
{
|
||||||
if (name == null) throw new NullPointerException("name");
|
if (name == null) throw new NullPointerException("name");
|
||||||
|
|
||||||
Predicate<String> predicate = PredicateEqualsIgnoreCase.get(name);
|
java.util.function.Predicate<String> predicate = name::equalsIgnoreCase;
|
||||||
for (E entity : this.getAll())
|
for (E entity : this.getAll())
|
||||||
{
|
{
|
||||||
if (entity == null) continue;
|
if (entity == null) continue;
|
||||||
@ -406,7 +419,7 @@ public abstract class EntityContainerAbstract<E extends EntityInternal<E>> imple
|
|||||||
if ( ! (entity instanceof Named)) continue;
|
if ( ! (entity instanceof Named)) continue;
|
||||||
Named named = (Named)entity;
|
Named named = (Named)entity;
|
||||||
|
|
||||||
if (predicate.apply(named.getName())) return entity;
|
if (predicate.test(named.getName())) return entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
@ -13,7 +13,6 @@ import com.massivecraft.massivecore.engine.EngineMassiveCoreWorldNameSet;
|
|||||||
import com.massivecraft.massivecore.integration.liability.IntegrationLiabilityAreaEffectCloud;
|
import com.massivecraft.massivecore.integration.liability.IntegrationLiabilityAreaEffectCloud;
|
||||||
import com.massivecraft.massivecore.mixin.MixinMessage;
|
import com.massivecraft.massivecore.mixin.MixinMessage;
|
||||||
import com.massivecraft.massivecore.nms.NmsEntityGet;
|
import com.massivecraft.massivecore.nms.NmsEntityGet;
|
||||||
import com.massivecraft.massivecore.predicate.Predicate;
|
|
||||||
import com.massivecraft.massivecore.predicate.PredicateElementGarbage;
|
import com.massivecraft.massivecore.predicate.PredicateElementGarbage;
|
||||||
import com.massivecraft.massivecore.predicate.PredicateElementSignificant;
|
import com.massivecraft.massivecore.predicate.PredicateElementSignificant;
|
||||||
import com.massivecraft.massivecore.util.extractor.Extractor;
|
import com.massivecraft.massivecore.util.extractor.Extractor;
|
||||||
@ -77,6 +76,7 @@ import java.util.SortedSet;
|
|||||||
import java.util.TreeSet;
|
import java.util.TreeSet;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
import java.util.function.Predicate;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
@ -1418,6 +1418,12 @@ public class MUtil
|
|||||||
// TRANSFORM
|
// TRANSFORM
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
|
public static <T> List<T> transform(Iterable<T> items, com.massivecraft.massivecore.predicate.Predicate<? super T> where, Comparator<? super T> orderby, Integer limit, Integer offset)
|
||||||
|
{
|
||||||
|
return transform(items, (Predicate<? super T>) where, orderby, limit, offset);
|
||||||
|
}
|
||||||
|
|
||||||
public static <T> List<T> transform(Iterable<T> items, Predicate<? super T> where, Comparator<? super T> orderby, Integer limit, Integer offset)
|
public static <T> List<T> transform(Iterable<T> items, Predicate<? super T> where, Comparator<? super T> orderby, Integer limit, Integer offset)
|
||||||
{
|
{
|
||||||
// Collection
|
// Collection
|
||||||
@ -1454,7 +1460,7 @@ public class MUtil
|
|||||||
|
|
||||||
for (T item : items)
|
for (T item : items)
|
||||||
{
|
{
|
||||||
if (where.apply(item))
|
if (where.test(item))
|
||||||
{
|
{
|
||||||
ret.add(item);
|
ret.add(item);
|
||||||
}
|
}
|
||||||
@ -1516,6 +1522,13 @@ public class MUtil
|
|||||||
public static <T> List<T> transform(Iterable<T> items, Integer limit) { return transform(items, null, null, limit, null); }
|
public static <T> List<T> transform(Iterable<T> items, Integer limit) { return transform(items, null, null, limit, null); }
|
||||||
public static <T> List<T> transform(Iterable<T> items, Integer limit, Integer offset) { return transform(items, null, null, limit, offset); }
|
public static <T> List<T> transform(Iterable<T> items, Integer limit, Integer offset) { return transform(items, null, null, limit, offset); }
|
||||||
|
|
||||||
|
// OLD PREDICATE
|
||||||
|
@Deprecated public static <T> List<T> transform(Iterable<T> items, com.massivecraft.massivecore.predicate.Predicate<? super T> where) { return transform(items, where, null, null, null); }
|
||||||
|
@Deprecated public static <T> List<T> transform(Iterable<T> items, com.massivecraft.massivecore.predicate.Predicate<? super T> where, Comparator<? super T> orderby) { return transform(items, where, orderby, null, null); }
|
||||||
|
@Deprecated public static <T> List<T> transform(Iterable<T> items, com.massivecraft.massivecore.predicate.Predicate<? super T> where, Comparator<? super T> orderby, Integer limit) { return transform(items, where, orderby, limit, null); }
|
||||||
|
@Deprecated public static <T> List<T> transform(Iterable<T> items, com.massivecraft.massivecore.predicate.Predicate<? super T> where, Integer limit) { return transform(items, where, null, limit, null); }
|
||||||
|
@Deprecated public static <T> List<T> transform(Iterable<T> items, com.massivecraft.massivecore.predicate.Predicate<? super T> where, Integer limit, Integer offset) { return transform(items, where, null, limit, offset); }
|
||||||
|
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
// SIMPLE CONSTRUCTORS
|
// SIMPLE CONSTRUCTORS
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
@ -1814,6 +1827,7 @@ public class MUtil
|
|||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
// MATH
|
// MATH
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
|
||||||
public static <T extends Number> T limitNumber(T d, T min, T max)
|
public static <T extends Number> T limitNumber(T d, T min, T max)
|
||||||
{
|
{
|
||||||
if (d.doubleValue() < min.doubleValue())
|
if (d.doubleValue() < min.doubleValue())
|
||||||
@ -1854,6 +1868,42 @@ public class MUtil
|
|||||||
return bd.doubleValue();
|
return bd.doubleValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// -------------------------------------------- //
|
||||||
|
// PREDICATE
|
||||||
|
// -------------------------------------------- //
|
||||||
|
|
||||||
|
public static <T> Predicate<T> predicatesAnd(Predicate<? super T>... predicates)
|
||||||
|
{
|
||||||
|
List<Predicate<? super T>> predicateList = Arrays.asList(predicates); // Must be explicit this way
|
||||||
|
return predicatesAnd(predicateList);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> Predicate<T> predicatesAnd(Collection<Predicate<? super T>> predicates)
|
||||||
|
{
|
||||||
|
if (predicates.isEmpty()) throw new IllegalArgumentException("isEmpty");
|
||||||
|
|
||||||
|
PredicateAnd<T> predicate = new PredicateAnd<T>();
|
||||||
|
predicate.predicates = new MassiveList<>(predicates);
|
||||||
|
|
||||||
|
return predicate;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class PredicateAnd<T> implements Predicate<T>
|
||||||
|
{
|
||||||
|
private List<Predicate<? super T>> predicates;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean test(T t)
|
||||||
|
{
|
||||||
|
for (Predicate<? super T> predicate : predicates)
|
||||||
|
{
|
||||||
|
if (predicate.test(t)) continue;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
// EXTRACTION
|
// EXTRACTION
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
@ -3,8 +3,6 @@ package com.massivecraft.massivecore.util;
|
|||||||
import com.google.common.reflect.ClassPath;
|
import com.google.common.reflect.ClassPath;
|
||||||
import com.massivecraft.massivecore.collections.MassiveList;
|
import com.massivecraft.massivecore.collections.MassiveList;
|
||||||
import com.massivecraft.massivecore.comparator.ComparatorNaturalOrder;
|
import com.massivecraft.massivecore.comparator.ComparatorNaturalOrder;
|
||||||
import com.massivecraft.massivecore.predicate.Predicate;
|
|
||||||
import com.massivecraft.massivecore.predicate.PredicateAnd;
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -20,6 +18,7 @@ import java.util.Collection;
|
|||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
public class ReflectionUtil
|
public class ReflectionUtil
|
||||||
{
|
{
|
||||||
@ -408,7 +407,7 @@ public class ReflectionUtil
|
|||||||
{
|
{
|
||||||
for (Class<?> superClazz : getSuperclasses(clazz, includeSelf))
|
for (Class<?> superClazz : getSuperclasses(clazz, includeSelf))
|
||||||
{
|
{
|
||||||
if (predicate.apply(superClazz)) return superClazz;
|
if (predicate.test(superClazz)) return superClazz;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -418,7 +417,7 @@ public class ReflectionUtil
|
|||||||
return getSuperclassPredicate(clazz, includeSelf, new Predicate<Class<?>>()
|
return getSuperclassPredicate(clazz, includeSelf, new Predicate<Class<?>>()
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
public boolean apply(Class<?> clazz)
|
public boolean test(Class<?> clazz)
|
||||||
{
|
{
|
||||||
for (Method method : clazz.getDeclaredMethods())
|
for (Method method : clazz.getDeclaredMethods())
|
||||||
{
|
{
|
||||||
@ -434,7 +433,7 @@ public class ReflectionUtil
|
|||||||
return getSuperclassPredicate(clazz, includeSelf, new Predicate<Class<?>>()
|
return getSuperclassPredicate(clazz, includeSelf, new Predicate<Class<?>>()
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
public boolean apply(Class<?> clazz)
|
public boolean test(Class<?> clazz)
|
||||||
{
|
{
|
||||||
for (Field field : clazz.getDeclaredFields())
|
for (Field field : clazz.getDeclaredFields())
|
||||||
{
|
{
|
||||||
@ -450,7 +449,7 @@ public class ReflectionUtil
|
|||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public static List<Class<?>> getPackageClasses(String packageName, ClassLoader classLoader, boolean recursive, Predicate<Class<?>>... predicates)
|
public static List<Class<?>> getPackageClasses(String packageName, ClassLoader classLoader, boolean recursive, java.util.function.Predicate<Class<?>>... predicates)
|
||||||
{
|
{
|
||||||
// Create ret
|
// Create ret
|
||||||
List<Class<?>> ret = new MassiveList<>();
|
List<Class<?>> ret = new MassiveList<>();
|
||||||
@ -459,7 +458,7 @@ public class ReflectionUtil
|
|||||||
{
|
{
|
||||||
// Get info
|
// Get info
|
||||||
ClassPath classPath = ClassPath.from(classLoader);
|
ClassPath classPath = ClassPath.from(classLoader);
|
||||||
Predicate<Class<?>> predicateCombined = PredicateAnd.get(predicates);
|
Predicate<Class<?>> predicateCombined = MUtil.predicatesAnd(predicates);
|
||||||
|
|
||||||
Collection<ClassPath.ClassInfo> classInfos = recursive ? classPath.getTopLevelClassesRecursive(packageName) : classPath.getTopLevelClasses(packageName);
|
Collection<ClassPath.ClassInfo> classInfos = recursive ? classPath.getTopLevelClassesRecursive(packageName) : classPath.getTopLevelClasses(packageName);
|
||||||
|
|
||||||
@ -486,7 +485,7 @@ public class ReflectionUtil
|
|||||||
}
|
}
|
||||||
|
|
||||||
// And it must not be ignored
|
// And it must not be ignored
|
||||||
if (!predicateCombined.apply(clazz)) continue;
|
if (!predicateCombined.test(clazz)) continue;
|
||||||
|
|
||||||
ret.add(clazz);
|
ret.add(clazz);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user