@Test public void resolvesOneArgumentFunctions() { LiveHttpRequest request = get("/foo") .header("Host", "www.hotels.com") .cookies(requestCookie("lang", "en_US|en-us_hotels_com")) .build(); assertThat(functionResolver.resolveFunction("header", singletonList("Host")).call(request, context), is("www.hotels.com")); assertThat(functionResolver.resolveFunction("cookie", singletonList("lang")).call(request, context), is("en_US|en-us_hotels_com")); }
PartialFunction resolveFunction(String name, List<String> arguments) { int argumentSize = arguments.size(); String argumentsRepresentation = join(", ", arguments); switch (argumentSize) { case 0: Function0 function0 = ensureNotNull( zeroArgumentFunctions.get(name), "No such function=[%s], with n=[%d] arguments=[%s]", name, argumentSize, argumentsRepresentation); return function0::call; case 1: Function1 function1 = ensureNotNull( oneArgumentFunctions.get(name), "No such function=[%s], with n=[%d] arguments=[%s]", name, argumentSize, argumentsRepresentation); return (request, context) -> function1.call(request, context, arguments.get(0)); default: throw new IllegalArgumentException(format("No such function=[%s], with n=[%d] arguments=[%s]", name, argumentSize, argumentsRepresentation)); } }
FunctionResolver { PartialFunction resolveFunction(String name, List<String> arguments) { int argumentSize = arguments.size(); String argumentsRepresentation = join(", ", arguments); switch (argumentSize) { case 0: Function0 function0 = ensureNotNull( zeroArgumentFunctions.get(name), "No such function=[%s], with n=[%d] arguments=[%s]", name, argumentSize, argumentsRepresentation); return function0::call; case 1: Function1 function1 = ensureNotNull( oneArgumentFunctions.get(name), "No such function=[%s], with n=[%d] arguments=[%s]", name, argumentSize, argumentsRepresentation); return (request, context) -> function1.call(request, context, arguments.get(0)); default: throw new IllegalArgumentException(format("No such function=[%s], with n=[%d] arguments=[%s]", name, argumentSize, argumentsRepresentation)); } } }
FunctionResolver { PartialFunction resolveFunction(String name, List<String> arguments) { int argumentSize = arguments.size(); String argumentsRepresentation = join(", ", arguments); switch (argumentSize) { case 0: Function0 function0 = ensureNotNull( zeroArgumentFunctions.get(name), "No such function=[%s], with n=[%d] arguments=[%s]", name, argumentSize, argumentsRepresentation); return function0::call; case 1: Function1 function1 = ensureNotNull( oneArgumentFunctions.get(name), "No such function=[%s], with n=[%d] arguments=[%s]", name, argumentSize, argumentsRepresentation); return (request, context) -> function1.call(request, context, arguments.get(0)); default: throw new IllegalArgumentException(format("No such function=[%s], with n=[%d] arguments=[%s]", name, argumentSize, argumentsRepresentation)); } } FunctionResolver(Map<String, Function0> zeroArgumentFunctions, Map<String, Function1> oneArgumentFunctions); }
FunctionResolver { PartialFunction resolveFunction(String name, List<String> arguments) { int argumentSize = arguments.size(); String argumentsRepresentation = join(", ", arguments); switch (argumentSize) { case 0: Function0 function0 = ensureNotNull( zeroArgumentFunctions.get(name), "No such function=[%s], with n=[%d] arguments=[%s]", name, argumentSize, argumentsRepresentation); return function0::call; case 1: Function1 function1 = ensureNotNull( oneArgumentFunctions.get(name), "No such function=[%s], with n=[%d] arguments=[%s]", name, argumentSize, argumentsRepresentation); return (request, context) -> function1.call(request, context, arguments.get(0)); default: throw new IllegalArgumentException(format("No such function=[%s], with n=[%d] arguments=[%s]", name, argumentSize, argumentsRepresentation)); } } FunctionResolver(Map<String, Function0> zeroArgumentFunctions, Map<String, Function1> oneArgumentFunctions);  }
FunctionResolver { PartialFunction resolveFunction(String name, List<String> arguments) { int argumentSize = arguments.size(); String argumentsRepresentation = join(", ", arguments); switch (argumentSize) { case 0: Function0 function0 = ensureNotNull( zeroArgumentFunctions.get(name), "No such function=[%s], with n=[%d] arguments=[%s]", name, argumentSize, argumentsRepresentation); return function0::call; case 1: Function1 function1 = ensureNotNull( oneArgumentFunctions.get(name), "No such function=[%s], with n=[%d] arguments=[%s]", name, argumentSize, argumentsRepresentation); return (request, context) -> function1.call(request, context, arguments.get(0)); default: throw new IllegalArgumentException(format("No such function=[%s], with n=[%d] arguments=[%s]", name, argumentSize, argumentsRepresentation)); } } FunctionResolver(Map<String, Function0> zeroArgumentFunctions, Map<String, Function1> oneArgumentFunctions);   }