From db4c6c96a3aa904005fc1985548cb0f8061e9201 Mon Sep 17 00:00:00 2001 From: Konrad Beiske Date: Wed, 3 Feb 2016 11:13:12 +0100 Subject: [PATCH] Minor refactoring and indentation fixes --- .../common/xcontent/XContentBuilder.java | 2 +- .../common/xcontent/smile/SmileXContent.java | 4 +- .../filtering/FilterPathBasedFilter.java | 17 +-- ...bstractFilteringJsonGeneratorTestCase.java | 135 +++++++++--------- 4 files changed, 75 insertions(+), 83 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/common/xcontent/XContentBuilder.java b/core/src/main/java/org/elasticsearch/common/xcontent/XContentBuilder.java index 13e45af1d37..95cafaae0d0 100644 --- a/core/src/main/java/org/elasticsearch/common/xcontent/XContentBuilder.java +++ b/core/src/main/java/org/elasticsearch/common/xcontent/XContentBuilder.java @@ -83,7 +83,7 @@ public final class XContentBuilder implements BytesStream, Releasable { return new XContentBuilder(xContent, new BytesStreamOutput(), filters); } - public static XContentBuilder builder(XContent xContent, boolean inclusive, String[] filters) throws IOException { + public static XContentBuilder builder(XContent xContent, String[] filters, boolean inclusive) throws IOException { return new XContentBuilder(xContent, new BytesStreamOutput(), inclusive, filters); } diff --git a/core/src/main/java/org/elasticsearch/common/xcontent/smile/SmileXContent.java b/core/src/main/java/org/elasticsearch/common/xcontent/smile/SmileXContent.java index 285314e9b89..5340d34392d 100644 --- a/core/src/main/java/org/elasticsearch/common/xcontent/smile/SmileXContent.java +++ b/core/src/main/java/org/elasticsearch/common/xcontent/smile/SmileXContent.java @@ -68,8 +68,8 @@ public class SmileXContent implements XContent { } @Override - public XContentGenerator createGenerator(OutputStream os, String[] filters, boolean inclusiveFilters) throws IOException { - return new SmileXContentGenerator(smileFactory.createGenerator(os, JsonEncoding.UTF8), os, inclusiveFilters, filters); + public XContentGenerator createGenerator(OutputStream os, String[] filters, boolean inclusive) throws IOException { + return new SmileXContentGenerator(smileFactory.createGenerator(os, JsonEncoding.UTF8), os, inclusive, filters); } @Override diff --git a/core/src/main/java/org/elasticsearch/common/xcontent/support/filtering/FilterPathBasedFilter.java b/core/src/main/java/org/elasticsearch/common/xcontent/support/filtering/FilterPathBasedFilter.java index 03e0122e9d2..b55d426d822 100644 --- a/core/src/main/java/org/elasticsearch/common/xcontent/support/filtering/FilterPathBasedFilter.java +++ b/core/src/main/java/org/elasticsearch/common/xcontent/support/filtering/FilterPathBasedFilter.java @@ -92,18 +92,11 @@ public class FilterPathBasedFilter extends TokenFilter { @Override public TokenFilter includeProperty(String name) { TokenFilter filter = evaluate(name, filters); - if (inclusive) { - if (filter == MATCHING) { - return TokenFilter.INCLUDE_ALL; - } else if (filter == NO_MATCHING) { - return null; - } - } else { - if (filter == MATCHING) { - return null; - } else if (filter == NO_MATCHING) { - return TokenFilter.INCLUDE_ALL; - } + if (filter == MATCHING) { + return inclusive ? TokenFilter.INCLUDE_ALL : null; + } + if (filter == NO_MATCHING) { + return inclusive ? null : TokenFilter.INCLUDE_ALL; } return filter; } diff --git a/core/src/test/java/org/elasticsearch/common/xcontent/support/filtering/AbstractFilteringJsonGeneratorTestCase.java b/core/src/test/java/org/elasticsearch/common/xcontent/support/filtering/AbstractFilteringJsonGeneratorTestCase.java index 13739473b16..d237c3bca4c 100644 --- a/core/src/test/java/org/elasticsearch/common/xcontent/support/filtering/AbstractFilteringJsonGeneratorTestCase.java +++ b/core/src/test/java/org/elasticsearch/common/xcontent/support/filtering/AbstractFilteringJsonGeneratorTestCase.java @@ -84,7 +84,7 @@ public abstract class AbstractFilteringJsonGeneratorTestCase extends ESTestCase } private XContentBuilder newXContentBuilder(boolean inclusive, String... filters) throws IOException { - return XContentBuilder.builder(getXContentType().xContent(), inclusive, filters); + return XContentBuilder.builder(getXContentType().xContent(), filters, inclusive); } /** @@ -456,73 +456,72 @@ public abstract class AbstractFilteringJsonGeneratorTestCase extends ESTestCase public void testSimpleArrayExclusive() throws Exception { XContentBuilder expected = newXContentBuilder(true).startObject() - .field("title", "My awesome book") - .field("pages", 456) - .field("price", 27.99) - .field("timestamp", 1428582942867L) - .nullField("default") - .startArray("authors") - .startObject() - .field("name", "John Doe") - .field("lastname", "John") - .field("firstname", "Doe") - .endObject() - .startObject() - .field("name", "William Smith") - .field("lastname", "William") - .field("firstname", "Smith") - .endObject() - .endArray() - .startObject("properties") - .field("weight", 0.8d) - .startObject("language") - .startObject("en") - .field("lang", "English") - .field("available", true) - .startArray("distributors") - .startObject() - .field("name", "The Book Shop") - .startArray("addresses") - .startObject() - .field("name", "address #1") - .field("street", "Hampton St") - .field("city", "London") - .endObject() - .startObject() - .field("name", "address #2") - .field("street", "Queen St") - .field("city", "Stornoway") - .endObject() - .endArray() - .endObject() - .startObject() - .field("name", "Sussex Books House") - .endObject() - .endArray() - .endObject() - .startObject("fr") - .field("lang", "French") - .field("available", false) - .startArray("distributors") - .startObject() - .field("name", "La Maison du Livre") - .startArray("addresses") - .startObject() - .field("name", "address #1") - .field("street", "Rue Mouffetard") - .field("city", "Paris") - .endObject() - .endArray() - .endObject() - .startObject() - .field("name", "Thetra") - .endObject() - .endArray() - .endObject() - .endObject() - .endObject() - .endObject(); - + .field("title", "My awesome book") + .field("pages", 456) + .field("price", 27.99) + .field("timestamp", 1428582942867L) + .nullField("default") + .startArray("authors") + .startObject() + .field("name", "John Doe") + .field("lastname", "John") + .field("firstname", "Doe") + .endObject() + .startObject() + .field("name", "William Smith") + .field("lastname", "William") + .field("firstname", "Smith") + .endObject() + .endArray() + .startObject("properties") + .field("weight", 0.8d) + .startObject("language") + .startObject("en") + .field("lang", "English") + .field("available", true) + .startArray("distributors") + .startObject() + .field("name", "The Book Shop") + .startArray("addresses") + .startObject() + .field("name", "address #1") + .field("street", "Hampton St") + .field("city", "London") + .endObject() + .startObject() + .field("name", "address #2") + .field("street", "Queen St") + .field("city", "Stornoway") + .endObject() + .endArray() + .endObject() + .startObject() + .field("name", "Sussex Books House") + .endObject() + .endArray() + .endObject() + .startObject("fr") + .field("lang", "French") + .field("available", false) + .startArray("distributors") + .startObject() + .field("name", "La Maison du Livre") + .startArray("addresses") + .startObject() + .field("name", "address #1") + .field("street", "Rue Mouffetard") + .field("city", "Paris") + .endObject() + .endArray() + .endObject() + .startObject() + .field("name", "Thetra") + .endObject() + .endArray() + .endObject() + .endObject() + .endObject() + .endObject(); assertXContentBuilder(expected, sample(false, "tags")); }