Class SortFilter
- java.lang.Object
- 
- java.io.Reader
- 
- java.io.FilterReader
- 
- org.apache.tools.ant.filters.BaseFilterReader
- 
- org.apache.tools.ant.filters.BaseParamFilterReader
- 
- org.apache.tools.ant.filters.SortFilter
 
 
 
 
 
- 
- All Implemented Interfaces:
- java.io.Closeable,- java.lang.AutoCloseable,- java.lang.Readable,- ChainableReader,- Parameterizable
 
 public final class SortFilter extends BaseParamFilterReader implements ChainableReader Sort a file before and/or after the file. Examples: <copy todir="build"> <fileset dir="input" includes="*.txt"/> <filterchain> <sortfilter/> </filterchain> </copy>Sort all files *.txtfrom src location and copy them into build location. The lines of each file are sorted in ascendant order comparing the lines via theString.compareTo(Object o)method.<copy todir="build"> <fileset dir="input" includes="*.txt"/> <filterchain> <sortfilter reverse="true"/> </filterchain> </copy>Sort all files *.txtfrom src location into reverse order and copy them into build location. If reverse parameter has valuetrue(default value), then the output line of the files will be in ascendant order.<copy todir="build"> <fileset dir="input" includes="*.txt"/> <filterchain> <filterreader classname="org.apache.tools.ant.filters.SortFilter"> <param name="comparator" value="org.apache.tools.ant.filters.EvenFirstCmp"/> </filterreader> </filterchain> </copy>Sort all files *.txtfrom src location using as sorting criterionEvenFirstCmpclass, that sorts the file lines putting even lines first then odd lines for example. The modified files are copied into build location. TheEvenFirstCmp, has to an instantiable class viaClass.newInstance(), therefore in case of inner class has to be static. It also has to implementjava.util.Comparatorinterface, for example:package org.apache.tools.ant.filters; ...(omitted) public final class EvenFirstCmp implements <b>Comparator</b> { public int compare(Object o1, Object o2) { ...(omitted) } }The example above is equivalent to: <componentdef name="evenfirst" classname="org.apache.tools.ant.filters.EvenFirstCmp"/> <copy todir="build"> <fileset dir="input" includes="*.txt"/> <filterchain> <sortfilter> <evenfirst/> </sortfilter> </filterchain> </copy>If parameter comparatoris present, thenreverseparameter will not be taken into account.- Since:
- Ant 1.8.0
 
- 
- 
Constructor SummaryConstructors Constructor Description SortFilter()Constructor for "dummy" instances.SortFilter(java.io.Reader in)Creates a new filtered reader.
 - 
Method SummaryModifier and Type Method Description voidadd(java.util.Comparator<? super java.lang.String> comparator)Set the comparator to be used as sorting criterion as nested element.java.io.Readerchain(java.io.Reader rdr)Creates a new SortReader using the passed in Reader for instantiation.java.util.Comparator<? super java.lang.String>getComparator()Returns the comparator to be used for sorting.booleanisReverse()Returnstrueif the sorting process will be in reverse order, otherwise the sorting process will be in ascendant order.intread()Returns the next character in the filtered stream.voidsetComparator(java.util.Comparator<? super java.lang.String> comparator)Set the comparator to be used as sorting criterion.voidsetReverse(boolean reverse)Sets the sorting process will be in ascendant (reverse=false) or to descendant (reverse=true).- 
Methods inherited from class org.apache.tools.ant.filters.BaseParamFilterReadergetParameters, setParameters
 - 
Methods inherited from class org.apache.tools.ant.filters.BaseFilterReadergetInitialized, getProject, read, readFully, readLine, setInitialized, setProject, skip
 
- 
 
- 
- 
- 
Constructor Detail- 
SortFilterpublic SortFilter() Constructor for "dummy" instances.- See Also:
- BaseFilterReader()
 
 - 
SortFilterpublic SortFilter(java.io.Reader in) Creates a new filtered reader.- Parameters:
- in- A Reader object providing the underlying stream. Must not be- null.
 
 
- 
 - 
Method Detail- 
readpublic int read() throws java.io.IOExceptionReturns the next character in the filtered stream. If the desired number of lines have already been read, the resulting stream is effectively at an end. Otherwise, the next character from the underlying stream is read and returned.- Overrides:
- readin class- java.io.FilterReader
- Returns:
- the next character in the resulting stream, or -1 if the end of the resulting stream has been reached
- Throws:
- java.io.IOException- if the underlying stream throws an IOException during reading
 
 - 
chainpublic java.io.Reader chain(java.io.Reader rdr) Creates a new SortReader using the passed in Reader for instantiation.- Specified by:
- chainin interface- ChainableReader
- Parameters:
- rdr- A Reader object providing the underlying stream. Must not be- null.
- Returns:
- a new filter based on this configuration, but filtering the specified reader
 
 - 
isReversepublic boolean isReverse() Returnstrueif the sorting process will be in reverse order, otherwise the sorting process will be in ascendant order.- Returns:
- trueif the sorting process will be in reverse order, otherwise the sorting process will be in ascendant order.
 
 - 
setReversepublic void setReverse(boolean reverse) Sets the sorting process will be in ascendant (reverse=false) or to descendant (reverse=true).- Parameters:
- reverse- Boolean representing reverse ordering process.
 
 - 
getComparatorpublic java.util.Comparator<? super java.lang.String> getComparator() Returns the comparator to be used for sorting.- Returns:
- the comparator
 
 - 
setComparatorpublic void setComparator(java.util.Comparator<? super java.lang.String> comparator) Set the comparator to be used as sorting criterion.- Parameters:
- comparator- the comparator to set
 
 - 
addpublic void add(java.util.Comparator<? super java.lang.String> comparator) Set the comparator to be used as sorting criterion as nested element.- Parameters:
- comparator- the comparator to set
 
 
- 
 
-