From 04ae927f38049d0a9f5f200443c9d5a1447755e9 Mon Sep 17 00:00:00 2001 From: Mark Harwood Date: Sat, 17 Nov 2007 20:08:06 +0000 Subject: [PATCH] Added toString implementation on BooleanFilter.java, provided by Jason Calabrese git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@595996 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/lucene/search/BooleanFilter.java | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/contrib/queries/src/java/org/apache/lucene/search/BooleanFilter.java b/contrib/queries/src/java/org/apache/lucene/search/BooleanFilter.java index 5450d2de130..107aa33a606 100644 --- a/contrib/queries/src/java/org/apache/lucene/search/BooleanFilter.java +++ b/contrib/queries/src/java/org/apache/lucene/search/BooleanFilter.java @@ -178,4 +178,43 @@ public class BooleanFilter extends Filter return hash; } + + /** Prints a user-readable version of this query. */ + public String toString() + { + StringBuffer buffer = new StringBuffer(); + + buffer.append("BooleanFilter("); + + appendFilters(shouldFilters, null, buffer); + appendFilters(mustFilters, "+", buffer); + appendFilters(notFilters, "-", buffer); + + buffer.append(")"); + + return buffer.toString(); + } + + private void appendFilters(ArrayList filters, String occurString, + StringBuffer buffer) + { + if (filters == null) + return; + + for (int i = 0; i < filters.size(); i++) + { + Filter filter = (Filter) filters.get(i); + if (occurString != null) + { + buffer.append(occurString); + } + + buffer.append(filter); + + if (i < filters.size() - 1) + { + buffer.append(' '); + } + } + } }