01: // Copyright 2007 The Apache Software Foundation
02: //
03: // Licensed under the Apache License, Version 2.0 (the "License");
04: // you may not use this file except in compliance with the License.
05: // You may obtain a copy of the License at
06: //
07: // http://www.apache.org/licenses/LICENSE-2.0
08: //
09: // Unless required by applicable law or agreed to in writing, software
10: // distributed under the License is distributed on an "AS IS" BASIS,
11: // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12: // See the License for the specific language governing permissions and
13: // limitations under the License.
14:
15: package org.apache.tapestry.upload.services;
16:
17: import static org.apache.tapestry.ioc.internal.util.CollectionFactory.newList;
18:
19: import java.util.List;
20:
21: /**
22: * Holds single or multivalued values.
23: */
24: public class ParameterValue {
25: private final List<String> _values = newList();
26:
27: public static final ParameterValue NULL = new ParameterValue() {
28: public String single() {
29: return null;
30: }
31:
32: public String[] multi() {
33: return null;
34: }
35: };
36:
37: public ParameterValue(String value) {
38: _values.add(value);
39: }
40:
41: public ParameterValue(String... values) {
42: for (String v : values) {
43: add(v);
44: }
45: }
46:
47: /**
48: * @return Single value of parameter (or first value if there are multiple values)
49: */
50: public String single() {
51: return _values.get(0);
52: }
53:
54: /**
55: * @return All values of parameter
56: */
57: public String[] multi() {
58: return _values.toArray(new String[_values.size()]);
59: }
60:
61: public void add(String value) {
62: _values.add(value);
63: }
64:
65: public boolean isMulti() {
66: return _values.size() > 1;
67: }
68: }
|