Revision 1965 org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.lib/src/main/java/org/gvsig/tools/dataTypes/impl/coercion/CoerceToString.java

View differences:

CoerceToString.java
32 32
public class CoerceToString implements CoercionWithLocale {
33 33

  
34 34
    @Override
35
	public Object coerce(Object value) throws CoercionException {
36
    	if( value == null ) {
37
    		return null;
38
    	}
39
		try {
40
			if( !(value instanceof String )) {
41
				value = value.toString();
42
			}
43
			return value;
44
		} catch (Exception e) {
45
			throw new CoercionException(e);
46
		}
35
    public Object coerce(Object value) throws CoercionException {
36
        if (value == null) {
37
            return null;
38
        }
39
        try {
40
            if (!(value instanceof String)) {
41
                value = value.toString();
42
            }
43
            return value;
44
        } catch (Exception e) {
45
            throw new CoercionException(e);
46
        }
47 47

  
48
	}
48
    }
49 49

  
50 50
    @Override
51
	public Object coerce(Object value, Locale locale) throws CoercionException {
52
    	if( value == null ) {
53
    		return null;
54
    	}
55
		try {
56
			if( !(value instanceof String )) {
57
				if( value instanceof Float || value instanceof Double ) {
58
					NumberFormat nf = NumberFormat.getInstance(locale);
59
					value = nf.format(((Number)value).doubleValue());
60
				} else {
61
					value = value.toString();
62
				}
63
			}
64
			return value;
65
		} catch (Exception e) {
66
			throw new CoercionException(e);
67
		}
68
	}
51
    public Object coerce(Object value, Locale locale) throws CoercionException {
52
        if (value == null) {
53
            return null;
54
        }
55
        try {
56
            if (!(value instanceof String)) {
57
                if (value instanceof Float || value instanceof Double) {
58
                    NumberFormat nf = NumberFormat.getInstance(locale);
59
                    value = nf.format(((Number) value).doubleValue());
60
                } else {
61
                    value = value.toString();
62
                }
63
            }
64
            return value;
65
        } catch (Exception e) {
66
            throw new CoercionException(e);
67
        }
68
    }
69 69

  
70 70
}

Also available in: Unified diff