View Javadoc

1   /*
2    * Copyright 2011 Vincent Behar
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.rundeck.api;
17  
18  import java.util.Properties;
19  
20  /**
21   * Builder for job options
22   * 
23   * @author Vincent Behar
24   */
25  public class OptionsBuilder {
26  
27      private final Properties options;
28  
29      /**
30       * Build a new instance. Use {@link #addOption(Object, Object)} to add some options, and then
31       * {@link #toProperties()} when you're done !
32       */
33      public OptionsBuilder() {
34          options = new Properties();
35      }
36  
37      /**
38       * Add an option
39       * 
40       * @param key of the option
41       * @param value of the option
42       * @return this, for method chaining
43       */
44      public OptionsBuilder addOption(Object key, Object value) {
45          options.put(key, value);
46          return this;
47      }
48  
49      /**
50       * @return a new {@link Properties} instance
51       */
52      public Properties toProperties() {
53          Properties options = new Properties();
54          options.putAll(this.options);
55          return options;
56      }
57  
58  }