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