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