1:
16: package ;
17:
18: import ;
19: import ;
20:
21: import ;
22: import ;
23: import ;
24: import ;
25: import ;
26:
27:
33: public class SwitchBuilder
34: {
35: private final String m_enabledPrefix;
36: private final String m_disabledPrefix;
37: private String m_description;
38: private String m_preferredName;
39: private Set m_aliases;
40: private boolean m_required;
41: private Argument m_argument;
42: private Group m_children;
43: private int m_id;
44: private Boolean m_switchDefault;
45:
46:
51: public SwitchBuilder()
52: {
53: this( Switch.DEFAULT_ENABLED_PREFIX, Switch.DEFAULT_DISABLED_PREFIX );
54: }
55:
56:
63: public SwitchBuilder( final String enabledPrefix, final String disabledPrefix )
64: throws IllegalArgumentException
65: {
66: if( ( enabledPrefix == null ) || ( enabledPrefix.length() < 1 ) )
67: {
68: throw new IllegalArgumentException(
69: ResourceHelper.getResourceHelper().getMessage(
70: ResourceConstants.SWITCH_ILLEGAL_ENABLED_PREFIX ) );
71: }
72:
73: if( ( disabledPrefix == null ) || ( disabledPrefix.length() < 1 ) )
74: {
75: throw new IllegalArgumentException(
76: ResourceHelper.getResourceHelper().getMessage(
77: ResourceConstants.SWITCH_ILLEGAL_DISABLED_PREFIX ) );
78: }
79:
80: if( enabledPrefix.equals( disabledPrefix ) )
81: {
82: throw new IllegalArgumentException(
83: ResourceHelper.getResourceHelper().getMessage(
84: ResourceConstants.SWITCH_IDENTICAL_PREFIXES ) );
85: }
86:
87: m_enabledPrefix = enabledPrefix;
88: m_disabledPrefix = disabledPrefix;
89: reset();
90: }
91:
92:
96: public Switch create()
97: {
98: final Switch option =
99: new Switch(
100: m_enabledPrefix,
101: m_disabledPrefix,
102: m_preferredName,
103: m_aliases,
104: m_description,
105: m_required,
106: m_argument,
107: m_children,
108: m_id,
109: m_switchDefault );
110: reset();
111: return option;
112: }
113:
114:
118: public SwitchBuilder reset()
119: {
120: m_description = null;
121: m_preferredName = null;
122: m_required = false;
123: m_aliases = new HashSet();
124: m_argument = null;
125: m_children = null;
126: m_id = 0;
127: m_switchDefault = null;
128: return this;
129: }
130:
131:
136: public SwitchBuilder withDescription( final String newDescription )
137: {
138: m_description = newDescription;
139: return this;
140: }
141:
142:
149: public SwitchBuilder withName( final String name )
150: {
151: if( m_preferredName == null )
152: {
153: m_preferredName = name;
154: }
155: else
156: {
157: m_aliases.add( name );
158: }
159: return this;
160: }
161:
162:
167: public SwitchBuilder withRequired( final boolean newRequired )
168: {
169: m_required = newRequired;
170: return this;
171: }
172:
173:
178: public SwitchBuilder withArgument( final Argument newArgument )
179: {
180: m_argument = newArgument;
181: return this;
182: }
183:
184:
189: public SwitchBuilder withChildren( final Group newChildren )
190: {
191: m_children = newChildren;
192: return this;
193: }
194:
195:
201: public final SwitchBuilder withId( final int newId )
202: {
203: m_id = newId;
204: return this;
205: }
206:
207:
213: public final SwitchBuilder withSwitchDefault( final Boolean newSwitchDefault )
214: {
215: m_switchDefault = newSwitchDefault;
216: return this;
217: }
218: }