Skip to content
This repository was archived by the owner on Jul 31, 2022. It is now read-only.

Changed PredicateHandler parameter order #127

Merged
merged 1 commit into from
Dec 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

<groupId>com.kttdevelopment</groupId>
<artifactId>simplehttpserver</artifactId>
<version>4.3.1</version>
<version>4.4.0</version>

<name>simplehttpserver</name>
<description>📕 SimpleHttpServer :: Simplified implementation of the sun http server :: Simplified handlers to execute complex operations</description>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* A utility class used to generate uniform contexts. Applications do not use this class.
*
* @since 03.05.03
* @version 4.3.1
* @version 4.4.0
* @author Ktt Development
*/
public abstract class ContextUtil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* @see SimpleHttpExchange
* @see Predicate
* @since 01.00.00
* @version 03.05.00
* @version 4.4.0
* @author Ktt Development
*/
public class PredicateHandler implements HttpHandler {
Expand All @@ -27,6 +27,7 @@ public class PredicateHandler implements HttpHandler {
/**
* Creates a predicate handler.
*
* @deprecated use {@link PredicateHandler#PredicateHandler(Predicate, HttpHandler, HttpHandler)}
* @param trueHandler handler to use if true
* @param falseHandler handler to use if false
* @param predicate predicate to test
Expand All @@ -38,12 +39,33 @@ public class PredicateHandler implements HttpHandler {
* @since 01.00.00
* @author Ktt Development
*/
@Deprecated
public PredicateHandler(final HttpHandler trueHandler, final HttpHandler falseHandler, final Predicate<HttpExchange> predicate){
T = trueHandler;
F = falseHandler;
this.predicate = predicate;
}

/**
* Creates a predicate handler.
*
* @param predicate predicate to test
* @param trueHandler handler to use if true
* @param falseHandler handler to use if false
*
* @see SimpleHttpHandler
* @see HttpHandler
* @see SimpleHttpExchange
* @see Predicate
* @since 4.4.0
* @author Ktt Development
*/
public PredicateHandler(final Predicate<HttpExchange> predicate, final HttpHandler trueHandler, final HttpHandler falseHandler){
this.predicate = predicate;
T = trueHandler;
F = falseHandler;
}

@Override
public final void handle(final HttpExchange exchange) throws IOException{
(predicate.test(exchange) ? T : F).handle(exchange);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* @see SimpleHttpHandler
* @see HttpHandler
* @since 01.00.00
* @version 02.00.00
* @version 4.4.0
* @author Ktt Development
*/
public class RootHandler extends PredicateHandler {
Expand All @@ -27,9 +27,9 @@ public class RootHandler extends PredicateHandler {
*/
public RootHandler(final HttpHandler rootHandler, final HttpHandler elseHandler){
super(
httpExchange -> httpExchange.getRequestURI().getPath().equals("/"),
rootHandler,
elseHandler,
httpExchange -> httpExchange.getRequestURI().getPath().equals("/")
elseHandler
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public void predicate() throws IOException, ExecutionException, InterruptedExcep
final boolean condition = System.currentTimeMillis() % 2 == 1;

final String context = "";
server.createContext(context, new PredicateHandler((SimpleHttpHandler) exchange -> exchange.send("A"), (SimpleHttpHandler) exchange -> exchange.send("B"), exchange -> condition));
server.createContext(context, new PredicateHandler(exchange -> condition, (SimpleHttpHandler) exchange -> exchange.send("A"), (SimpleHttpHandler) exchange -> exchange.send("B")));
server.start();

Assertions.assertFalse(server.getContexts().isEmpty(), "Server did not contain a temporary context");
Expand Down