Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
BigDecimalField |
|
| 2.4;2.4 |
1 | package org.apache.fulcrum.intake.model; | |
2 | ||
3 | /* | |
4 | * Licensed to the Apache Software Foundation (ASF) under one | |
5 | * or more contributor license agreements. See the NOTICE file | |
6 | * distributed with this work for additional information | |
7 | * regarding copyright ownership. The ASF licenses this file | |
8 | * to you under the Apache License, Version 2.0 (the | |
9 | * "License"); you may not use this file except in compliance | |
10 | * with the License. You may obtain a copy of the License at | |
11 | * | |
12 | * http://www.apache.org/licenses/LICENSE-2.0 | |
13 | * | |
14 | * Unless required by applicable law or agreed to in writing, | |
15 | * software distributed under the License is distributed on an | |
16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | |
17 | * KIND, either express or implied. See the License for the | |
18 | * specific language governing permissions and limitations | |
19 | * under the License. | |
20 | */ | |
21 | ||
22 | import java.math.BigDecimal; | |
23 | ||
24 | import org.apache.fulcrum.intake.IntakeException; | |
25 | import org.apache.fulcrum.intake.validator.BigDecimalValidator; | |
26 | ||
27 | /** | |
28 | * @author <a href="mailto:jmcnally@collab.net">John McNally</a> | |
29 | * @author <a href="mailto:dlr@finemaltcoding.com">Daniel Rall</a> | |
30 | * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a> | |
31 | * @author <a href="mailto:quintonm@bellsouth.net">Quinton McCombs</a> | |
32 | * @author <a href="mailto:tv@apache.org">Thomas Vandahl</a> | |
33 | * @version $Id: BigDecimalField.java 1770205 2016-11-17 15:03:41Z tv $ | |
34 | */ | |
35 | public class BigDecimalField | |
36 | extends Field<BigDecimal> | |
37 | { | |
38 | /** Serial version */ | |
39 | private static final long serialVersionUID = -8356433008715252236L; | |
40 | ||
41 | /** | |
42 | * Constructor. | |
43 | * | |
44 | * @param field xml field definition object | |
45 | * @param group xml group definition object | |
46 | * @throws IntakeException thrown by superclass | |
47 | */ | |
48 | public BigDecimalField(XmlField field, Group group) | |
49 | throws IntakeException | |
50 | { | |
51 | 2 | super(field, group); |
52 | 2 | } |
53 | ||
54 | /** | |
55 | * Sets the default value for a BigDecimal field | |
56 | * | |
57 | * @param prop Parameter for the default values | |
58 | */ | |
59 | @Override | |
60 | public void setDefaultValue(String prop) | |
61 | { | |
62 | 2 | defaultValue = null; |
63 | ||
64 | 2 | if (prop == null) |
65 | { | |
66 | 2 | return; |
67 | } | |
68 | ||
69 | 0 | defaultValue = new BigDecimal(prop); |
70 | 0 | } |
71 | ||
72 | /** | |
73 | * Set the empty Value. This value is used if Intake | |
74 | * maps a field to a parameter returned by the user and | |
75 | * the corresponding field is either empty (empty string) | |
76 | * or non-existant. | |
77 | * | |
78 | * @param prop The value to use if the field is empty. | |
79 | */ | |
80 | @Override | |
81 | public void setEmptyValue(String prop) | |
82 | { | |
83 | 2 | emptyValue = null; |
84 | ||
85 | 2 | if (prop == null) |
86 | { | |
87 | 2 | return; |
88 | } | |
89 | ||
90 | 0 | emptyValue = new BigDecimal(prop); |
91 | 0 | } |
92 | ||
93 | /** | |
94 | * A suitable validator. | |
95 | * | |
96 | * @return A suitable validator | |
97 | */ | |
98 | @Override | |
99 | protected String getDefaultValidator() | |
100 | { | |
101 | 2 | return BigDecimalValidator.class.getName(); |
102 | } | |
103 | ||
104 | /** | |
105 | * Sets the value of the field from data in the parser. | |
106 | */ | |
107 | @Override | |
108 | protected void doSetValue() | |
109 | { | |
110 | 0 | if (isMultiValued()) |
111 | { | |
112 | 0 | BigDecimal[] values = parser.getBigDecimals(getKey()); |
113 | ||
114 | 0 | for (int i = 0; i < values.length; i++) |
115 | { | |
116 | 0 | if (values[i] == null) |
117 | { | |
118 | 0 | values[i] = getEmptyValue(); |
119 | } | |
120 | } | |
121 | ||
122 | 0 | setTestValue(values); |
123 | 0 | } |
124 | else | |
125 | { | |
126 | 0 | setTestValue(parser.getBigDecimal(getKey(), getEmptyValue())); |
127 | } | |
128 | 0 | } |
129 | } |