Minor refactoring and indentation fixes
This commit is contained in:
parent
a0d8d656fc
commit
db4c6c96a3
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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"));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue