Frames | No Frames |
1: /** 2: * Copyright 2003-2004 The Apache Software Foundation 3: * Copyright 2005 Stephen McConnell 4: * 5: * Licensed under the Apache License, Version 2.0 (the "License"); 6: * you may not use this file except in compliance with the License. 7: * You may obtain a copy of the License at 8: * 9: * http://www.apache.org/licenses/LICENSE-2.0 10: * 11: * Unless required by applicable law or agreed to in writing, software 12: * distributed under the License is distributed on an "AS IS" BASIS, 13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14: * See the License for the specific language governing permissions and 15: * limitations under the License. 16: */ 17: package net.dpml.cli.builder; 18: 19: import java.util.ArrayList; 20: import java.util.List; 21: 22: import net.dpml.cli.Group; 23: import net.dpml.cli.Option; 24: import net.dpml.cli.option.GroupImpl; 25: 26: /** 27: * Builds Group instances. 28: * 29: * @author <a href="@PUBLISHER-URL@">@PUBLISHER-NAME@</a> 30: * @version @PROJECT-VERSION@ 31: */ 32: public class GroupBuilder 33: { 34: private String m_name; 35: private String m_description; 36: private List m_options; 37: private int m_minimum; 38: private int m_maximum; 39: 40: /** 41: * Creates a new GroupBuilder 42: */ 43: public GroupBuilder() 44: { 45: reset(); 46: } 47: 48: /** 49: * Creates a new Group instance 50: * @return the new Group instance 51: */ 52: public Group create() 53: { 54: final GroupImpl group = 55: new GroupImpl( 56: m_options, 57: m_name, 58: m_description, 59: m_minimum, 60: m_maximum ); 61: reset(); 62: return group; 63: } 64: 65: /** 66: * Resets the builder 67: * @return this builder 68: */ 69: public GroupBuilder reset() 70: { 71: m_name = null; 72: m_description = null; 73: m_options = new ArrayList(); 74: m_minimum = 0; 75: m_maximum = Integer.MAX_VALUE; 76: return this; 77: } 78: 79: /** 80: * Use this option description 81: * @param newDescription the description to use 82: * @return this builder 83: */ 84: public GroupBuilder withDescription( final String newDescription ) 85: { 86: m_description = newDescription; 87: return this; 88: } 89: 90: /** 91: * Use this option name 92: * @param newName the name to use 93: * @return this builder 94: */ 95: public GroupBuilder withName( final String newName ) 96: { 97: m_name = newName; 98: return this; 99: } 100: 101: /** 102: * A valid group requires at least this many options present 103: * @param newMinimum the minimum Options required 104: * @return this builder 105: */ 106: public GroupBuilder withMinimum( final int newMinimum ) 107: { 108: m_minimum = newMinimum; 109: return this; 110: } 111: 112: /** 113: * A valid group requires at most this many options present 114: * @param newMaximum the maximum Options allowed 115: * @return this builder 116: */ 117: public GroupBuilder withMaximum( final int newMaximum ) 118: { 119: m_maximum = newMaximum; 120: return this; 121: } 122: 123: /** 124: * Add this option to the group 125: * @param option the Option to add 126: * @return this builder 127: */ 128: public GroupBuilder withOption( final Option option ) 129: { 130: m_options.add( option ); 131: return this; 132: } 133: }