Package com.google.refine.expr

Examples of com.google.refine.expr.EvalError


                Calendar c = Calendar.getInstance();
                c.setTime((Date) args[0]);
                return getPart(c, part);
            }
        }
        return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects a date and a string");
    }
View Full Code Here


        } else if ("weekday".equals(part)) {
            return s_daysOfWeek[c.get(Calendar.DAY_OF_WEEK)];
        } else if ("time".equals(part)) {
            return c.getTimeInMillis();
        } else {
            return new EvalError("Date unit '" + part + "' not recognized.");
        }
    }
View Full Code Here

    public Object call(Properties bindings, Object[] args) {
        if (args.length == 2 && args[0] != null && args[0] instanceof Number
                && args[1] != null && args[1] instanceof Number) {
            return GreatestCommonDenominator.GCD(((Number) args[0]).doubleValue(), ((Number) args[1]).doubleValue());
        }
        return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects two numbers");
    }
View Full Code Here

                    }
                }
                return total;
            }
        }
        return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects an array of numbers");
    }
View Full Code Here

            if (v != null) {
                if (v instanceof JSONArray) {
                    try {
                        v = JSONUtilities.toArray((JSONArray) v);
                    } catch (JSONException e) {
                        return new EvalError(ControlFunctionRegistry.getFunctionName(this) +
                                " fails to process a JSON array: " + e.getMessage());
                    }
                }
               
                if (v.getClass().isArray() || v instanceof List<?>) {
                    int length = v.getClass().isArray() ?
                            ((Object[]) v).length :
                            ExpressionUtils.toObjectList(v).size();
                   
                    Object[] r = new Object[length];
                    if (v.getClass().isArray()) {
                        Object[] a = (Object[]) v;
                        for (int i = 0; i < length; i++) {
                            r[i] = a[r.length - i - 1];
                        }
                    } else {
                        List<Object> a = ExpressionUtils.toObjectList(v);
                        for (int i = 0; i < length; i++) {
                            r[i] = a.get(r.length - i - 1);
                        }
                    }
                    return r;
                }
            }
        }
        return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects an array");
    }
View Full Code Here

    @Override
    public Object call(Properties bindings, Object[] args) {
        if (args.length == 1 && args[0] != null && args[0] instanceof Number) {
            return StrictMath.cosh(((Number) args[0]).doubleValue());
        }
        return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects a number");
    }
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.log(((Number) args[0]).doubleValue());
        }
        return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects a number");
    }
View Full Code Here

            if (v != null) {
                if (v instanceof JSONArray) {
                    try {
                        v = JSONUtilities.toArray((JSONArray) v);
                    } catch (JSONException e) {
                        return new EvalError(ControlFunctionRegistry.getFunctionName(this) +
                                " fails to process a JSON array: " + e.getMessage());
                    }
                }
               
                if (v.getClass().isArray() || v instanceof List<?>) {
                    Set<Object> set = null;
                   
                    if (v.getClass().isArray()) {
                        Object[] a = (Object[]) v;
                       
                        set = new HashSet<Object>(a.length);
                        for (Object element : a) {
                            set.add(element);
                        }
                    } else {
                        set = new HashSet<Object>(ExpressionUtils.toObjectList(v));
                    }
                    return set.toArray();
                }
            }
        }
        return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects an array");
    }
View Full Code Here

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

                       
                        Arrays.sort(r, 0, r.length);
                       
                        return r;
                    } catch (JSONException e) {
                        return new EvalError(ControlFunctionRegistry.getFunctionName(this) +
                                " fails to process a JSON array: " + e.getMessage());
                    }
                } else if (v instanceof List<?>) {
                    List<? extends Comparable<Object>> a = (List<? extends Comparable<Object>>) v;
                    Collections.sort(a);
                   
                    return a;
                }
            }
        }
        return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects an array");
    }
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.