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