You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by ma...@apache.org on 2009/06/16 20:04:44 UTC

svn commit: r785330 - /myfaces/trinidad/trunk/trinidad-api/src/main/java/org/apache/myfaces/trinidad/bean/FacesBean.java

Author: matzew
Date: Tue Jun 16 18:04:44 2009
New Revision: 785330

URL: http://svn.apache.org/viewvc?rev=785330&view=rev
Log:
TRINIDAD-1510 - add propertyKeys() to FacesBean.TYPE and make the data strucutures final

making _superTyp,  _keyMap, _keyList and the new _unmodifiableKeys FINAL, therefore getting 
rid of _init();
added propertyKey() and fix the  keys() to return the iterator of the newly added propertyKeys()
(as this Iterator is not modifiable...)

Modified:
    myfaces/trinidad/trunk/trinidad-api/src/main/java/org/apache/myfaces/trinidad/bean/FacesBean.java

Modified: myfaces/trinidad/trunk/trinidad-api/src/main/java/org/apache/myfaces/trinidad/bean/FacesBean.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-api/src/main/java/org/apache/myfaces/trinidad/bean/FacesBean.java?rev=785330&r1=785329&r2=785330&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-api/src/main/java/org/apache/myfaces/trinidad/bean/FacesBean.java (original)
+++ myfaces/trinidad/trunk/trinidad-api/src/main/java/org/apache/myfaces/trinidad/bean/FacesBean.java Tue Jun 16 18:04:44 2009
@@ -19,8 +19,11 @@
 package org.apache.myfaces.trinidad.bean;
 
 import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.Iterator;
+import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
@@ -222,7 +225,21 @@
     public Type(Type superType)
     {
       _superType = superType;
-      _init();
+      // todo initial size of map, and type of map
+      // todo initial size of list, and type of list
+      // todo build combined data structure
+      _keyMap = new HashMap<String, PropertyKey>();
+      _keyList = new ArrayList<PropertyKey>();
+      _unmodifiableKeys = Collections.unmodifiableList(_keyList);
+
+      if (_superType != null)
+      {
+        _keyMap.putAll(_superType._keyMap);
+        _keyList.addAll(_superType._keyList);
+        _index = _superType._index;
+        _superType.lock();
+      }
+
     }
 
     /**
@@ -375,7 +392,18 @@
      */
     public Iterator<PropertyKey> keys()
     {
-      return _keyList.iterator();
+      return propertyKeys().iterator();
+    }
+    
+    /**
+     * Returns an unmodifiable <code>Collection</code> of registered property keys,
+     * excluding aliases.
+     * 
+     * @return unmodifiable <code>Collection</code> with registered 
+     */
+    public Collection<PropertyKey> propertyKeys()
+    {
+      return _unmodifiableKeys;
     }
 
     protected PropertyKey createPropertyKey(
@@ -441,7 +469,7 @@
     }
      
     
-    static private void _expandListToIndex(ArrayList<?> list, int count)
+    static private void _expandListToIndex(ArrayList<PropertyKey> list, int count)
     {
       list.ensureCapacity(count + 1);
       int addCount = (count + 1) - list.size();
@@ -449,24 +477,6 @@
         list.add(null);
     }
 
-    /**
-     * @todo initial size of map, and type of map
-     * @todo initial size of list, and type of list
-     * @todo build combined data structure
-     */
-    private void _init()
-    {
-      _keyMap = new HashMap<String, PropertyKey>();
-      _keyList = new ArrayList<PropertyKey>();
-
-      if (_superType != null)
-      {
-        _keyMap.putAll(_superType._keyMap);
-        _keyList.addAll(_superType._keyList);
-        _index = _superType._index;
-        _superType.lock();
-      }
-    }
 
     private void _checkLocked()
     {
@@ -484,11 +494,13 @@
       }
     }
 
-    private Map<String, PropertyKey> _keyMap;
-    private ArrayList<PropertyKey>   _keyList;
+    private final Map<String, PropertyKey> _keyMap;
+    private final List<PropertyKey> _unmodifiableKeys;
+    // keyList is used for optimized operations, like findKey(index)
+    private final ArrayList<PropertyKey>   _keyList;
     private boolean   _isLocked;
     private int       _index;
-    private Type      _superType;
+    private final Type _superType;
     static private final TrinidadLogger _LOG = TrinidadLogger.createTrinidadLogger(Type.class); 
   }
 }