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.sin(((Number) args[0]).doubleValue());
        }
        return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects a number");
    }
View Full Code Here


            if (o1 != null && o1 instanceof Element) {
                Element e1 = (Element)o1;
                return e1.text();

            }else{
                return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " failed as the first parameter is not an HTML Element.  Please first use parseHtml(string) and select(query) prior to using this function");
            }
        }
        return null;
    }
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.toDegrees(((Number) args[0]).doubleValue());
        }
        return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects a number");
    }
View Full Code Here

    public Object evaluate(Properties bindings) {
        Object o = _inner.evaluate(bindings);
        if (ExpressionUtils.isError(o)) {
            return o; // bubble the error up
        } else if (o == null) {
            return new EvalError("Cannot retrieve field from null");
        } else if (o instanceof HasFields) {
            return ((HasFields) o).getField(_fieldName, bindings);
        } else if (o instanceof JSONObject) {
            try {
                return ((JSONObject) o).get(_fieldName);
            } catch (JSONException e) {
                return new EvalError("Object does not have any field, including " + _fieldName);
            }
        } else {
            return new EvalError("Object does not have any field, including " + _fieldName);
        }
    }
View Full Code Here

    @Override
    public Object evaluate(Properties bindings) {
        try {
            return _control.call(bindings, _args);
        } catch (Exception e) {
            return new EvalError(e.toString());
        }
    }
View Full Code Here

             args[i] = v;
        }
        try {
            return _function.call(bindings, args);
        } catch (Exception e) {
            return new EvalError(e.toString());
        }
    }
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 indexName = ((VariableExpr) args[1]).getName();
        String elementName = ((VariableExpr) args[2]).getName();
       
        Object oldIndexValue = bindings.get(indexName);
        Object oldElementValue = bindings.get(elementName);
        try {
            List<Object> results = null;
           
            if (o.getClass().isArray()) {
                Object[] values = (Object[]) o;
               
                results = new ArrayList<Object>(values.length);
               
                for (int i = 0; i < values.length; i++) {
                    Object v = values[i];
                   
                    bindings.put(indexName, i);
                    bindings.put(elementName, v);
                   
                    Object r = args[3].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(indexName, i);
                        bindings.put(elementName, v);
                       
                        Object r = args[3].evaluate(bindings);
                       
                        results.add(r);
                    } catch (JSONException e) {
                        results.add(new EvalError(e.getMessage()));
                    }
                }
            } else {
                List<Object> list = ExpressionUtils.toObjectList(o);
               
View Full Code Here

                } else {
                    // legacy
                    recon = Recon.loadStreaming(jp, pool);
                }
            } else if ("e".equals(fieldName)) {
                value = new EvalError(jp.getText());
            } else if ("v".equals(fieldName)) {
                JsonToken token = jp.getCurrentToken();
           
                if (token == JsonToken.VALUE_STRING) {
                    value = jp.getText();
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 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);
                    if (r instanceof Boolean && ((Boolean) r).booleanValue()) {
                        results.add(v);
                    }
                }
            } 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);
                        if (r instanceof Boolean && ((Boolean) r).booleanValue()) {
                            results.add(v);
                        }
                    } catch (JSONException e) {
                        results.add(new EvalError(e.getMessage()));
                    }
                }
            } else {
                Collection<Object> collection = ExpressionUtils.toObjectCollection(o);
               
View Full Code Here

        } else if (ExpressionUtils.isError(toO)) {
            return toO;
        } else if (ExpressionUtils.isError(stepO)) {
            return stepO;
        } else if (!(fromO instanceof Number) || !(toO instanceof Number) || !(stepO instanceof Number)) {
            return new EvalError("First, second, and third arguments of forRange must all be numbers");
        }
       
        String indexName = ((VariableExpr) args[3]).getName();
        Object oldIndexValue = bindings.get(indexName);
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.