Package com.google.refine.expr

Examples of com.google.refine.expr.EvalError


    @Override
    public Object call(Properties bindings, Object[] args) {
        if (args.length == 1 && args[0] != null && args[0] instanceof Number) {
            return Math.toRadians(((Number) args[0]).doubleValue());
        }
        return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects a number");
    }
View Full Code Here


            int a = ((Number) args[0]).intValue();
            int b = ((Number) args[1]).intValue();
           
            return a % b;
        }
        return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects 2 numbers");
    }
View Full Code Here

            Object s2 = args[1];
            if (s1 != null && s2 != null && s1 instanceof String && s2 instanceof String) {
                return ((String) s1).lastIndexOf((String) s2);
            }
        }
        return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects 2 strings");
    }
View Full Code Here

public class Combin implements Function {

    @Override
    public Object call(Properties bindings, Object[] args) {
        if(args.length != 2) {
            return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects two numbers");
        }
        if(args[0] == null || !(args[0] instanceof Number)) {
            return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects the first argument to be a number");
        }
        if(args[1] == null || !(args[1] instanceof Number)) {
            return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects the second argument to be a number");
        }

        return Combin.combination(((Number) args[0]).intValue(), ((Number) args[1]).intValue());
    }
View Full Code Here

            Object s2 = args[1];
            if (s1 != null && s2 != null && s1 instanceof String && s2 instanceof String) {
                return ((String) s1).indexOf((String) s2);
            }
        }
        return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects 2 strings");
    }
View Full Code Here

                }
            );

            return unwrap(result);
        } catch (PyException e) {
            return new EvalError(e.getMessage());
        }
    }
View Full Code Here

                    } catch (NumberFormatException e) {
                    }
                    try {
                        return Double.parseDouble(s);
                    } catch (NumberFormatException e) {
                        return new EvalError("Cannot parse to number");
                    }
                }
            }
        }
        return null;
View Full Code Here

                args[1] != null && args[1] instanceof Number) {
            return Math.max(
                ((Number) args[0]).doubleValue(),
                ((Number) args[1]).doubleValue());
        }
        return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects 2 numbers");
    }
View Full Code Here

    @Override
    public Object call(Properties bindings, Object[] args) {
        if (args.length == 1 && args[0] != null && args[0] instanceof Number) {
            return Math.tan(((Number) args[0]).doubleValue());
        }
        return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects a number");
    }
View Full Code Here

            o1 =  ((Long) arg0).toString(); // treat integers as years
        } else if (arg0 instanceof String) {
            o1 = (String) arg0;
        } else {
            // ignore cell values that aren't strings
            return new EvalError("Not a String - cannot parse to date");
        }

        // "o, boolean month_first (optional)"
        if (args.length == 1 || (args.length == 2 && args[1] instanceof Boolean)) {
            boolean month_first = true;
            if (args.length == 2) {
                month_first = (Boolean) args[1];
            }
            try {
                return CalendarParser.parse( o1, (month_first) ? CalendarParser.MM_DD_YY : CalendarParser.DD_MM_YY);
            } catch (CalendarParserException e) {
                Date d = ParsingUtilities.stringToDate(o1);
                if (d != null) {
                    return d;
                } else {
                    try {
                        return javax.xml.bind.DatatypeConverter.parseDateTime(o1).getTime();
                    } catch (IllegalArgumentException e2) {
                    }
                    // alternate implementation which may be useful on some JVMs?
//                    try {
//                        return javax.xml.datatype.DatatypeFactory.newInstance().newXMLGregorianCalendar(o1).toGregorianCalendar().getTime();
//                    } catch (DatatypeConfigurationException e2) {    
//                    }
                }
                return new EvalError("Cannot parse to date");
            }
        }

        // "o, format1, format2 (optional), ..."
        if (args.length>=2) {
            for (int i=1;i<args.length;i++) {
                if (!(args[i] instanceof String)) {
                    // skip formats that aren't strings
                    continue;
                }
                String format  = (String) args[i];
                SimpleDateFormat formatter;
                try {
                    formatter = new SimpleDateFormat(format);
                } catch (IllegalArgumentException e) {
                    return new EvalError("Unknown date format");
                }
                Date date = null;
                try {
                    date = formatter.parse(o1);
                } catch (java.text.ParseException e) {
                    continue;
                }
                if (date != null) {
                    GregorianCalendar c = new GregorianCalendar();
                    c.setTime(date);
                    return c;
                }
            }
            return new EvalError("Unable to parse as date");
        }

        return null;
    }
View Full Code Here

TOP

Related Classes of com.google.refine.expr.EvalError

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.