1 /**
2 * Copyright (C) 2016 Gary Gregory. All rights reserved.
3 *
4 * See the NOTICE.txt file distributed with this work for additional
5 * information regarding copyright ownership.
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 */
19
20 package com.garygregory.jcommander.converters.math;
21
22 import java.math.BigDecimal;
23
24 import com.garygregory.jcommander.converters.AbstractBaseConverter;
25
26 /**
27 * Converts a {@link String} into a {@link BigDecimal}.
28 * <p>
29 * For a description of the format, see {@link BigDecimal#BigDecimal(String)}.
30 * </p>
31 *
32 * <p>
33 * Example:
34 * </p>
35 *
36 * <pre class="prettyprint">
37 * <code class="language-java">@Parameter(names = { "--bigDecimal" }, converter = BigDecimalConverter.class)
38 * private BigDecimal bigDecimal;</code>
39 * </pre>
40 * <p>
41 *
42 * @see BigDecimal
43 * @see BigDecimal#BigDecimal(String)
44 *
45 * @since 1.0.0
46 * @author <a href="mailto:ggregory@garygregory.com">Gary Gregory</a>
47 */
48 public class BigDecimalConverter extends AbstractBaseConverter<BigDecimal> {
49
50 /**
51 * Constructs a converter.
52 *
53 * @param optionName
54 * The option name, may be null.
55 */
56 public BigDecimalConverter(final String optionName) {
57 super(optionName, BigDecimal.class);
58 }
59
60 @Override
61 protected BigDecimal convertImpl(final String value) {
62 return new BigDecimal(value);
63 }
64
65 }