class SchemaValueConverter {

    public static Object convert(Schema.Type type, Object value) {
        if (value == null) {
            return null;
        }

        switch (type) {
            case BOOLEAN:
                if (value instanceof Boolean) {
                    return value;
                } else if (value instanceof String) {
                    return Boolean.valueOf((String) value);
                }
                break;

            case BYTE:
            case SHORT:
            case INTEGER:
            case LONG:
            case FLOAT:
            case DOUBLE:
                return convertNumber(type, value);

            case STRING:
                if (value instanceof String) {
                    return value;
                }
                break;

            case BINARY:
                if (value instanceof byte[]) {
                    return value;
                }
                break;

            case NESTED:
                if (value instanceof Map) {
                    return value;
                }
                break;

            case ARRAY:
                if (value instanceof List) {
                    return value;
                }
                break;

        }

        throw new IllegalArgumentException("Cannot convert value " + value + " with Java type class " +
                value.getClass() + " to type " + type);
    }

    private  SchemaValueConverter();

}