Package com.google.refine.expr

Examples of com.google.refine.expr.EvalError


    public Object call(Properties bindings, Evaluable[] args) {
        Object o;
        try {
            o = args[0].evaluate(bindings);
        } catch (Exception e) {
            o = new EvalError(e.toString());
        }
        return test(o);
    }
View Full Code Here


    public Object call(Properties bindings, Evaluable[] args) {
        Object o = args[0].evaluate(bindings);
        if (ExpressionUtils.isError(o)) {
            return o;
        } else if (!ExpressionUtils.isArrayOrCollection(o) && !(o instanceof JSONArray)) {
            return new EvalError("First argument to forEach is not an array");
        }
       
        String name = ((VariableExpr) args[1]).getName();
       
        Object oldValue = bindings.get(name);
        try {
            List<Object> results = null;
           
            if (o.getClass().isArray()) {
                Object[] values = (Object[]) o;
               
                results = new ArrayList<Object>(values.length);
                for (Object v : values) {
                    bindings.put(name, v);
                   
                    Object r = args[2].evaluate(bindings);
                   
                    results.add(r);
                }
            } else if (o instanceof JSONArray) {
                JSONArray a = (JSONArray) o;
                int l = a.length();
               
                results = new ArrayList<Object>(l);
                for (int i = 0; i < l; i++) {
                    try {
                        Object v = a.get(i);
                       
                        bindings.put(name, v);
                       
                        Object r = args[2].evaluate(bindings);
                       
                        results.add(r);
                    } catch (JSONException e) {
                        results.add(new EvalError(e.getMessage()));
                    }
                }
            } else {
                Collection<Object> collection = ExpressionUtils.toObjectCollection(o);
               
View Full Code Here

                                errorString);
                    } else {
                        message = e.toString();
                    }
                    return _onError == OnError.StoreError ?
                            new CellAtRow(urlData.row, new Cell(new EvalError(message), null)) : null;
                }
            } catch (Exception e) {
                return _onError == OnError.StoreError ?
                        new CellAtRow(urlData.row, new Cell(new EvalError(e.getMessage()), null)) : null;
            }
        }
View Full Code Here

                } else if ("soundex".equalsIgnoreCase(encoding)) {
                    return soundex.key(str);
                } else if ("cologne".equalsIgnoreCase(encoding)) {
                    return cologne.key(str);
                } else {
                    return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " doesn't know how to handle the '" + encoding + "' encoding.");
                }
            }
        }
        return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects 3 strings");
    }
View Full Code Here

            }
           
            try {
                return parser.parseLine(s);
            } catch (IOException e) {
                return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " error: " + e.getMessage());
            }
        }
        return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects 1 or 2 strings");
    }
View Full Code Here

                                return days / 30;
                            }
                            if ("years".equals(unit)) {
                                return days / 365;
                            }
                            return new EvalError("Unknown time unit " + unit);
                        } catch (CalendarParserException e) {
                            return new EvalError(e);
                        }
                    }
                }
            }
        }
        return new EvalError("Unexpected arguments - expecting either 2 strings or 2 dates and a unit string");
    }
View Full Code Here

    public Object call(Properties bindings, Object[] args) {
        if (args.length == 1 && args[0] != null) {
            Object o = args[0];
            return (o instanceof String ? (String) o : o.toString()).toLowerCase();
        }
        return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects a string");
    }
View Full Code Here

    public Object call(Properties bindings, Object[] args) {
        if (args.length == 1 && args[0] != null) {
            Object o = args[0];
            return (o instanceof String ? (String) o : o.toString()).toUpperCase();
        }
        return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects a string");
    }
View Full Code Here

                lastIndex = thisIndex;
            }
           
            return results;
        }
        return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects 1 string and 1 or more numbers");
    }
View Full Code Here

                } else if ("url".equals(mode)) {
                    try {
                        return URLEncoder.encode(s,"UTF-8");
                    } catch (UnsupportedEncodingException e) {}
                } else {
                    return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " does not recognize mode '" + mode + "'.");
                }
            }
        }
        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.