/*
 * ObjectSelector - Object selection library for Java
 * Copyright (C) 2013 Fabian Prasser
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */

package de.linearbits.objectselector.datatypes;

/**
 * Double data type
 * @author Fabian Prasser
 */
public class DNumeric extends DataType<Double>{

    /**
     * Creates a new numeric data type
     */
    protected DNumeric(){
        // Empty by design
    }

    @Override
    public Double fromObject(Object object) {
        if (object instanceof Double) return (Double)object;
        else if (object instanceof Character) return Double.valueOf((Character)object);
        else if (object instanceof Short) return Double.valueOf((Short)object);
        else if (object instanceof Integer) return Double.valueOf((Integer)object);
        else if (object instanceof Float) return Double.valueOf((Float)object);
        return fromString(String.valueOf(object));
    }

    @Override
    public Double fromString(String value) {
        return Double.valueOf(value);
    }
}

@@ -811,16 +811,85 @@
 pes;%0D%0A%0D%0A
+import java.text.DecimalFormat;%0D%0Aimport java.text.ParseException;%0D%0A%0D%0A
 /**%0D%0A * 
@@ -993,119 +993,582 @@
 %0D%0A%0D%0A
-    /**%0D%0A     * Creates a new numeric data type%0D%0A     */%0D%0A    protected DNumeric()%7B%0D%0A        // Empty by design
+%09/** Format, if any*/%0D%0A%09private String string;%0D%0A%09/** Format, if any*/%0D%0A%09private DecimalFormat format;%0D%0A%09%0D%0A    /**%0D%0A     * Creates a new numeric data type%0D%0A     */%0D%0A    protected DNumeric()%7B%0D%0A    %09this.string = null;%0D%0A    %09this.format = null;%0D%0A    %7D%0D%0A    %0D%0A    /**%0D%0A     * Creates a new numeric data type with given format%0D%0A     * @param format%0D%0A     */%0D%0A    protected DNumeric(String format)%7B%0D%0A    %09if (format == null)%7B%0D%0A    %09%09this.string = null;%0D%0A    %09%09this.format = null;%09%0D%0A    %09%7D else %7B%0D%0A    %09%09this.string = format;%0D%0A    %09%09this.format = new DecimalFormat(string);%0D%0A    %09%7D
 %0D%0A  
@@ -2168,37 +2168,196 @@
     
-return Double.valueOf(value);
+try %7B%0D%0A%09%09%09return format == null ? Double.valueOf(value) : format.parse(value).doubleValue();%0D%0A%09%09%7D catch (NumberFormatException %7C ParseException e) %7B%0D%0A%09%09%09throw new RuntimeException(e);%0D%0A%09%09%7D
 %0D%0A  

Add format to numeric data type