View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *      https://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 org.apache.commons.beanutils2.bugs.other;
18  
19  import java.util.HashMap;
20  import java.util.Map;
21  
22  import org.apache.commons.beanutils2.bugs.Jira18Test;
23  
24  /**
25   * Factory which creates <em>package</em> scope beans with public methods for {@link Jira18Test}.
26   */
27  public class Jira18BeanFactory {
28  
29      /* =============== Package Friendly Bean =============== */
30      static class PackageFriendlyBean {
31  
32          private final String[] indexed = { "one", "two", "three" };
33          private String simple = "FOO";
34          private final Map<String, Object> mapped = new HashMap<>();
35  
36          /** Default Constructor */
37          public PackageFriendlyBean() {
38              mapped.put("foo-key", "foo-value");
39              mapped.put("bar-key", "bar-value");
40          }
41  
42          /**
43           * Gets indexed property.
44           *
45           * @param index The index
46           * @return The indexed value
47           */
48          public String getIndexed(final int index) {
49              return indexed[index];
50          }
51  
52          /**
53           * Gets mapped property.
54           *
55           * @param key The mapped key
56           * @return The mapped value
57           */
58          public String getMapped(final String key) {
59              return (String) mapped.get(key);
60          }
61  
62          /**
63           * Gets simple property.
64           *
65           * @return The simple value
66           */
67          public String getSimple() {
68              return simple;
69          }
70  
71          /**
72           * Sets indexed property.
73           *
74           * @param index The index
75           * @param value The indexed value
76           */
77          public void setIndexed(final int index, final String value) {
78              this.indexed[index] = value;
79          }
80  
81          /**
82           * Sets mapped property.
83           *
84           * @param key   The mapped key
85           * @param value The mapped value
86           */
87          public void setMapped(final String key, final String value) {
88              mapped.put(key, value);
89          }
90  
91          /**
92           * Sets simple property.
93           *
94           * @param simple The simple value
95           */
96          public void setSimple(final String simple) {
97              this.simple = simple;
98          }
99  
100     }
101 
102     /**
103      * Factory method which creates package friendly beans.
104      *
105      * @return The a package friendly bean with public methods
106      */
107     public static Object createBean() {
108         return new PackageFriendlyBean();
109     }
110 
111 }