Fix HeaderCondition

Signed-off-by: Quentin Legot <legotquentin@gmail.com>
This commit is contained in:
Quentin Legot 2023-03-19 19:53:54 +01:00
parent 19e1dd2937
commit be9c4de097
4 changed files with 12 additions and 5 deletions

View File

@ -1,4 +1,9 @@
package fr.altarik.toolbox.pagination;
public class PaginatedContent {
public PaginatedContent(String header, String content) {
// TODO: 19/03/2023
}
}

View File

@ -2,6 +2,7 @@ package fr.altarik.toolbox.pagination.api;
import net.minecraft.server.network.ServerPlayerEntity;
@SuppressWarnings("unused") // Api usage
public interface PaginationApi {
/**

View File

@ -12,6 +12,9 @@ import java.util.Map;
import java.util.function.Predicate;
public class PaginationApiImpl implements PaginationApi {
/**
* Integer represent relative tts of the paginated content, decreased by 1 every seconds
*/
private final Map<ServerPlayerEntity, Pair<Integer, PaginatedContent>> paginatedContent = new HashMap<>();
private final Predicate<ServerPlayerEntity> playerCondition = new NullPlayerCondition().negate();
private final Predicate<String> headerCondition = new HeaderCondition().negate();
@ -21,7 +24,6 @@ public class PaginationApiImpl implements PaginationApi {
if(playerCondition.test(playerEntity) || headerCondition.test(header) || contentCondition.test(content)) {
throw new IllegalArgumentException("Preconditions aren't satisfied");
}
// TODO: 01/03/2023
paginatedContent.put(playerEntity, new Pair<>(900, new PaginatedContent(header, content)));
}
}

View File

@ -3,12 +3,11 @@ package fr.altarik.toolbox.pagination.precondition;
import java.util.function.Predicate;
/**
* This predicate returns true if header is not null, not blank (not empty excluding whitespaces)
* and if its length doesn't exceed 50 characters.
* This predicate returns true if its length doesn't exceed 50 characters.
*/
public class HeaderCondition implements Predicate<String> {
@Override
public boolean test(String header) {
return header != null && !header.isBlank() && header.length() <= 50;
return header.length() <= 50;
}
}