Removed java.lang FunctionalInterface clones

This commit is contained in:
Auxilor 2020-12-29 22:26:21 +00:00
parent 0940a56b4c
commit ef65fc35d1
14 changed files with 78 additions and 141 deletions

View File

@ -3,7 +3,6 @@ package com.willfp.ecoenchants.enchantments.meta;
import com.google.common.collect.ImmutableList;
import com.willfp.eco.util.config.Configs;
import com.willfp.eco.util.config.annotations.ConfigUpdater;
import com.willfp.eco.util.lambda.ObjectCallable;
import com.willfp.ecoenchants.enchantments.EcoEnchant;
import com.willfp.ecoenchants.enchantments.itemtypes.Artifact;
import com.willfp.ecoenchants.enchantments.itemtypes.Spell;
@ -13,6 +12,7 @@ import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Supplier;
public class EnchantmentType {
/**
@ -80,12 +80,12 @@ public class EnchantmentType {
/**
* Lambda to fetch the color of the type.
*/
private final ObjectCallable<String> colorCallable;
private final Supplier<String> colorSupplier;
/**
* Lambda to fetch the singularity of the type.
*/
private final ObjectCallable<Boolean> singularCallable;
private final Supplier<Boolean> singularSupplier;
/**
* If only one enchantment of this type is allowed on an item.
@ -136,12 +136,12 @@ public class EnchantmentType {
*
* @param name The name of the type.
* @param singular Whether an item can have several enchantments of this type.
* @param colorCallable Lambda to fetch the color of enchantments with this type to have. Updates on /ecoreload.
* @param colorSupplier Lambda to fetch the color of enchantments with this type to have. Updates on /ecoreload.
*/
public EnchantmentType(@NotNull final String name,
final boolean singular,
@NotNull final ObjectCallable<String> colorCallable) {
this(name, () -> singular, colorCallable);
@NotNull final Supplier<String> colorSupplier) {
this(name, () -> singular, colorSupplier);
}
/**
@ -151,57 +151,57 @@ public class EnchantmentType {
*
* @param name The name of the type.
* @param singular Whether an item can have several enchantments of this type.
* @param colorCallable Lambda to fetch the color of enchantments with this type to have. Updates on /ecoreload.
* @param colorSupplier Lambda to fetch the color of enchantments with this type to have. Updates on /ecoreload.
* @param requiredToExtend Class that all enchantments of this type must extend - or null if not required.
*/
public EnchantmentType(@NotNull final String name,
final boolean singular,
@NotNull final ObjectCallable<String> colorCallable,
@NotNull final Supplier<String> colorSupplier,
@Nullable final Class<? extends EcoEnchant> requiredToExtend) {
this(name, () -> singular, colorCallable, requiredToExtend);
this(name, () -> singular, colorSupplier, requiredToExtend);
}
/**
* Create EnchantmentType with updatable color and singularity.
*
* @param name The name of the type.
* @param singularCallable Lambda to fetch whether an item can have several enchantments of this type. Updates on /ecoreload.
* @param colorCallable Lambda to fetch the color of enchantments with this type to have. Updates on /ecoreload.
* @param singularSupplier Lambda to fetch whether an item can have several enchantments of this type. Updates on /ecoreload.
* @param colorSupplier Lambda to fetch the color of enchantments with this type to have. Updates on /ecoreload.
*/
public EnchantmentType(@NotNull final String name,
@NotNull final ObjectCallable<Boolean> singularCallable,
@NotNull final ObjectCallable<String> colorCallable) {
this(name, singularCallable, colorCallable, null);
@NotNull final Supplier<Boolean> singularSupplier,
@NotNull final Supplier<String> colorSupplier) {
this(name, singularSupplier, colorSupplier, null);
}
/**
* Create EnchantmentType with updatable color and singularity that <b>must</b> extend a specified class.
*
* @param name The name of the type.
* @param singularCallable Lambda to fetch whether an item can have several enchantments of this type. Updates on /ecoreload.
* @param colorCallable Lambda to fetch the color of enchantments with this type to have. Updates on /ecoreload.
* @param singularSupplier Lambda to fetch whether an item can have several enchantments of this type. Updates on /ecoreload.
* @param colorSupplier Lambda to fetch the color of enchantments with this type to have. Updates on /ecoreload.
* @param requiredToExtend Class that all enchantments of this type must extend - or null if not required.
*/
public EnchantmentType(@NotNull final String name,
@NotNull final ObjectCallable<Boolean> singularCallable,
@NotNull final ObjectCallable<String> colorCallable,
@NotNull final Supplier<Boolean> singularSupplier,
@NotNull final Supplier<String> colorSupplier,
@Nullable final Class<? extends EcoEnchant> requiredToExtend) {
this.name = name;
this.singularCallable = singularCallable;
this.colorCallable = colorCallable;
this.singularSupplier = singularSupplier;
this.colorSupplier = colorSupplier;
this.requiredToExtend = requiredToExtend;
color = colorCallable.call();
singular = singularCallable.call();
color = colorSupplier.get();
singular = singularSupplier.get();
REGISTERED.add(this);
}
private void refresh() {
this.color = colorCallable.call();
this.singular = singularCallable.call();
this.color = colorSupplier.get();
this.singular = singularSupplier.get();
}
/**
* Update callables of all types.
* Update suppliers of all types.
*/
@ConfigUpdater
public static void update() {

View File

@ -1,7 +1,6 @@
package com.willfp.ecoenchants.enchantments.util;
import com.willfp.eco.util.lambda.Callable;
import com.willfp.ecoenchants.enchantments.itemtypes.Spell;
import lombok.Getter;
import lombok.Setter;
@ -32,7 +31,7 @@ public class SpellRunnable {
* Must be set before execution.
*/
@Setter
private Callable task = () -> {
private Runnable task = () -> {
// Empty as must be set using this#setTask
};
@ -52,7 +51,7 @@ public class SpellRunnable {
* Run the runnable.
*/
public void run() {
task.call();
task.run();
updateEndTime();
}

View File

@ -1,7 +1,6 @@
package com.willfp.eco.util.bukkit.scheduling;
import com.willfp.eco.util.injection.PluginDependent;
import com.willfp.eco.util.lambda.Callable;
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
import org.bukkit.Bukkit;
import org.bukkit.scheduler.BukkitTask;
@ -22,44 +21,44 @@ public class EcoScheduler extends PluginDependent implements Scheduler {
/**
* Run the task after a specified tick delay.
*
* @param callable The lambda to run.
* @param runnable The lambda to run.
* @param ticksLater The amount of ticks to wait before execution.
* @return The created {@link BukkitTask}.
*/
@Override
public BukkitTask runLater(@NotNull final Callable callable,
public BukkitTask runLater(@NotNull final Runnable runnable,
final long ticksLater) {
return Bukkit.getScheduler().runTaskLater(this.getPlugin(), callable::call, ticksLater);
return Bukkit.getScheduler().runTaskLater(this.getPlugin(), runnable, ticksLater);
}
/**
* Run the task repeatedly on a timer.
*
* @param callable The lambda to run.
* @param runnable The lambda to run.
* @param delay The amount of ticks to wait before the first execution.
* @param repeat The amount of ticks to wait between executions.
* @return The created {@link BukkitTask}.
*/
@Override
public BukkitTask runTimer(@NotNull final Callable callable,
public BukkitTask runTimer(@NotNull final Runnable runnable,
final long delay,
final long repeat) {
return Bukkit.getScheduler().runTaskTimer(this.getPlugin(), callable::call, delay, repeat);
return Bukkit.getScheduler().runTaskTimer(this.getPlugin(), runnable, delay, repeat);
}
/**
* Run the task repeatedly and asynchronously on a timer.
*
* @param callable The lambda to run.
* @param runnable The lambda to run.
* @param delay The amount of ticks to wait before the first execution.
* @param repeat The amount of ticks to wait between executions.
* @return The created {@link BukkitTask}.
*/
@Override
public BukkitTask runAsyncTimer(@NotNull final Callable callable,
public BukkitTask runAsyncTimer(@NotNull final Runnable runnable,
final long delay,
final long repeat) {
return Bukkit.getScheduler().runTaskTimerAsynchronously(this.getPlugin(), callable::call, delay, repeat);
return Bukkit.getScheduler().runTaskTimerAsynchronously(this.getPlugin(), runnable, delay, repeat);
}
/**
@ -76,12 +75,12 @@ public class EcoScheduler extends PluginDependent implements Scheduler {
/**
* Run the task asynchronously.
*
* @param callable The lambda to run.
* @param runnable The lambda to run.
* @return The created {@link BukkitTask}.
*/
@Override
public BukkitTask runAsync(@NotNull final Callable callable) {
return Bukkit.getScheduler().runTaskAsynchronously(this.getPlugin(), callable::call);
public BukkitTask runAsync(@NotNull final Runnable runnable) {
return Bukkit.getScheduler().runTaskAsynchronously(this.getPlugin(), runnable);
}
/**

View File

@ -1,10 +1,11 @@
package com.willfp.eco.util.bukkit.scheduling;
import com.willfp.eco.util.factory.PluginDependentFactory;
import com.willfp.eco.util.lambda.InputCallable;
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
import org.jetbrains.annotations.NotNull;
import java.util.function.Consumer;
public class RunnableFactory extends PluginDependentFactory {
/**
* Factory class to produce {@link EcoBukkitRunnable}s associated with an {@link AbstractEcoPlugin}.
@ -18,14 +19,14 @@ public class RunnableFactory extends PluginDependentFactory {
/**
* Create an {@link EcoBukkitRunnable}.
*
* @param callable Lambda of the code to run, where the parameter represents the instance of the runnable.
* @param consumer Lambda of the code to run, where the parameter represents the instance of the runnable.
* @return The created {@link EcoBukkitRunnable}.
*/
public EcoBukkitRunnable create(@NotNull final InputCallable<EcoBukkitRunnable> callable) {
public EcoBukkitRunnable create(@NotNull final Consumer<EcoBukkitRunnable> consumer) {
return new EcoBukkitRunnable(this.getPlugin()) {
@Override
public void run() {
callable.call(this);
consumer.accept(this);
}
};
}

View File

@ -1,6 +1,5 @@
package com.willfp.eco.util.bukkit.scheduling;
import com.willfp.eco.util.lambda.Callable;
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
import org.bukkit.scheduler.BukkitTask;
import org.jetbrains.annotations.NotNull;
@ -9,31 +8,31 @@ public interface Scheduler {
/**
* Run the task after a specified tick delay.
*
* @param callable The lambda to run.
* @param runnable The lambda to run.
* @param ticksLater The amount of ticks to wait before execution.
* @return The created {@link BukkitTask}.
*/
BukkitTask runLater(@NotNull Callable callable, long ticksLater);
BukkitTask runLater(@NotNull Runnable runnable, long ticksLater);
/**
* Run the task repeatedly on a timer.
*
* @param callable The lambda to run.
* @param runnable The lambda to run.
* @param delay The amount of ticks to wait before the first execution.
* @param repeat The amount of ticks to wait between executions.
* @return The created {@link BukkitTask}.
*/
BukkitTask runTimer(@NotNull Callable callable, long delay, long repeat);
BukkitTask runTimer(@NotNull Runnable runnable, long delay, long repeat);
/**
* Run the task repeatedly and asynchronously on a timer.
*
* @param callable The lambda to run.
* @param runnable The lambda to run.
* @param delay The amount of ticks to wait before the first execution.
* @param repeat The amount of ticks to wait between executions.
* @return The created {@link BukkitTask}.
*/
BukkitTask runAsyncTimer(@NotNull Callable callable, long delay, long repeat);
BukkitTask runAsyncTimer(@NotNull Runnable runnable, long delay, long repeat);
/**
* Run the task.
@ -46,10 +45,10 @@ public interface Scheduler {
/**
* Run the task asynchronously.
*
* @param callable The lambda to run.
* @param runnable The lambda to run.
* @return The created {@link BukkitTask}.
*/
BukkitTask runAsync(@NotNull Callable callable);
BukkitTask runAsync(@NotNull Runnable runnable);
/**
* Schedule the task to be ran repeatedly on a timer.

View File

@ -1,17 +1,17 @@
package com.willfp.eco.util.drops.telekinesis;
import com.willfp.eco.util.lambda.ObjectInputCallable;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import java.util.HashSet;
import java.util.Set;
import java.util.function.Function;
public class EcoTelekinesisTests implements TelekinesisTests {
/**
* Set of tests that return if the player is telekinetic.
*/
private final Set<ObjectInputCallable<Boolean, Player>> tests = new HashSet<>();
private final Set<Function<Player, Boolean>> tests = new HashSet<>();
/**
* Register a new test to check against.
@ -19,7 +19,7 @@ public class EcoTelekinesisTests implements TelekinesisTests {
* @param test The test to register, where the boolean output is if the player is telekinetic.
*/
@Override
public void registerTest(@NotNull final ObjectInputCallable<Boolean, Player> test) {
public void registerTest(@NotNull final Function<Player, Boolean> test) {
tests.add(test);
}
@ -33,8 +33,8 @@ public class EcoTelekinesisTests implements TelekinesisTests {
*/
@Override
public boolean testPlayer(@NotNull final Player player) {
for (ObjectInputCallable<Boolean, Player> test : tests) {
if (test.call(player)) {
for (Function<Player, Boolean> test : tests) {
if (test.apply(player)) {
return true;
}
}

View File

@ -1,16 +1,17 @@
package com.willfp.eco.util.drops.telekinesis;
import com.willfp.eco.util.lambda.ObjectInputCallable;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import java.util.function.Function;
public interface TelekinesisTests {
/**
* Register a new test to check against.
*
* @param test The test to register, where the boolean output is if the player is telekinetic.
*/
void registerTest(@NotNull ObjectInputCallable<Boolean, Player> test);
void registerTest(@NotNull Function<Player, Boolean> test);
/**
* Test the player for telekinesis.

View File

@ -1,6 +1,5 @@
package com.willfp.eco.util.integrations;
import com.willfp.eco.util.lambda.Callable;
import lombok.Getter;
import org.jetbrains.annotations.NotNull;
@ -8,7 +7,7 @@ public class IntegrationLoader {
/**
* The lambda to be ran if the plugin is present.
*/
private final Callable callable;
private final Runnable runnable;
/**
* The plugin to require to load the integration.
@ -23,8 +22,8 @@ public class IntegrationLoader {
* @param onLoad The lambda to be ran if the plugin is present.
*/
public IntegrationLoader(@NotNull final String pluginName,
@NotNull final Callable onLoad) {
this.callable = onLoad;
@NotNull final Runnable onLoad) {
this.runnable = onLoad;
this.pluginName = pluginName;
}
@ -32,6 +31,6 @@ public class IntegrationLoader {
* Load the integration.
*/
public void load() {
callable.call();
runnable.run();
}
}

View File

@ -1,12 +1,13 @@
package com.willfp.eco.util.integrations.placeholder;
import com.willfp.eco.util.lambda.ObjectInputCallable;
import lombok.Getter;
import org.apache.commons.lang.Validate;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.function.Function;
public class PlaceholderEntry {
/**
* The name of the placeholder, used in lookups.
@ -17,7 +18,7 @@ public class PlaceholderEntry {
/**
* The lambda to retrieve the output of the placeholder given a player.
*/
private final ObjectInputCallable<String, Player> function;
private final Function<Player, String> function;
/**
* If the placeholder requires a player to lookup.
@ -31,7 +32,7 @@ public class PlaceholderEntry {
* @param function A lambda to get the result of the placeholder given a player.
*/
public PlaceholderEntry(@NotNull final String identifier,
@NotNull final ObjectInputCallable<String, Player> function) {
@NotNull final Function<Player, String> function) {
this(identifier, function, false);
}
@ -43,7 +44,7 @@ public class PlaceholderEntry {
* @param requiresPlayer If the placeholder requires a player.
*/
public PlaceholderEntry(@NotNull final String identifier,
@NotNull final ObjectInputCallable<String, Player> function,
@NotNull final Function<Player, String> function,
final boolean requiresPlayer) {
this.identifier = identifier;
this.function = function;
@ -60,7 +61,7 @@ public class PlaceholderEntry {
if (player == null) {
Validate.isTrue(!requiresPlayer, "null player passed to requiresPlayer placeholder.");
}
return this.function.call(player);
return this.function.apply(player);
}
/**

View File

@ -1,12 +0,0 @@
package com.willfp.eco.util.lambda;
/**
* Represents code that can be later executed.
*/
@FunctionalInterface
public interface Callable {
/**
* Execute the lambda.
*/
void call();
}

View File

@ -1,16 +0,0 @@
package com.willfp.eco.util.lambda;
/**
* Functional Interface that requires an object as a parameter.
*
* @param <A> The type of the object to require.
*/
@FunctionalInterface
public interface InputCallable<A> {
/**
* Execute the lambda.
*
* @param object The lambda parameter.
*/
void call(A object);
}

View File

@ -1,16 +0,0 @@
package com.willfp.eco.util.lambda;
/**
* Functional Interface to return a value of a given type.
*
* @param <A> The type to return.
*/
@FunctionalInterface
public interface ObjectCallable<A> {
/**
* Execute the lambda.
*
* @return The return value of the specified type.
*/
A call();
}

View File

@ -1,18 +0,0 @@
package com.willfp.eco.util.lambda;
/**
* Functional Interface to return a value of a specified type given a certain parameter.
*
* @param <A> The type of object to return
* @param <B> The type of object for the parameter
*/
@FunctionalInterface
public interface ObjectInputCallable<A, B> {
/**
* Execute the lambda.
*
* @param object The lambda parameter.
* @return The required return type.
*/
A call(B object);
}

View File

@ -1,7 +1,6 @@
package com.willfp.eco.util.optional;
import com.willfp.eco.util.ClassUtils;
import com.willfp.eco.util.lambda.ObjectCallable;
import lombok.Getter;
import org.bukkit.Bukkit;
import org.jetbrains.annotations.NotNull;
@ -9,6 +8,7 @@ import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.function.Supplier;
public class Prerequisite {
/**
@ -41,7 +41,7 @@ public class Prerequisite {
/**
* Retrieve if the necessary prerequisite condition is met.
*/
private final ObjectCallable<Boolean> isMetCallable;
private final Supplier<Boolean> isMetSupplier;
/**
* The description of the requirements of the prerequisite.
@ -52,22 +52,22 @@ public class Prerequisite {
/**
* Create a prerequisite.
*
* @param isMetCallable An {@link ObjectCallable<Boolean>} that returns if the prerequisite is met
* @param isMetSupplier An {@link Supplier<Boolean>} that returns if the prerequisite is met
* @param description The description of the prerequisite, shown to the user if it isn't
*/
public Prerequisite(@NotNull final ObjectCallable<Boolean> isMetCallable,
public Prerequisite(@NotNull final Supplier<Boolean> isMetSupplier,
@NotNull final String description) {
this.isMetCallable = isMetCallable;
this.isMet = isMetCallable.call();
this.isMetSupplier = isMetSupplier;
this.isMet = isMetSupplier.get();
this.description = description;
VALUES.add(this);
}
/**
* Refresh the condition set in the callable, updates {@link this#isMet}.
* Refresh the condition set in the supplier, updates {@link this#isMet}.
*/
private void refresh() {
this.isMet = this.isMetCallable.call();
this.isMet = this.isMetSupplier.get();
}
/**