Package com.alibaba.toolkit.util.typeconvert

Examples of com.alibaba.toolkit.util.typeconvert.ConvertFailedException


public class FloatConverter implements Converter {
    protected static final Float DEFAULT_VALUE = new Float(0.0F);

    public Object convert(Object value, ConvertChain chain) {
        if (value == null) {
            throw new ConvertFailedException().setDefaultValue(DEFAULT_VALUE);
        }

        if (value instanceof Float) {
            return value;
        }

        if (value instanceof Number) {
            return new Float(((Number) value).floatValue());
        }

        if (value instanceof String) {
            String strValue = ((String) value).trim();

            try {
                return new Float(strValue);
            } catch (NumberFormatException e) {
                if (strValue.length() > 0) {
                    throw new ConvertFailedException(e);
                }

                throw new ConvertFailedException().setDefaultValue(DEFAULT_VALUE);
            }
        }

        return chain.convert(value);
    }
View Full Code Here


public class IntegerConverter implements Converter {
    protected static final Integer DEFAULT_VALUE = new Integer(0);

    public Object convert(Object value, ConvertChain chain) {
        if (value == null) {
            throw new ConvertFailedException().setDefaultValue(DEFAULT_VALUE);
        }

        if (value instanceof Integer) {
            return value;
        }

        if (value instanceof Number) {
            return new Integer(((Number) value).intValue());
        }

        if (value instanceof String) {
            String strValue = ((String) value).trim();

            try {
                return Integer.decode(strValue);
            } catch (NumberFormatException e) {
                if (strValue.length() > 0) {
                    throw new ConvertFailedException(e);
                }

                throw new ConvertFailedException().setDefaultValue(DEFAULT_VALUE);
            }
        }

        return chain.convert(value);
    }
View Full Code Here

public class LongConverter implements Converter {
    protected static final Long DEFAULT_VALUE = new Long(0L);

    public Object convert(Object value, ConvertChain chain) {
        if (value == null) {
            throw new ConvertFailedException().setDefaultValue(DEFAULT_VALUE);
        }

        if (value instanceof Long) {
            return value;
        }

        if (value instanceof Number) {
            return new Long(((Number) value).longValue());
        }

        if (value instanceof String) {
            String strValue = ((String) value).trim();

            try {
                return Long.decode(strValue);
            } catch (NumberFormatException e) {
                if (strValue.length() > 0) {
                    throw new ConvertFailedException(e);
                }

                throw new ConvertFailedException().setDefaultValue(DEFAULT_VALUE);
            }
        }

        return chain.convert(value);
    }
View Full Code Here

public class DoubleConverter implements Converter {
    protected static final Double DEFAULT_VALUE = new Double(0.0);

    public Object convert(Object value, ConvertChain chain) {
        if (value == null) {
            throw new ConvertFailedException().setDefaultValue(DEFAULT_VALUE);
        }

        if (value instanceof Double) {
            return value;
        }

        if (value instanceof Number) {
            return new Double(((Number) value).doubleValue());
        }

        if (value instanceof String) {
            String strValue = ((String) value).trim();

            try {
                return new Double(strValue);
            } catch (NumberFormatException e) {
                if (strValue.length() > 0) {
                    throw new ConvertFailedException(e);
                }

                throw new ConvertFailedException().setDefaultValue(DEFAULT_VALUE);
            }
        }

        return chain.convert(value);
    }
View Full Code Here

public class ByteConverter implements Converter {
    protected static final Byte DEFAULT_VALUE = new Byte((byte) 0);

    public Object convert(Object value, ConvertChain chain) {
        if (value == null) {
            throw new ConvertFailedException().setDefaultValue(DEFAULT_VALUE);
        }

        if (value instanceof Byte) {
            return value;
        }

        if (value instanceof Number) {
            return new Byte(((Number) value).byteValue());
        }

        if (value instanceof String) {
            String strValue = ((String) value).trim();

            try {
                return Byte.decode(strValue);
            } catch (NumberFormatException e) {
                if (strValue.length() > 0) {
                    throw new ConvertFailedException(e);
                }

                throw new ConvertFailedException().setDefaultValue(DEFAULT_VALUE);
            }
        }

        return chain.convert(value);
    }
View Full Code Here

public class CharacterConverter implements Converter {
    protected static final Character DEFAULT_VALUE = new Character('\0');

