[jira] [Comment Edited] (JEXL-151) operators to manipulate j.u.Collection

2015-07-28 Thread Henri Biestro (JIRA)

[ 
https://issues.apache.org/jira/browse/JEXL-151?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanelfocusedCommentId=14642859#comment-14642859
 ] 

Henri Biestro edited comment on JEXL-151 at 7/28/15 6:46 AM:
-

After JEXL-170 has been implemented it is straight-forward to implement the 
required functionality by extending JexlArithmetic. If you feel it has any 
sence to others you may include the code below in base implementaion:

{code}
public CollectionObject selfAdd(CollectionObject c, Object x) {

if (x != null  c != null) {

   if (x instanceof Collection?) {
 c.addAll((Collection?)x);
   } else if (x.getClass().isArray()) {
 for (int i = 0; i  Array.getLength(x); i++) {
   Object key = Array.get(x, i);
   c.add(key);
 }
   } else {
 c.add(x);
   }
}

return c;
}

public CollectionObject selfSubtract(CollectionObject c, Object x) {

if (x != null  c != null) {

   if (x instanceof Collection) {
 c.removeAll((Collection?)x);
   } else if (x.getClass().isArray()) {
 for (int i = 0; i  Array.getLength(x); i++) {
   Object key = Array.get(x, i);
   c.remove(key);
 }
   } else {
 c.remove(x);
   }
}

return c;
}

public CollectionObject selfMultiply(CollectionObject c, Object x) {

if (x != null  c != null) {

   if (x instanceof Collection?) {
 c.retainAll((Collection?) x);
   } else if (x.getClass().isArray()) {
 ListObject list = new ArrayListObject();
 for (int i = 0; i  Array.getLength(x); i++) {
   Object key = Array.get(x, i);
   list.add(key);
 }
 c.retainAll(list);
   } else {
 ListObject list = new ArrayListObject();
 list.add(x);
 c.retainAll(list);
   }
}

return c;
}
{code}


was (Author: dmitri_blinov):
After JEXL-170 has been implemented it is straight-forward to implement the 
required functionality by extending JexlArithmetic. If you feel it has any 
sence to others you may include the code below in base implementaion:

{{{quote}{noformat}
public CollectionObject selfAdd(CollectionObject c, Object x) {

if (x != null  c != null) {

   if (x instanceof Collection?) {
 c.addAll((Collection?)x);
   } else if (x.getClass().isArray()) {
 for (int i = 0; i  Array.getLength(x); i++) {
   Object key = Array.get(x, i);
   c.add(key);
 }
   } else {
 c.add(x);
   }
}

return c;
}

public CollectionObject selfSubtract(CollectionObject c, Object x) {

if (x != null  c != null) {

   if (x instanceof Collection) {
 c.removeAll((Collection?)x);
   } else if (x.getClass().isArray()) {
 for (int i = 0; i  Array.getLength(x); i++) {
   Object key = Array.get(x, i);
   c.remove(key);
 }
   } else {
 c.remove(x);
   }
}

return c;
}

public CollectionObject selfMultiply(CollectionObject c, Object x) {

if (x != null  c != null) {

   if (x instanceof Collection?) {
 c.retainAll((Collection?) x);
   } else if (x.getClass().isArray()) {
 ListObject list = new ArrayListObject();
 for (int i = 0; i  Array.getLength(x); i++) {
   Object key = Array.get(x, i);
   list.add(key);
 }
 c.retainAll(list);
   } else {
 ListObject list = new ArrayListObject();
 list.add(x);
 c.retainAll(list);
   }
}

return c;
}
{noformat}{quote}}}

 operators to manipulate j.u.Collection
 --

 Key: JEXL-151
 URL: https://issues.apache.org/jira/browse/JEXL-151
 Project: Commons JEXL
  Issue Type: New Feature
Affects Versions: 3.0
Reporter: Dmitri Blinov
Priority: Minor
 Fix For: Later


 New operators to add or remove collection items to/from Collection. Operators 
 can be named as += and -= respectively, or any other way. Operator += can be 
 mapped to Collection.addAll(Collection c) if right argument is Collection or 
 to Collection.add(Object o) otherwise. Operator -= can be mapped to 
 Collection.removeAll(Collection c) if right argument is Collection or to 
 Collection.remove(Object o) otherwise. Extend operators =~  (!~) to support 
 CollectionA =~ CollectionB usage, in which case it should map to 
 B.containsAll(A) operation.

[jira] [Comment Edited] (JEXL-151) operators to manipulate j.u.Collection

2015-07-21 Thread Dmitri Blinov (JIRA)

[ 
https://issues.apache.org/jira/browse/JEXL-151?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanelfocusedCommentId=14634769#comment-14634769
 ] 

Dmitri Blinov edited comment on JEXL-151 at 7/21/15 8:33 AM:
-

For now I have managed to overload operators + and - via JexlArithmetic to 
support manipulation of Collection items, it's odd-looking a bit, but works. 
Another case is =~ operator which is implemented inside Interpreter.java and 
since can not be overloaded, but as I see it requires only three lines of code 
to implement

// try contains on collection
if (right instanceof Collection?) {
   if (left instanceof Collection?) 
  return ((Collection?) right).containsAll((Collection?) 
left);
   else
   return ((Collection?) right).contains(left);
}

Can we include it in near future?



was (Author: dmitri_blinov):
For now I have managed to overload operators + and - via JexlArithmetic to 
support manipulation of Collection items, it's odd-looking a bit, but works. 
Another case is =~ operator which is implemented inside Interpreter.java and 
since can not be overloaded, but as I see it requires only three lines of code 
to implement

// try contains on collection
if (right instanceof Collection?) {
+   if (left instanceof Collection?) 
+  return ((Collection?) right).containsAll((Collection?) 
left);
+   else
   return ((Collection?) right).contains(left);
}

Can we include it in near future?


 operators to manipulate j.u.Collection
 --

 Key: JEXL-151
 URL: https://issues.apache.org/jira/browse/JEXL-151
 Project: Commons JEXL
  Issue Type: New Feature
Affects Versions: 3.0
Reporter: Dmitri Blinov
Priority: Minor
 Fix For: Later


 New operators to add or remove collection items to/from Collection. Operators 
 can be named as += and -= respectively, or any other way. Operator += can be 
 mapped to Collection.addAll(Collection c) if right argument is Collection or 
 to Collection.add(Object o) otherwise. Operator -= can be mapped to 
 Collection.removeAll(Collection c) if right argument is Collection or to 
 Collection.remove(Object o) otherwise. Extend operators =~  (!~) to support 
 CollectionA =~ CollectionB usage, in which case it should map to 
 B.containsAll(A) operation.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)