1:
17: package ;
18:
19: import ;
20: import ;
21:
22: import ;
23: import ;
24: import ;
25: import ;
26: import ;
27:
28:
34: public class DefaultOptionBuilder
35: {
36: private final String m_shortPrefix;
37: private final String m_longPrefix;
38: private final boolean m_burstEnabled;
39: private String m_preferredName;
40: private Set m_aliases;
41: private Set m_burstAliases;
42: private boolean m_required;
43: private String m_description;
44: private Argument m_argument;
45: private Group m_children;
46: private int m_id;
47:
48:
54: public DefaultOptionBuilder()
55: {
56: this(
57: DefaultOption.DEFAULT_SHORT_PREFIX,
58: DefaultOption.DEFAULT_LONG_PREFIX,
59: DefaultOption.DEFAULT_BURST_ENABLED );
60: }
61:
62:
70: public DefaultOptionBuilder(
71: final String shortPrefix, final String longPrefix, final boolean burstEnabled )
72: throws IllegalArgumentException
73: {
74: if( ( shortPrefix == null ) || ( shortPrefix.length() == 0 ) )
75: {
76: throw new IllegalArgumentException(
77: ResourceHelper.getResourceHelper().getMessage(
78: ResourceConstants.OPTION_ILLEGAL_SHORT_PREFIX ) );
79: }
80:
81: if( ( longPrefix == null ) || ( longPrefix.length() == 0 ) )
82: {
83: throw new IllegalArgumentException(
84: ResourceHelper.getResourceHelper().getMessage(
85: ResourceConstants.OPTION_ILLEGAL_LONG_PREFIX ) );
86: }
87:
88: m_shortPrefix = shortPrefix;
89: m_longPrefix = longPrefix;
90: m_burstEnabled = burstEnabled;
91: reset();
92: }
93:
94:
99: public DefaultOption create() throws IllegalStateException
100: {
101: if( m_preferredName == null )
102: {
103: throw new IllegalStateException(
104: ResourceHelper.getResourceHelper().getMessage(
105: ResourceConstants.OPTION_NO_NAME ) );
106: }
107: final DefaultOption option =
108: new DefaultOption(
109: m_shortPrefix,
110: m_longPrefix,
111: m_burstEnabled,
112: m_preferredName,
113: m_description,
114: m_aliases,
115: m_burstAliases,
116: m_required,
117: m_argument,
118: m_children,
119: m_id );
120: reset();
121: return option;
122: }
123:
124:
128: public DefaultOptionBuilder reset()
129: {
130: m_preferredName = null;
131: m_description = null;
132: m_aliases = new HashSet();
133: m_burstAliases = new HashSet();
134: m_required = false;
135: m_argument = null;
136: m_children = null;
137: m_id = 0;
138: return this;
139: }
140:
141:
148: public DefaultOptionBuilder withShortName( final String shortName )
149: {
150: final String name = m_shortPrefix + shortName;
151: if( m_preferredName == null )
152: {
153: m_preferredName = name;
154: }
155: else
156: {
157: m_aliases.add( name );
158: }
159: if( m_burstEnabled && ( name.length() == ( m_shortPrefix.length() + 1 ) ) )
160: {
161: m_burstAliases.add( name );
162: }
163: return this;
164: }
165:
166:
173: public DefaultOptionBuilder withLongName( final String longName )
174: {
175: final String name = m_longPrefix + longName;
176: if( m_preferredName == null )
177: {
178: m_preferredName = name;
179: }
180: else
181: {
182: m_aliases.add( name );
183: }
184: return this;
185: }
186:
187:
192: public DefaultOptionBuilder withDescription( final String newDescription )
193: {
194: m_description = newDescription;
195: return this;
196: }
197:
198:
203: public DefaultOptionBuilder withRequired( final boolean newRequired )
204: {
205: m_required = newRequired;
206: return this;
207: }
208:
209:
214: public DefaultOptionBuilder withChildren( final Group newChildren )
215: {
216: m_children = newChildren;
217: return this;
218: }
219:
220:
225: public DefaultOptionBuilder withArgument( final Argument newArgument )
226: {
227: m_argument = newArgument;
228: return this;
229: }
230:
231:
238: public final DefaultOptionBuilder withId( final int newId )
239: {
240: m_id = newId;
241: return this;
242: }
243: }