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