You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tinkerpop.apache.org by dkuppitz <gi...@git.apache.org> on 2017/10/04 18:48:12 UTC

[GitHub] tinkerpop issue #729: TINKERPOP-1632: Create a set of default functions

Github user dkuppitz commented on the issue:

    https://github.com/apache/tinkerpop/pull/729
  
    You can add a static compiled regex pattern:
    
    ```
    private static final Pattern EQUATION_PATTERN = Pattern.compile("\\b(?!abs|acos|asin|atan|cbrt|ceil|cos|cosh|exp|floor|log|log10|log2|sin|sinh|sqrt|tan|tanh|signum)(_|([A-Za-z][A-Za-z0-9]*))\\b");
    ```
    
    ...then `getVariables()` can be as simple as:
    
    ```
    protected static final Set<String> getVariables(final String equation) {
        final Matcher matcher = EQUATION_PATTERN.matcher(equation);
        final Set<String> variables = new LinkedHashSet<>();
        while (matcher.find()) {
            variables.add(matcher.group());
        }
        return variables;
    }
    ```
    
    And perhaps to increase the readability and maintainability, we should do something like this:
    
    ```
    private static final String[] FUNCTIONS = new String[] {
            "abs", "acos", "asin", "atan",
            "cbrt", "ceil", "cos", "cosh",
            "exp",
            "floor",
            "log", "log10", "log2",
            "signum", "sin", "sinh", "sqrt",
            "tan", "tanh"
        };
    
    private static final Pattern EQUATION_PATTERN = Pattern.compile("\\b(?!" +
            String.join("|", FUNCTIONS) + ")(_|([A-Za-z][A-Za-z0-9]*))\\b");
    ```


---