From 9d15809c91e3a318ed798a929438ec1d8148b29c Mon Sep 17 00:00:00 2001 From: Stefan Bodewig Date: Thu, 27 Aug 2009 07:22:29 +0000 Subject: [PATCH] Hey, TokenFilters can be used in filterchains with no effort, didn't know that git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@808306 13f79535-47bb-0310-9956-ffa450edef68 --- docs/manual/CoreTypes/filterchain.html | 2 ++ .../org/apache/tools/ant/filters/UniqFilter.java | 4 +--- src/tests/antunit/filters/uniq-test.xml | 12 ++++++++++++ 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/docs/manual/CoreTypes/filterchain.html b/docs/manual/CoreTypes/filterchain.html index df9cf27d8..54d9df4a3 100644 --- a/docs/manual/CoreTypes/filterchain.html +++ b/docs/manual/CoreTypes/filterchain.html @@ -1365,6 +1365,8 @@ Delete tabs from lines, trim the lines and removes empty lines.

Suppresses all tokens that match their ancestor token. It is most useful if combined with a sort filter.

+

This filter may be used directly within a filterchain.

+

Example:

This suppresses duplicate lines. diff --git a/src/main/org/apache/tools/ant/filters/UniqFilter.java b/src/main/org/apache/tools/ant/filters/UniqFilter.java index a7d2334e4..e72d5f581 100644 --- a/src/main/org/apache/tools/ant/filters/UniqFilter.java +++ b/src/main/org/apache/tools/ant/filters/UniqFilter.java @@ -26,12 +26,10 @@ package org.apache.tools.ant.filters; * * @since Ant 1.8.0 */ -public class UniqFilter implements TokenFilter.Filter { +public class UniqFilter extends TokenFilter.ChainableReaderFilter { private String lastLine = null; - public UniqFilter() { } - public String filter(String string) { return lastLine == null || !lastLine.equals(string) ? (lastLine = string) : null; diff --git a/src/tests/antunit/filters/uniq-test.xml b/src/tests/antunit/filters/uniq-test.xml index 0957b9ebe..832ec944d 100644 --- a/src/tests/antunit/filters/uniq-test.xml +++ b/src/tests/antunit/filters/uniq-test.xml @@ -23,6 +23,18 @@ + + + + + + + + +