Renamed 'and' to 'andSame' and 'andOther' to 'and'

In RoutingFunction, renamed 'and' to 'andSame', and 'andOther' to
'and' to make the commonly used method name shorter.
This commit is contained in:
Arjen Poutsma
2016-09-12 15:02:12 +02:00
parent 96ec18a9aa
commit 61bf6a25b7
3 changed files with 11 additions and 11 deletions

View File

@@ -38,14 +38,14 @@ public interface RoutingFunction<T> {
/**
* Return a composed routing function that first invokes this function,
* and then invokes the {@code other} function if this route had
* and then invokes the {@code other} function (of the same type {@code T}) if this route had
* {@linkplain Optional#empty() no result}.
*
* @param other the function to apply when this function has no result
* @param other the function of type {@code T} to apply when this function has no result
* @return a composed function that first routes with this function and then the {@code other} function if this
* function has no result
*/
default RoutingFunction<T> and(RoutingFunction<T> other) {
default RoutingFunction<T> andSame(RoutingFunction<T> other) {
return request -> {
Optional<HandlerFunction<T>> result = this.route(request);
return result.isPresent() ? result : other.route(request);
@@ -54,14 +54,14 @@ public interface RoutingFunction<T> {
/**
* Return a composed routing function that first invokes this function,
* and then invokes the {@code other} function if this route had
* and then invokes the {@code other} function (of a different type) if this route had
* {@linkplain Optional#empty() no result}.
*
* @param other the function to apply when this function has no result
* @return a composed function that first routes with this function and then the {@code other} function if this
* function has no result
*/
default <S> RoutingFunction<?> andOther(RoutingFunction<S> other) {
default RoutingFunction<?> and(RoutingFunction<?> other) {
return request -> {
Optional<HandlerFunction<Object>> result = this.route(request).
map(CastingUtils::cast);

View File

@@ -29,12 +29,12 @@ import static org.junit.Assert.*;
public class RoutingFunctionTests {
@Test
public void and() throws Exception {
public void andSame() throws Exception {
HandlerFunction<Void> handlerFunction = request -> Response.ok().build();
RoutingFunction<Void> routingFunction1 = request -> Optional.empty();
RoutingFunction<Void> routingFunction2 = request -> Optional.of(handlerFunction);
RoutingFunction<Void> result = routingFunction1.and(routingFunction2);
RoutingFunction<Void> result = routingFunction1.andSame(routingFunction2);
assertNotNull(result);
MockRequest request = MockRequest.builder().build();
@@ -44,12 +44,12 @@ public class RoutingFunctionTests {
}
@Test
public void andOther() throws Exception {
public void and() throws Exception {
HandlerFunction<String> handlerFunction = request -> Response.ok().body("42");
RoutingFunction<Void> routingFunction1 = request -> Optional.empty();
RoutingFunction<String> routingFunction2 = request -> Optional.of(handlerFunction);
RoutingFunction<?> result = routingFunction1.andOther(routingFunction2);
RoutingFunction<?> result = routingFunction1.and(routingFunction2);
assertNotNull(result);
MockRequest request = MockRequest.builder().build();

View File

@@ -51,8 +51,8 @@ public class SseHandlerFunctionIntegrationTests
protected RoutingFunction<?> routingFunction() {
SseHandler sseHandler = new SseHandler();
return route(RequestPredicates.GET("/string"), sseHandler::string)
.andOther(route(RequestPredicates.GET("/person"), sseHandler::person))
.andOther(route(RequestPredicates.GET("/event"), sseHandler::sse));
.and(route(RequestPredicates.GET("/person"), sseHandler::person))
.and(route(RequestPredicates.GET("/event"), sseHandler::sse));
}