Skip to main content

[el-spec commits] [el-spec~source-code:47] Implementation of Grouping cannot implements List, as it would trigger

  • From: kchung@...
  • To: commits@...
  • Subject: [el-spec commits] [el-spec~source-code:47] Implementation of Grouping cannot implements List, as it would trigger
  • Date: Thu, 2 Feb 2012 20:53:32 +0000

Project:    el-spec
Repository: source-code
Revision:   47
Author:     kchung
Date:       2012-02-02 20:53:30 UTC
Link:       

Log Message:
------------
Implementation of Grouping cannot implements List, as it would trigger
ListELResolver when getting the key property from Grouping.



Revisions:
----------
47


Modified Paths:
---------------
trunk/impl/src/main/java/com/sun/el/query/GroupBy.java


Added Paths:
------------
trunk/impl/src/main/java/com/sun/el/query/GroupingImpl.java


Diffs:
------
Index: trunk/impl/src/main/java/com/sun/el/query/ArrayListGrouping.java
===================================================================
--- trunk/impl/src/main/java/com/sun/el/query/ArrayListGrouping.java    
(revision 46)
+++ trunk/impl/src/main/java/com/sun/el/query/ArrayListGrouping.java    
(revision 47)
@@ -1,37 +0,0 @@
-package com.sun.el.query;
-
-/**
- * Implements javax.el.Grouping
- */
-
-import java.util.ArrayList;
-import javax.el.Grouping;
-
-public class ArrayListGrouping<K, T> extends ArrayList<T>
-                                     implements Grouping<K, T>{
-
-    private K key;
-
-    /**
-     * Constructor
-     * @param key The common key for the collection.
-     */
-    public ArrayListGrouping(K key) {
-        this.key = key;
-    }
-
-    /**
-     * Return the key for the collection
-     * @return The key for the collection.
-     */
-    @Override
-    public K getKey() {
-        return key;
-    }
-
-    @Override
-    public String toString() {
-        return key.toString() + ": " + super.toString();
-    }
-}
-
Index: trunk/impl/src/main/java/com/sun/el/query/GroupingImpl.java
===================================================================
--- trunk/impl/src/main/java/com/sun/el/query/GroupingImpl.java (revision 0)
+++ trunk/impl/src/main/java/com/sun/el/query/GroupingImpl.java (revision 47)
@@ -0,0 +1,50 @@
+package com.sun.el.query;
+
+/**
+ * Implements javax.el.Grouping
+ * We don't extend ArrayList to avoid triggering the ListELResolver when
+ * access the 'key' property.
+ */
+
+import java.util.Iterator;
+import java.util.ArrayList;
+import javax.el.Grouping;
+
+public class GroupingImpl<K, T> implements Grouping<K, T>{
+
+    private K key;
+    private ArrayList<T> group;
+
+    /**
+     * Constructor
+     * @param key The common key for the collection.
+     */
+    public GroupingImpl(K key) {
+        this.group = new ArrayList<T>();
+        this.key = key;
+    }
+
+    public void add(T item) {
+        group.add(item);
+    }
+
+    @Override
+    public Iterator<T> iterator() {
+        return group.iterator();
+    }
+
+    /**
+     * Return the key for the collection
+     * @return The key for the collection.
+     */
+    @Override
+    public K getKey() {
+        return key;
+    }
+
+    @Override
+    public String toString() {
+        return key.toString() + ": " + group.toString();
+    }
+}
+
Index: trunk/impl/src/main/java/com/sun/el/query/GroupBy.java
===================================================================
--- trunk/impl/src/main/java/com/sun/el/query/GroupBy.java      (revision 46)
+++ trunk/impl/src/main/java/com/sun/el/query/GroupBy.java      (revision 47)
@@ -10,7 +10,7 @@
 
 class GroupBy extends QueryOperator {
     @Override
-    public Iterable<ArrayListGrouping<Object,Object>> invoke(
+    public Iterable<GroupingImpl<Object,Object>> invoke(
                                    final ELContext context,
                                    final Iterable<Object> base,
                                    final Object[] params) {
@@ -23,8 +23,8 @@
         }
         final Comparator cmp = getComparator("groupBy", params, indexC, 
true);
 
-        List<ArrayListGrouping<Object,Object>> groups =
-                    new ArrayList<ArrayListGrouping<Object,Object>>();
+        List<GroupingImpl<Object,Object>> groups =
+                    new ArrayList<GroupingImpl<Object,Object>>();
 
         for (Object element: base) {
             Object key = keySelector.invoke(context, element);
@@ -37,19 +37,18 @@
         return groups;
     }
 
-    private void addToGroup(List<ArrayListGrouping<Object,Object>> groups,
+    private void addToGroup(List<GroupingImpl<Object,Object>> groups,
                             Object key, Object value) {
         if (key == null || value == null) {
             return;
         }
-        for (ArrayListGrouping<Object, Object> group: groups) {
+        for (GroupingImpl<Object, Object> group: groups) {
             if (key.equals(group.getKey())) {
                 group.add(value);
                 return;
             }
         }
-        ArrayListGrouping<Object, Object> g =
-            new ArrayListGrouping<Object,Object>(key);
+        GroupingImpl<Object, Object> g = new 
GroupingImpl<Object,Object>(key);
         g.add(value);
         groups.add(g);
         return;





[el-spec commits] [el-spec~source-code:47] Implementation of Grouping cannot implements List, as it would trigger

kchung 02/02/2012
 
 
Close
loading
Please Confirm
Close