1 package net.logAnalyzer.converters;
2
3 import net.logAnalyzer.handlers.ParsingException;
4
5 /***
6 * This class implements a converter used to parse or convert
7 * {@link java.lang.Double} values.
8 *
9 * @author Karim REFEYTON
10 * @version 0.1
11 */
12 public class DoubleConverter extends LAConverter {
13
14 /***
15 * Constructs a new converter from a converter definition.
16 * @param definition Definition of the converter.
17 * @param literal Literal value identifying the converter.
18 */
19 public DoubleConverter(ConverterDefinition definition, String literal) {
20 super(definition, literal);
21 }
22
23 /***
24 * Returns the class {@link java.lang.Double}.
25 * @see LAConverter#getValueClass()
26 */
27 public Class getValueClass() {
28 return Double.class;
29 }
30
31 /***
32 * Returns the value parsed with {@link Double#Double(java.lang.String)}.
33 * @return The parsed value.
34 * @see LAConverter#parse(String)
35 * @throws ParsingException If the value can't be parsed.
36 */
37 public Object parse(String value) throws ParsingException {
38 if (value == null || value.length() == 0 || value.equals("-")) {
39 return new Double(0);
40 } else {
41 return new Double(value);
42 }
43 }
44
45 /***
46 * Returns a string representation of the value calling <tt>toString()</tt>.
47 * @param value Value to convert as String.
48 * @return String representation of the value.
49 * @see LAConverter#toString(Object)
50 */
51 public String toString(Object value) {
52 return value.toString();
53 }
54 }