001package org.unix4j.unix.tail;
002
003import java.util.Arrays;
004import java.util.Collections;
005import java.util.EnumSet;
006import java.util.Iterator;
007import org.unix4j.option.Option;
008
009import org.unix4j.unix.Tail;
010
011/**
012 * Option sets for the {@link Tail tail} command with 
013 * the following options: {@link #c c}, {@link #s s}, {@link #q q}.
014 * <p>
015 * Application code does normally not directly refer to this class;
016 * {@link Tail#Options} should be used instead to specify command 
017 * options. See also {@link org.unix4j.unix.tail.TailOptions} for more information.
018 */
019public enum TailOptionSet_cqs implements TailOptions {
020        /** Option set with the following active options: {@link #chars c}, {@link #countFromStart s}, {@link #suppressHeaders q}.*/
021        Active_cqs(
022                /*c:*/null /*already set*/, /*chars:*/null /*already set*/, /*s:*/null /*already set*/, /*countFromStart:*/null /*already set*/, /*q:*/null /*already set*/, /*suppressHeaders:*/null /*already set*/, 
023                true, 
024                /*active:*/TailOption.chars, TailOption.countFromStart, TailOption.suppressHeaders
025        ),
026        /** Option set with the following active options: {@link #chars c}, {@link #countFromStart s}, {@link #suppressHeaders q}.*/
027        Active_cqs_long(
028                /*c:*/null /*already set*/, /*chars:*/null /*already set*/, /*s:*/null /*already set*/, /*countFromStart:*/null /*already set*/, /*q:*/null /*already set*/, /*suppressHeaders:*/null /*already set*/, 
029                false, 
030                /*active:*/TailOption.chars, TailOption.countFromStart, TailOption.suppressHeaders
031        ),
032        /** Option set with the following active options: {@link #chars c}, {@link #suppressHeaders q}.*/
033        Active_cq(
034                /*c:*/null /*already set*/, /*chars:*/null /*already set*/, /*s:*/Active_cqs, /*countFromStart:*/Active_cqs_long, /*q:*/null /*already set*/, /*suppressHeaders:*/null /*already set*/, 
035                true, 
036                /*active:*/TailOption.chars, TailOption.suppressHeaders
037        ),
038        /** Option set with the following active options: {@link #chars c}, {@link #suppressHeaders q}.*/
039        Active_cq_long(
040                /*c:*/null /*already set*/, /*chars:*/null /*already set*/, /*s:*/Active_cqs, /*countFromStart:*/Active_cqs_long, /*q:*/null /*already set*/, /*suppressHeaders:*/null /*already set*/, 
041                false, 
042                /*active:*/TailOption.chars, TailOption.suppressHeaders
043        ),
044        /** Option set with the following active options: {@link #chars c}, {@link #countFromStart s}.*/
045        Active_cs(
046                /*c:*/null /*already set*/, /*chars:*/null /*already set*/, /*s:*/null /*already set*/, /*countFromStart:*/null /*already set*/, /*q:*/Active_cqs, /*suppressHeaders:*/Active_cqs_long, 
047                true, 
048                /*active:*/TailOption.chars, TailOption.countFromStart
049        ),
050        /** Option set with the following active options: {@link #chars c}, {@link #countFromStart s}.*/
051        Active_cs_long(
052                /*c:*/null /*already set*/, /*chars:*/null /*already set*/, /*s:*/null /*already set*/, /*countFromStart:*/null /*already set*/, /*q:*/Active_cqs, /*suppressHeaders:*/Active_cqs_long, 
053                false, 
054                /*active:*/TailOption.chars, TailOption.countFromStart
055        ),
056        /** Option set with the following active options: {@link #countFromStart s}, {@link #suppressHeaders q}.*/
057        Active_qs(
058                /*c:*/Active_cqs, /*chars:*/Active_cqs_long, /*s:*/null /*already set*/, /*countFromStart:*/null /*already set*/, /*q:*/null /*already set*/, /*suppressHeaders:*/null /*already set*/, 
059                true, 
060                /*active:*/TailOption.countFromStart, TailOption.suppressHeaders
061        ),
062        /** Option set with the following active options: {@link #countFromStart s}, {@link #suppressHeaders q}.*/
063        Active_qs_long(
064                /*c:*/Active_cqs, /*chars:*/Active_cqs_long, /*s:*/null /*already set*/, /*countFromStart:*/null /*already set*/, /*q:*/null /*already set*/, /*suppressHeaders:*/null /*already set*/, 
065                false, 
066                /*active:*/TailOption.countFromStart, TailOption.suppressHeaders
067        ),
068        /** Option set with the following active options: {@link #chars c}.*/
069        Active_c(
070                /*c:*/null /*already set*/, /*chars:*/null /*already set*/, /*s:*/Active_cs, /*countFromStart:*/Active_cs_long, /*q:*/Active_cq, /*suppressHeaders:*/Active_cq_long, 
071                true, 
072                /*active:*/TailOption.chars
073        ),
074        /** Option set with the following active options: {@link #chars c}.*/
075        Active_c_long(
076                /*c:*/null /*already set*/, /*chars:*/null /*already set*/, /*s:*/Active_cs, /*countFromStart:*/Active_cs_long, /*q:*/Active_cq, /*suppressHeaders:*/Active_cq_long, 
077                false, 
078                /*active:*/TailOption.chars
079        ),
080        /** Option set with the following active options: {@link #suppressHeaders q}.*/
081        Active_q(
082                /*c:*/Active_cq, /*chars:*/Active_cq_long, /*s:*/Active_qs, /*countFromStart:*/Active_qs_long, /*q:*/null /*already set*/, /*suppressHeaders:*/null /*already set*/, 
083                true, 
084                /*active:*/TailOption.suppressHeaders
085        ),
086        /** Option set with the following active options: {@link #suppressHeaders q}.*/
087        Active_q_long(
088                /*c:*/Active_cq, /*chars:*/Active_cq_long, /*s:*/Active_qs, /*countFromStart:*/Active_qs_long, /*q:*/null /*already set*/, /*suppressHeaders:*/null /*already set*/, 
089                false, 
090                /*active:*/TailOption.suppressHeaders
091        ),
092        /** Option set with the following active options: {@link #countFromStart s}.*/
093        Active_s(
094                /*c:*/Active_cs, /*chars:*/Active_cs_long, /*s:*/null /*already set*/, /*countFromStart:*/null /*already set*/, /*q:*/Active_qs, /*suppressHeaders:*/Active_qs_long, 
095                true, 
096                /*active:*/TailOption.countFromStart
097        ),
098        /** Option set with the following active options: {@link #countFromStart s}.*/
099        Active_s_long(
100                /*c:*/Active_cs, /*chars:*/Active_cs_long, /*s:*/null /*already set*/, /*countFromStart:*/null /*already set*/, /*q:*/Active_qs, /*suppressHeaders:*/Active_qs_long, 
101                false, 
102                /*active:*/TailOption.countFromStart
103        );
104        private TailOptionSet_cqs(
105                TailOptionSet_cqs c, TailOptionSet_cqs chars, TailOptionSet_cqs s, TailOptionSet_cqs countFromStart, TailOptionSet_cqs q, TailOptionSet_cqs suppressHeaders, 
106                boolean useAcronym,
107                TailOption... activeOptions
108        ) {
109                this.c = c == null ? this : c;
110                this.chars = chars == null ? this : chars;
111                this.s = s == null ? this : s;
112                this.countFromStart = countFromStart == null ? this : countFromStart;
113                this.q = q == null ? this : q;
114                this.suppressHeaders = suppressHeaders == null ? this : suppressHeaders;
115                this.useAcronym = useAcronym;
116                this.options = activeOptions.length == 0 ? EnumSet.noneOf(TailOption.class) : EnumSet.copyOf(Arrays.asList(activeOptions));
117        }
118        private final boolean useAcronym;
119        /**
120         * Option {@code "-c"}: The {@code count} argument is in units of characters instead of 
121                        lines. Starts from 1 and includes line ending characters.
122         * <p>
123         * The option {@code "-c"} is equivalent to the {@code "--}{@link #chars chars}{@code "} option.
124         * <p>
125         * Technically speaking, this field points to a set with the options of the 
126         * current set plus the option {@code "-c"}. If the option {@code "-c"}
127         * is already set, the field {@code c} points to the enum constant itself
128         * as it already represents the current set of options.
129         */
130        public final TailOptionSet_cqs c;
131        /**
132         * Option {@code "--chars"}: The {@code count} argument is in units of characters instead of 
133                        lines. Starts from 1 and includes line ending characters.
134         * <p>
135         * The option {@code "--chars"} is equivalent to the {@code "-}{@link #c c}{@code "} option.
136         * <p>
137         * Technically speaking, this field points to a set with the options of the 
138         * current set plus the option {@code "--chars"}. If the option {@code "--chars"}
139         * is already set, the field {@code chars} points to the enum constant itself
140         * as it already represents the current set of options.
141         */
142        public final TailOptionSet_cqs chars;
143        /**
144         * Option {@code "-s"}: The {@code count} argument is relative to the beginning of the file
145                        instead of counting from the end of the file. For instance, 
146                        {@code tail -s 10} prints the lines starting from line 10;
147                        {@code tail -s 1} prints the whole file.
148         * <p>
149         * The option {@code "-s"} is equivalent to the {@code "--}{@link #countFromStart countFromStart}{@code "} option.
150         * <p>
151         * Technically speaking, this field points to a set with the options of the 
152         * current set plus the option {@code "-s"}. If the option {@code "-s"}
153         * is already set, the field {@code s} points to the enum constant itself
154         * as it already represents the current set of options.
155         */
156        public final TailOptionSet_cqs s;
157        /**
158         * Option {@code "--countFromStart"}: The {@code count} argument is relative to the beginning of the file
159                        instead of counting from the end of the file. For instance, 
160                        {@code tail -s 10} prints the lines starting from line 10;
161                        {@code tail -s 1} prints the whole file.
162         * <p>
163         * The option {@code "--countFromStart"} is equivalent to the {@code "-}{@link #s s}{@code "} option.
164         * <p>
165         * Technically speaking, this field points to a set with the options of the 
166         * current set plus the option {@code "--countFromStart"}. If the option {@code "--countFromStart"}
167         * is already set, the field {@code countFromStart} points to the enum constant itself
168         * as it already represents the current set of options.
169         */
170        public final TailOptionSet_cqs countFromStart;
171        /**
172         * Option {@code "-q"}: Suppresses printing of headers when multiple files are being
173                        examined.
174         * <p>
175         * The option {@code "-q"} is equivalent to the {@code "--}{@link #suppressHeaders suppressHeaders}{@code "} option.
176         * <p>
177         * Technically speaking, this field points to a set with the options of the 
178         * current set plus the option {@code "-q"}. If the option {@code "-q"}
179         * is already set, the field {@code q} points to the enum constant itself
180         * as it already represents the current set of options.
181         */
182        public final TailOptionSet_cqs q;
183        /**
184         * Option {@code "--suppressHeaders"}: Suppresses printing of headers when multiple files are being
185                        examined.
186         * <p>
187         * The option {@code "--suppressHeaders"} is equivalent to the {@code "-}{@link #q q}{@code "} option.
188         * <p>
189         * Technically speaking, this field points to a set with the options of the 
190         * current set plus the option {@code "--suppressHeaders"}. If the option {@code "--suppressHeaders"}
191         * is already set, the field {@code suppressHeaders} points to the enum constant itself
192         * as it already represents the current set of options.
193         */
194        public final TailOptionSet_cqs suppressHeaders;
195        private final EnumSet<TailOption> options;
196        
197        //inherit javadoc
198        @Override
199        public Class<TailOption> optionType() {
200                return TailOption.class;
201        }
202        //inherit javadoc
203        @Override
204        public boolean isSet(TailOption option) {
205                return options.contains(option);
206        }
207        //inherit javadoc
208        @Override
209        public int size() {
210                return options.size();
211        }
212        /**
213         * Returns the set with the active options. The returned set a new defensive
214         * copy instance created when this method is called, modifications of this
215         * set will therefore not alter {@code this} option set.
216         * 
217         * @return a copy of the set with the active options.
218         */
219        @Override
220        public EnumSet<TailOption> asSet() {
221                return EnumSet.copyOf(options);
222        }
223        /**
224         * Returns an immutable iterator with the active options of this option set.
225         * 
226         * @return an immutable iterator for over the active options
227         */
228        @Override
229        public Iterator<TailOption> iterator() {
230                return Collections.unmodifiableSet(options).iterator();
231        }
232        /**
233         * Returns true if the {@link Option#acronym() acronym} should be used in
234         * for the specified {@code option} string representations. 
235         * <p>
236         * In particular and independent from the {@code option} argument, this 
237         * option set returns true if the last option added to this set was an 
238         * acronym, and false if it was a long option name. 
239         * <p>
240         * For instance, the set defined as
241         * <pre>
242         *    TailOptionSet_cqs.chars.s;
243         * </pre>
244         * uses acronyms, that is, this method always returns true for the above 
245         * set. 
246         * <p>
247         * On the other hand, long option names are used and this method always 
248         * returns false for the set
249         * <pre>
250         *    TailOptionSet_cqs.c.countFromStart;
251         * </pre>
252         * <p>
253         * Note that a repeated option is <i>not</i> treated as the last set option.
254         * For instance, the first and last option of the following set are 
255         * equivalent and acronyms are used:
256         * <pre>
257         *    TailOptionSet_cqs.c.s.chars;
258         * </pre>
259         * <p>
260         * This method always returns true for the empty set with no active options.
261         *  
262         * @param option
263         *            the option of interest, has no impact on the result returned
264         *            by this method
265         * @return true if option acronyms should be used for string representations
266         *         of any option of this option set
267         */
268        @Override
269        public boolean useAcronymFor(TailOption option) {
270                return useAcronym;
271        }
272}