From 85e4edccf578142bef7a08e954fb8ddc1b4f111a Mon Sep 17 00:00:00 2001 From: Fevzi Anifieiev Date: Wed, 25 Mar 2020 00:58:27 -0400 Subject: [PATCH] (#1019) Simplified conditional statement with EO way --- .../java/org/takes/facets/fork/FkHost.java | 38 +++++++------------ 1 file changed, 13 insertions(+), 25 deletions(-) diff --git a/src/main/java/org/takes/facets/fork/FkHost.java b/src/main/java/org/takes/facets/fork/FkHost.java index 0d2a17ef8..2b25d5b8d 100644 --- a/src/main/java/org/takes/facets/fork/FkHost.java +++ b/src/main/java/org/takes/facets/fork/FkHost.java @@ -24,10 +24,9 @@ package org.takes.facets.fork; import lombok.EqualsAndHashCode; -import org.cactoos.Text; +import org.cactoos.scalar.EqualsNullable; +import org.cactoos.scalar.Ternary; import org.cactoos.text.Lowered; -import org.cactoos.text.UncheckedText; -import org.takes.Request; import org.takes.Response; import org.takes.Take; import org.takes.misc.Opt; @@ -48,11 +47,6 @@ * * @see TkFork * @since 0.32 - * @todo #998:30min Use {@link org.cactoos.scalar.Ternary} scalar here for - * conditionally evaluated result. Please refere to - * https://github.com/yegor256/cactoos/blob/master/src/main/java/org/cactoos/ - * scalar/Ternary.java class for javadoc on how to use this scalar in an - * elegant way. */ @EqualsAndHashCode(callSuper = true) public final class FkHost extends FkWrap { @@ -73,23 +67,17 @@ public FkHost(final String host, final Take take) { * @return Fork */ private static Fork fork(final String host, final Take take) { - // @checkstyle AnonInnerLengthCheck (50 lines) - return new Fork() { - @Override - public Opt route(final Request req) throws Exception { - final String hst = new RqHeaders.Smart( - new RqHeaders.Base(req) - ).single("host"); - final Opt rsp; - final Text lowhost = new UncheckedText(new Lowered(host)); - final Text lowhst = new UncheckedText(new Lowered(hst)); - if (lowhost.asString().equals(lowhst.asString())) { - rsp = new Opt.Single<>(take.act(req)); - } else { - rsp = new Opt.Empty<>(); - } - return rsp; - } + return req -> { + final String hst = new RqHeaders.Smart( + new RqHeaders.Base(req) + ).single("host"); + return new Ternary>( + new EqualsNullable( + new Lowered(host), new Lowered(hst) + ), + new Opt.Single<>(take.act(req)), + new Opt.Empty<>() + ).value(); }; }