View Javadoc

1   /*
2    * NOTE - This file has been modified from the original Ant Version.
3    * The Apache licence under which Ant is released is set out below.
4    */
5   
6   /*
7    * Copyright  2002,2004 The Apache Software Foundation
8    *
9    *  Licensed under the Apache License, Version 2.0 (the "License");
10   *  you may not use this file except in compliance with the License.
11   *  You may obtain a copy of the License at
12   *
13   *      http://www.apache.org/licenses/LICENSE-2.0
14   *
15   *  Unless required by applicable law or agreed to in writing, software
16   *  distributed under the License is distributed on an "AS IS" BASIS,
17   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18   *  See the License for the specific language governing permissions and
19   *  limitations under the License.
20   *
21   */
22  
23  package org.apache.tools.ant.input;
24  
25  import java.util.Vector;
26  
27  /***
28   * Encapsulates an input request.
29   * Modified for Antigen from the original Ant version
30   *
31   * @version $Revision: 1.2 $
32   * @since Ant 1.5
33   */
34  public class MultipleChoiceInputRequest extends InputRequest {
35      private Vector choices = new Vector();
36  	private String theDefault;
37  
38      /***
39       * @param prompt The prompt to show to the user.  Must not be null.
40       * @param choices holds all input values that are allowed.
41       *                Must not be null.
42       */
43      public MultipleChoiceInputRequest(String prompt, Vector choices) {
44          super(prompt);
45          if (choices == null) {
46              throw new IllegalArgumentException("choices must not be null");
47          }
48          this.choices = choices;
49      }
50      
51      public MultipleChoiceInputRequest(String prompt, Vector choices, String theDefault) {
52          this(prompt, choices);
53          this.theDefault = theDefault;
54      }
55      
56      public String getDefault() {
57       return theDefault;   
58      }
59  
60      /***
61       * @return The possible values.
62       */
63      public Vector getChoices() {
64          return choices;
65      }
66  
67      /***
68       * @return true if the input is one of the allowed values.
69       */
70      public boolean isInputValid() {
71          return choices.contains(getInput());
72      }
73  }