Skip to content

Commit

Permalink
Merge pull request #36 from Etrayed/fix/redundant-interfaces
Browse files Browse the repository at this point in the history
Interface Changes
  • Loading branch information
PXAV committed Dec 30, 2020
2 parents 55cb23a + abead07 commit d139862
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 46 deletions.
Expand Up @@ -7,6 +7,7 @@
*
* @author pxav
*/
@FunctionalInterface
public interface ClickListener {

/**
Expand Down

This file was deleted.

Expand Up @@ -4,6 +4,8 @@
import de.pxav.kelp.core.inventory.item.KelpItem;
import de.pxav.kelp.core.player.KelpPlayer;

import java.util.function.Supplier;

/**
* This widget is used to handle button interactions
* toggling a certain setting.
Expand All @@ -29,7 +31,7 @@ public class ToggleableWidget implements SimpleWidget {
private KelpPlayer player;

// the condition to be checked every time the widget updates
private Condition condition;
private Supplier<Boolean> condition;

// The slot of the inventory, where the widget should finally be located.
private int slot;
Expand Down Expand Up @@ -64,7 +66,7 @@ public ToggleableWidget slot(int slot) {
* @param condition The condition to be fulfilled.
* @return Current instance of the widget.
*/
public ToggleableWidget condition(Condition condition) {
public ToggleableWidget condition(Supplier<Boolean> condition) {
this.condition = condition;
return this;
}
Expand Down Expand Up @@ -178,7 +180,7 @@ public KelpPlayer getPlayer() {
*/
@Override
public KelpItem render() {
if (condition.getCondition()) {
if (condition.get()) {
return this.whenTrue.slot(slot);
} else {
return this.whenFalse.slot(slot);
Expand Down
Expand Up @@ -2,6 +2,7 @@

import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.util.function.Predicate;

/**
* This class contains all criteria you can use for searching/filtering
Expand All @@ -10,9 +11,8 @@
* @see MethodFinder
* @author pxav
*/
public interface MethodCriterion {

boolean matches(Method method);
@FunctionalInterface
public interface MethodCriterion extends Predicate<Method> {

static MethodCriterion annotatedWith(Class<? extends Annotation> annotation) {
return method -> method.isAnnotationPresent(annotation);
Expand All @@ -36,4 +36,7 @@ static MethodCriterion locatedIn(String packageName) {
.equals(packageName);
}

static MethodCriterion fromPredicate(Predicate<Method> predicate) {
return predicate::test;
}
}
Expand Up @@ -57,7 +57,7 @@ public Stream<Method> filter(String[] packageNames, MethodCriterion... methodCri

boolean allMatch = true;
for (MethodCriterion methodCriterion : methodCriteria) {
if (!methodCriterion.matches(method)) {
if (!methodCriterion.test(method)) {
allMatch = false;
break;
}
Expand Down
16 changes: 6 additions & 10 deletions core/src/main/java/de/pxav/kelp/core/reflect/TypeCriterion.java
@@ -1,6 +1,7 @@
package de.pxav.kelp.core.reflect;

import java.lang.annotation.Annotation;
import java.util.function.Predicate;

/**
* This class contains all criteria you can use for searching/filtering
Expand All @@ -9,16 +10,8 @@
* @see TypeFinder
* @author pxav
*/
public interface TypeCriterion {

/**
* Returns {@code true} if the given criteria are fulfilled
* by the given class.
*
* @param c The class you want to check
* @return {@code true} if the criteria matches the class
*/
boolean matches(Class<?> c);
@FunctionalInterface
public interface TypeCriterion extends Predicate<Class<?>> {

/**
* Checks if the class is annotated with a certain
Expand Down Expand Up @@ -56,4 +49,7 @@ static TypeCriterion locatedIn(String packageName) {
return c -> c.getPackage().getName().equals(packageName);
}

static TypeCriterion fromPredicate(Predicate<Class<?>> predicate) {
return predicate::test;
}
}
Expand Up @@ -48,7 +48,7 @@ public Stream<Class<?>> filter(String[] packageNames, TypeCriterion... typeCrite
Class<?> c = current.loadClass();
boolean allMatch = true;
for (TypeCriterion typeCriterion : typeCriteria) {
if (!typeCriterion.matches(c)) {
if (!typeCriterion.test(c)) {
allMatch = false;
break;
}
Expand Down
Expand Up @@ -14,6 +14,7 @@
*
* @author pxav
*/
@FunctionalInterface
public interface KelpSchedulerRunnable {

/**
Expand Down
Expand Up @@ -11,6 +11,7 @@
*
* @author pxav
*/
@FunctionalInterface
public interface Retrievable {

/**
Expand Down

0 comments on commit d139862

Please sign in to comment.