commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Dmitri Blinov (JIRA)" <j...@apache.org>
Subject [jira] [Created] (JEXL-228) Ability to read j.u.Collection elements other than instanceof j.u.List by using [] and . operator
Date Sun, 25 Jun 2017 08:50:00 GMT
Dmitri Blinov created JEXL-228:
----------------------------------

             Summary: Ability to read j.u.Collection elements other than instanceof j.u.List
by using [] and . operator
                 Key: JEXL-228
                 URL: https://issues.apache.org/jira/browse/JEXL-228
             Project: Commons JEXL
          Issue Type: Improvement
    Affects Versions: 3.1
            Reporter: Dmitri Blinov
            Priority: Minor


In the current implementation of Jexl there is a possibility to address in a script the specific
elements of {{List}} and {{Array}} by using operators {{[]}} or {{.}}, whereas its not that
simple for descendants of {{Set}} or any other {{Collection}} descendant, as there is no such
an operator for them out of the box. But in practice this is not so uncommon task for a script
writer to get, for example, the first element of the LinkedHashSet, which is supposed to maintain
the logical order of its elements, but unfortunately does not implement {{List}} interface
for us to be able to address its elements in that order. I believe such a basic functionality
- deserves to be available for script witers from the start.

I have been experimenting with overloading access operators in customized JexlArithmetic for
a while and have managed to overload operators {{[]}} and {{.}} so that they could be used
not only for {{List}} interfaces but for other {{Collection}} types as well:

{code}
    protected Object nth(Collection c, int i) {

       if (c instanceof List) {
         List list = (List) c;
         return list.get(i);
       } else {

         for (Object o : c) {
            if (i-- == 0)
              return o;
         }
       }

       return null;
    }

    public Object propertyGet(Collection c, Number n) {
       return nth(c, n.intValue());
    }

    public Object arrayGet(Collection c, Number n) {
       return nth(c, n.intValue());
    }
{code}

But I'm not satisfied with the fact that I have disabled alltogether the initial Jexl implementation
of access operators for {{LIst}} types.

The suggestion is to add the ability for Jexl scripts to read, not manipulate, elements of
any {{Collection}} type. 

BTW, I have found that for {{List}} elements this solution is roughly 50% faster compared
with that of built-in Jexl List access implementation, so may be there should be a place for
a performance improvement in a way Jexl itself accesses list elements.



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Mime
View raw message