From fa2d5c054b4bb619cfabe5f5a1b890c6e0d41af0 Mon Sep 17 00:00:00 2001 From: Matthew Davis Date: Tue, 3 Jan 2023 11:00:28 -0500 Subject: [PATCH] add example of using the values handler and change method signature --- .../java/io/zulia/client/command/factory/Values.java | 3 ++- .../src/test/java/io/zulia/client/HelperTest.java | 9 +++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/zulia-client/src/main/java/io/zulia/client/command/factory/Values.java b/zulia-client/src/main/java/io/zulia/client/command/factory/Values.java index 9b402a18..0fb11ca0 100644 --- a/zulia-client/src/main/java/io/zulia/client/command/factory/Values.java +++ b/zulia-client/src/main/java/io/zulia/client/command/factory/Values.java @@ -96,8 +96,9 @@ public Values withFields(Collection fields) { } - public void setValueHandler(Function valueHandler) { + public Values valueHandler(Function valueHandler) { this.valueHandler = valueHandler; + return this; } public String asString() { diff --git a/zulia-client/src/test/java/io/zulia/client/HelperTest.java b/zulia-client/src/test/java/io/zulia/client/HelperTest.java index 13431698..dc452d1a 100644 --- a/zulia-client/src/test/java/io/zulia/client/HelperTest.java +++ b/zulia-client/src/test/java/io/zulia/client/HelperTest.java @@ -7,6 +7,8 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; +import java.util.function.Function; + public class HelperTest { @Test @@ -29,6 +31,13 @@ public void valuesTest() { } + { + Function quoteAndTrim = s -> Values.VALUE_QUOTER.apply(s).trim(); + String query = Values.all().valueHandler(quoteAndTrim).of(" slow cat ", " Pink Shirt ").asString(); + Assertions.assertEquals("(\"slow cat\" AND \"Pink Shirt\")", query); + } + + { String query = Values.any().of("a", "b").withFields("title", "abstract").asString(); Assertions.assertEquals("title,abstract:(a OR b)", query);