001package org.unix4j.unix.ls;
002
003import java.io.File;
004import java.util.List;
005
006import org.unix4j.processor.LineProcessor;
007
008/**
009 * Interface used by the different output formats of the ls command.
010 */
011interface LsFormatter {
012        /**
013         * Writes information of the given file to the {@code output}.
014         * 
015         * @param relativeTo
016         *            the starting directory to use as starting point to get to
017         *            {@code file}; all path elements from this directory to
018         *            {@code file} should be printed
019         * @param file
020         *            the file whose name or other information is written to
021         *            {@code output}
022         * @param args
023         *            arguments possibly used to lookup some formatting options
024         * @param output
025         *            the output object to write to
026         * @return true if the {@code output} object is ready to take more output
027         *         lines, and false if not
028         */
029        boolean writeFormatted(File relativeTo, File file, LsArguments args, LineProcessor output);
030
031        interface Factory {
032                /**
033                 * Creates and returns a new formatter for the files in the specified
034                 * {@code directory}.
035                 * 
036                 * @param relativeTo
037                 *            the starting directory to use as starting point to get to
038                 *            {@code directory}; all path elements from the relative
039                 *            directory to the files in {@code directory} should be
040                 *            printed
041                 * @param directory
042                 *            the directory whose files should be formatted
043                 * @param directoryFiles
044                 *            the directory files to be formatted by the returned
045                 *            formatter
046                 * @param args
047                 *            arguments possibly used to lookup some formatting options
048                 */
049                LsFormatter create(File relativeTo, File directory, List<File> directoryFiles, LsArguments args);
050        }
051
052}