001package org.unix4j.unix.head;
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.Head;
010
011/**
012 * Option sets for the {@link Head head} command with 
013 * the following options: {@link #c c}, {@link #q q}.
014 * <p>
015 * Application code does normally not directly refer to this class;
016 * {@link Head#Options} should be used instead to specify command 
017 * options. See also {@link org.unix4j.unix.head.HeadOptions} for more information.
018 */
019public enum HeadOptionSet_cq implements HeadOptions {
020        /** Option set with the following active options: {@link #chars c}, {@link #suppressHeaders q}.*/
021        Active_cq(
022                /*c:*/null /*already set*/, /*chars:*/null /*already set*/, /*q:*/null /*already set*/, /*suppressHeaders:*/null /*already set*/, 
023                true, 
024                /*active:*/HeadOption.chars, HeadOption.suppressHeaders
025        ),
026        /** Option set with the following active options: {@link #chars c}, {@link #suppressHeaders q}.*/
027        Active_cq_long(
028                /*c:*/null /*already set*/, /*chars:*/null /*already set*/, /*q:*/null /*already set*/, /*suppressHeaders:*/null /*already set*/, 
029                false, 
030                /*active:*/HeadOption.chars, HeadOption.suppressHeaders
031        ),
032        /** Option set with the following active options: {@link #chars c}.*/
033        Active_c(
034                /*c:*/null /*already set*/, /*chars:*/null /*already set*/, /*q:*/Active_cq, /*suppressHeaders:*/Active_cq_long, 
035                true, 
036                /*active:*/HeadOption.chars
037        ),
038        /** Option set with the following active options: {@link #chars c}.*/
039        Active_c_long(
040                /*c:*/null /*already set*/, /*chars:*/null /*already set*/, /*q:*/Active_cq, /*suppressHeaders:*/Active_cq_long, 
041                false, 
042                /*active:*/HeadOption.chars
043        ),
044        /** Option set with the following active options: {@link #suppressHeaders q}.*/
045        Active_q(
046                /*c:*/Active_cq, /*chars:*/Active_cq_long, /*q:*/null /*already set*/, /*suppressHeaders:*/null /*already set*/, 
047                true, 
048                /*active:*/HeadOption.suppressHeaders
049        ),
050        /** Option set with the following active options: {@link #suppressHeaders q}.*/
051        Active_q_long(
052                /*c:*/Active_cq, /*chars:*/Active_cq_long, /*q:*/null /*already set*/, /*suppressHeaders:*/null /*already set*/, 
053                false, 
054                /*active:*/HeadOption.suppressHeaders
055        );
056        private HeadOptionSet_cq(
057                HeadOptionSet_cq c, HeadOptionSet_cq chars, HeadOptionSet_cq q, HeadOptionSet_cq suppressHeaders, 
058                boolean useAcronym,
059                HeadOption... activeOptions
060        ) {
061                this.c = c == null ? this : c;
062                this.chars = chars == null ? this : chars;
063                this.q = q == null ? this : q;
064                this.suppressHeaders = suppressHeaders == null ? this : suppressHeaders;
065                this.useAcronym = useAcronym;
066                this.options = activeOptions.length == 0 ? EnumSet.noneOf(HeadOption.class) : EnumSet.copyOf(Arrays.asList(activeOptions));
067        }
068        private final boolean useAcronym;
069        /**
070         * Option {@code "-c"}: The {@code count} argument is in units of characters instead of 
071                        lines. Starts from 1 and includes line ending characters.
072         * <p>
073         * The option {@code "-c"} is equivalent to the {@code "--}{@link #chars chars}{@code "} option.
074         * <p>
075         * Technically speaking, this field points to a set with the options of the 
076         * current set plus the option {@code "-c"}. If the option {@code "-c"}
077         * is already set, the field {@code c} points to the enum constant itself
078         * as it already represents the current set of options.
079         */
080        public final HeadOptionSet_cq c;
081        /**
082         * Option {@code "--chars"}: The {@code count} argument is in units of characters instead of 
083                        lines. Starts from 1 and includes line ending characters.
084         * <p>
085         * The option {@code "--chars"} is equivalent to the {@code "-}{@link #c c}{@code "} option.
086         * <p>
087         * Technically speaking, this field points to a set with the options of the 
088         * current set plus the option {@code "--chars"}. If the option {@code "--chars"}
089         * is already set, the field {@code chars} points to the enum constant itself
090         * as it already represents the current set of options.
091         */
092        public final HeadOptionSet_cq chars;
093        /**
094         * Option {@code "-q"}: Suppresses printing of headers when multiple files are being
095                        examined.
096         * <p>
097         * The option {@code "-q"} is equivalent to the {@code "--}{@link #suppressHeaders suppressHeaders}{@code "} option.
098         * <p>
099         * Technically speaking, this field points to a set with the options of the 
100         * current set plus the option {@code "-q"}. If the option {@code "-q"}
101         * is already set, the field {@code q} points to the enum constant itself
102         * as it already represents the current set of options.
103         */
104        public final HeadOptionSet_cq q;
105        /**
106         * Option {@code "--suppressHeaders"}: Suppresses printing of headers when multiple files are being
107                        examined.
108         * <p>
109         * The option {@code "--suppressHeaders"} is equivalent to the {@code "-}{@link #q q}{@code "} option.
110         * <p>
111         * Technically speaking, this field points to a set with the options of the 
112         * current set plus the option {@code "--suppressHeaders"}. If the option {@code "--suppressHeaders"}
113         * is already set, the field {@code suppressHeaders} points to the enum constant itself
114         * as it already represents the current set of options.
115         */
116        public final HeadOptionSet_cq suppressHeaders;
117        private final EnumSet<HeadOption> options;
118        
119        //inherit javadoc
120        @Override
121        public Class<HeadOption> optionType() {
122                return HeadOption.class;
123        }
124        //inherit javadoc
125        @Override
126        public boolean isSet(HeadOption option) {
127                return options.contains(option);
128        }
129        //inherit javadoc
130        @Override
131        public int size() {
132                return options.size();
133        }
134        /**
135         * Returns the set with the active options. The returned set a new defensive
136         * copy instance created when this method is called, modifications of this
137         * set will therefore not alter {@code this} option set.
138         * 
139         * @return a copy of the set with the active options.
140         */
141        @Override
142        public EnumSet<HeadOption> asSet() {
143                return EnumSet.copyOf(options);
144        }
145        /**
146         * Returns an immutable iterator with the active options of this option set.
147         * 
148         * @return an immutable iterator for over the active options
149         */
150        @Override
151        public Iterator<HeadOption> iterator() {
152                return Collections.unmodifiableSet(options).iterator();
153        }
154        /**
155         * Returns true if the {@link Option#acronym() acronym} should be used in
156         * for the specified {@code option} string representations. 
157         * <p>
158         * In particular and independent from the {@code option} argument, this 
159         * option set returns true if the last option added to this set was an 
160         * acronym, and false if it was a long option name. 
161         * <p>
162         * For instance, the set defined as
163         * <pre>
164         *    HeadOptionSet_cq.chars.q;
165         * </pre>
166         * uses acronyms, that is, this method always returns true for the above 
167         * set. 
168         * <p>
169         * On the other hand, long option names are used and this method always 
170         * returns false for the set
171         * <pre>
172         *    HeadOptionSet_cq.c.suppressHeaders;
173         * </pre>
174         * <p>
175         * Note that a repeated option is <i>not</i> treated as the last set option.
176         * For instance, the first and last option of the following set are 
177         * equivalent and acronyms are used:
178         * <pre>
179         *    HeadOptionSet_cq.c.q.chars;
180         * </pre>
181         * <p>
182         * This method always returns true for the empty set with no active options.
183         *  
184         * @param option
185         *            the option of interest, has no impact on the result returned
186         *            by this method
187         * @return true if option acronyms should be used for string representations
188         *         of any option of this option set
189         */
190        @Override
191        public boolean useAcronymFor(HeadOption option) {
192                return useAcronym;
193        }
194}