    public Object convert(Object value, ConvertChain chain) {
        if (value == null) {
            throw new ConvertFailedException().setDefaultValue(DEFAULT_VALUE);
        }

        if (value instanceof Character) {
            return value;
        }

        if (value instanceof Number) {
            return new Character((char) ((Number) value).intValue());
        }

        if (value instanceof String) {
            String strValue = ((String) value).trim();

            try {
                return new Character((char) Integer.decode(strValue).intValue());
            } catch (NumberFormatException e) {
                if (strValue.length() > 0) {
                    throw new ConvertFailedException(e);
                }

                throw new ConvertFailedException().setDefaultValue(DEFAULT_VALUE);
            }
        }

        return chain.convert(value);
    }
View Full Code Here

public class FloatConverter implements Converter {
    protected static final Float DEFAULT_VALUE = new Float(0.0F);

    public Object convert(Object value, ConvertChain chain) {
        if (value == null) {
            throw new ConvertFailedException().setDefaultValue(DEFAULT_VALUE);
        }

        if (value instanceof Float) {
            return value;
        }

        if (value instanceof Number) {
            return new Float(((Number) value).floatValue());
        }

        if (value instanceof String) {
            String strValue = ((String) value).trim();

            try {
                return new Float(strValue);
            } catch (NumberFormatException e) {
                if (strValue.length() > 0) {
                    throw new ConvertFailedException(e);
                }

                throw new ConvertFailedException().setDefaultValue(DEFAULT_VALUE);
            }
        }

        return chain.convert(value);
    }
View Full Code Here

public class IntegerConverter implements Converter {
    protected static final Integer DEFAULT_VALUE = new Integer(0);

    public Object convert(Object value, ConvertChain chain) {
        if (value == null) {
            throw new ConvertFailedException().setDefaultValue(DEFAULT_VALUE);
        }

        if (value instanceof Integer) {
            return value;
        }

        if (value instanceof Number) {
            return new Integer(((Number) value).intValue());
        }

        if (value instanceof String) {
            String strValue = ((String) value).trim();

            try {
                return Integer.decode(strValue);
            } catch (NumberFormatException e) {
                if (strValue.length() > 0) {
                    throw new ConvertFailedException(e);
                }

                throw new ConvertFailedException().setDefaultValue(DEFAULT_VALUE);
            }
        }

        return chain.convert(value);
    }
View Full Code Here

public class LongConverter implements Converter {
    protected static final Long DEFAULT_VALUE = new Long(0L);

    public Object convert(Object value, ConvertChain chain) {
        if (value == null) {
            throw new ConvertFailedException().setDefaultValue(DEFAULT_VALUE);
        }

        if (value instanceof Long) {
            return value;
        }

        if (value instanceof Number) {
            return new Long(((Number) value).longValue());
        }

        if (value instanceof String) {
            String strValue = ((String) value).trim();

            try {
                return Long.decode(strValue);
            } catch (NumberFormatException e) {
                if (strValue.length() > 0) {
                    throw new ConvertFailedException(e);
                }

                throw new ConvertFailedException().setDefaultValue(DEFAULT_VALUE);
            }
        }

        return chain.convert(value);
    }
View Full Code Here

public class DoubleConverter implements Converter {
    protected static final Double DEFAULT_VALUE = new Double(0.0);

    public Object convert(Object value, ConvertChain chain) {
        if (value == null) {
            throw new ConvertFailedException().setDefaultValue(DEFAULT_VALUE);
        }

        if (value instanceof Double) {
            return value;
        }

        if (value instanceof Number) {
            return new Double(((Number) value).doubleValue());
        }

        if (value instanceof String) {
            String strValue = ((String) value).trim();

            try {
                return new Double(strValue);
            } catch (NumberFormatException e) {
                if (strValue.length() > 0) {
                    throw new ConvertFailedException(e);
                }

                throw new ConvertFailedException().setDefaultValue(DEFAULT_VALUE);
            }
        }

        return chain.convert(value);
    }
View Full Code Here

TOP

Related Classes of com.alibaba.toolkit.util.typeconvert.ConvertFailedException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.