myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tandrasc...@apache.org
Subject [myfaces] branch master updated: refactored
Date Mon, 12 Aug 2019 16:02:26 GMT
This is an automated email from the ASF dual-hosted git repository.

tandraschko pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/myfaces.git


The following commit(s) were added to refs/heads/master by this push:
     new 401773c  refactored
401773c is described below

commit 401773c8fe497f148cec22f48b74208233bc852c
Author: Thomas Andraschko <tandraschko@apache.org>
AuthorDate: Mon Aug 12 18:02:19 2019 +0200

    refactored
---
 .../javax/faces/component/_DeltaStateHelper.java   | 32 ++++++---------------
 .../behavior/_AjaxBehaviorDeltaStateHelper.java    | 31 +++++---------------
 .../component/behavior/_DeltaStateHelper.java      | 32 ++++++---------------
 .../view/facelets/pool/impl/ViewPoolImpl.java      | 33 ++++++----------------
 .../view/facelets/tag/TagAttributesImpl.java       | 18 +++---------
 .../CreateDynamicCompositeComponentListener.java   |  1 -
 .../view/jsp/JspViewDeclarationLanguageBase.java   |  2 +-
 7 files changed, 36 insertions(+), 113 deletions(-)

diff --git a/api/src/main/java/javax/faces/component/_DeltaStateHelper.java b/api/src/main/java/javax/faces/component/_DeltaStateHelper.java
index e122629..0f4b627 100644
--- a/api/src/main/java/javax/faces/component/_DeltaStateHelper.java
+++ b/api/src/main/java/javax/faces/component/_DeltaStateHelper.java
@@ -303,22 +303,14 @@ class _DeltaStateHelper implements StateHelper, TransientStateHelper,
TransientS
         if (_createDeltas(key))
         {
             //Track delta case
-            Map<Object, Boolean> deltaListMapValues = (Map<Object, Boolean>)
_deltas.get(key);
-            if (deltaListMapValues == null)
-            {
-                deltaListMapValues = new InternalDeltaListMap<Object, Boolean>(3);
-                _deltas.put(key, deltaListMapValues);
-            }
+            Map<Object, Boolean> deltaListMapValues = (Map<Object, Boolean>)
_deltas.computeIfAbsent(key,
+                    k -> new InternalDeltaListMap<>(3));
             deltaListMapValues.put(value, Boolean.TRUE);
         }
 
         //Handle change on full map
-        List<Object> fullListValues = (List<Object>) _fullState.get(key);
-        if (fullListValues == null)
-        {
-            fullListValues = new InternalList<Object>(3);
-            _fullState.put(key, fullListValues);
-        }
+        List<Object> fullListValues = (List<Object>) _fullState.computeIfAbsent(key,
+                k -> new InternalList<>(3));
         fullListValues.add(value);
     }
 
@@ -396,12 +388,8 @@ class _DeltaStateHelper implements StateHelper, TransientStateHelper,
TransientS
         if (_createDeltas(key))
         {
             //Track delta case
-            Map<String, Object> mapValues = (Map<String, Object>) _deltas.get(key);
-            if (mapValues == null)
-            {
-                mapValues = new InternalMap<String, Object>();
-                _deltas.put(key, mapValues);
-            }
+            Map<String, Object> mapValues = (Map<String, Object>) _deltas.computeIfAbsent(key,
+                    k -> new InternalMap<>());
             if (mapValues.containsKey(mapKey))
             {
                 returnValue = mapValues.put(mapKey, value);
@@ -414,12 +402,8 @@ class _DeltaStateHelper implements StateHelper, TransientStateHelper,
TransientS
         }
 
         //Handle change on full map
-        Map<String, Object> mapValues = (Map<String, Object>) _fullState.get(key);
-        if (mapValues == null)
-        {
-            mapValues = new InternalMap<String, Object>();
-            _fullState.put(key, mapValues);
-        }
+        Map<String, Object> mapValues = (Map<String, Object>) _fullState.computeIfAbsent(key,
+                k -> new InternalMap<>());
         if (returnSet)
         {
             mapValues.put(mapKey, value);
diff --git a/api/src/main/java/javax/faces/component/behavior/_AjaxBehaviorDeltaStateHelper.java
b/api/src/main/java/javax/faces/component/behavior/_AjaxBehaviorDeltaStateHelper.java
index bacaab2..3a3be4f 100644
--- a/api/src/main/java/javax/faces/component/behavior/_AjaxBehaviorDeltaStateHelper.java
+++ b/api/src/main/java/javax/faces/component/behavior/_AjaxBehaviorDeltaStateHelper.java
@@ -101,22 +101,13 @@ class _AjaxBehaviorDeltaStateHelper<A extends AjaxBehavior> implements
StateHelp
         if (_createDeltas())
         {
             //Track delta case
-            Map<Object, Boolean> deltaListMapValues = (Map<Object, Boolean>)
_deltas.get(key);
-            if (deltaListMapValues == null)
-            {
-                deltaListMapValues = new InternalDeltaListMap<Object, Boolean>(3);
-                _deltas.put(key, deltaListMapValues);
-            }
+            Map<Object, Boolean> deltaListMapValues = (Map<Object, Boolean>)
_deltas.computeIfAbsent(key,
+                    k -> new InternalDeltaListMap<>(3));
             deltaListMapValues.put(value, Boolean.TRUE);
         }
 
         //Handle change on full map
-        List<Object> fullListValues = (List<Object>) _fullState.get(key);
-        if (fullListValues == null)
-        {
-            fullListValues = new InternalList<Object>(3);
-            _fullState.put(key, fullListValues);
-        }
+        List<Object> fullListValues = (List<Object>) _fullState.computeIfAbsent(key,
k -> new InternalList<>(3));
         fullListValues.add(value);
     }
 
@@ -190,12 +181,8 @@ class _AjaxBehaviorDeltaStateHelper<A extends AjaxBehavior> implements
StateHelp
         if (_createDeltas())
         {
             //Track delta case
-            Map<String, Object> mapValues = (Map<String, Object>) _deltas.get(key);
-            if (mapValues == null)
-            {
-                mapValues = new InternalMap<String, Object>();
-                _deltas.put(key, mapValues);
-            }
+            Map<String, Object> mapValues = (Map<String, Object>) _deltas.computeIfAbsent(key,
+                    k -> new InternalMap<>());
             if (mapValues.containsKey(mapKey))
             {
                 returnValue = mapValues.put(mapKey, value);
@@ -208,12 +195,8 @@ class _AjaxBehaviorDeltaStateHelper<A extends AjaxBehavior> implements
StateHelp
         }
 
         //Handle change on full map
-        Map<String, Object> mapValues = (Map<String, Object>) _fullState.get(key);
-        if (mapValues == null)
-        {
-            mapValues = new InternalMap<String, Object>();
-            _fullState.put(key, mapValues);
-        }
+        Map<String, Object> mapValues = (Map<String, Object>) _fullState.computeIfAbsent(key,
+                k -> new InternalMap<>());
         if (returnSet)
         {
             mapValues.put(mapKey, value);
diff --git a/api/src/main/java/javax/faces/component/behavior/_DeltaStateHelper.java b/api/src/main/java/javax/faces/component/behavior/_DeltaStateHelper.java
index 6a8895b..c2c7ee2 100644
--- a/api/src/main/java/javax/faces/component/behavior/_DeltaStateHelper.java
+++ b/api/src/main/java/javax/faces/component/behavior/_DeltaStateHelper.java
@@ -195,22 +195,14 @@ class _DeltaStateHelper <A extends AjaxBehavior> implements StateHelper
         if (_createDeltas())
         {
             //Track delta case
-            Map<Object, Boolean> deltaListMapValues = (Map<Object, Boolean>)
_deltas.get(key);
-            if (deltaListMapValues == null)
-            {
-                deltaListMapValues = new InternalDeltaListMap<Object, Boolean>(3);
-                _deltas.put(key, deltaListMapValues);
-            }
+            Map<Object, Boolean> deltaListMapValues = (Map<Object, Boolean>)
_deltas.computeIfAbsent(key,
+                    k -> new InternalDeltaListMap<>(3));
             deltaListMapValues.put(value, Boolean.TRUE);
         }
 
         //Handle change on full map
-        List<Object> fullListValues = (List<Object>) _fullState.get(key);
-        if (fullListValues == null)
-        {
-            fullListValues = new InternalList<Object>(3);
-            _fullState.put(key, fullListValues);
-        }
+        List<Object> fullListValues = (List<Object>) _fullState.computeIfAbsent(key,
+                k -> new InternalList<>(3));
         fullListValues.add(value);
     }
 
@@ -287,12 +279,8 @@ class _DeltaStateHelper <A extends AjaxBehavior> implements StateHelper
         if (_createDeltas())
         {
             //Track delta case
-            Map<String, Object> mapValues = (Map<String, Object>) _deltas.get(key);
-            if (mapValues == null)
-            {
-                mapValues = new InternalMap<String, Object>();
-                _deltas.put(key, mapValues);
-            }
+            Map<String, Object> mapValues = (Map<String, Object>) _deltas.computeIfAbsent(key,
+                    k -> new InternalMap<>());
             if (mapValues.containsKey(mapKey))
             {
                 returnValue = mapValues.put(mapKey, value);
@@ -305,12 +293,8 @@ class _DeltaStateHelper <A extends AjaxBehavior> implements StateHelper
         }
 
         //Handle change on full map
-        Map<String, Object> mapValues = (Map<String, Object>) _fullState.get(key);
-        if (mapValues == null)
-        {
-            mapValues = new InternalMap<String, Object>();
-            _fullState.put(key, mapValues);
-        }
+        Map<String, Object> mapValues = (Map<String, Object>) _fullState.computeIfAbsent(key,
+                k -> new InternalMap<>());
         if (returnSet)
         {
             mapValues.put(mapKey, value);
diff --git a/impl/src/main/java/org/apache/myfaces/view/facelets/pool/impl/ViewPoolImpl.java
b/impl/src/main/java/org/apache/myfaces/view/facelets/pool/impl/ViewPoolImpl.java
index 71b48be..9f34202 100644
--- a/impl/src/main/java/org/apache/myfaces/view/facelets/pool/impl/ViewPoolImpl.java
+++ b/impl/src/main/java/org/apache/myfaces/view/facelets/pool/impl/ViewPoolImpl.java
@@ -93,12 +93,7 @@ public class ViewPoolImpl extends ViewPool
     
     protected void pushStaticStructureView(FacesContext context, MetadataViewKey key, ViewEntry
entry)
     {
-        ViewPoolEntryHolder q = staticStructureViewPool.get(key);
-        if (q == null)
-        {
-            q = new ViewPoolEntryHolder(maxCount);
-            staticStructureViewPool.put(key, q);
-        }
+        ViewPoolEntryHolder q = staticStructureViewPool.computeIfAbsent(key, k -> new
ViewPoolEntryHolder(maxCount));
         q.add(entry);
     }
     
@@ -109,6 +104,7 @@ public class ViewPoolImpl extends ViewPool
         {
             return null;
         }
+
         ViewEntry entry = q.poll();
         if (entry == null)
         {
@@ -203,19 +199,10 @@ public class ViewPoolImpl extends ViewPool
     protected void pushDynamicStructureView(FacesContext context, UIViewRoot root, DynamicViewKey
key, ViewEntry entry)
     {
         MetadataViewKey ordinaryKey = deriveViewKey(context, root);
-        Map<DynamicViewKey, ViewPoolEntryHolder> map = dynamicStructureViewPool.get(ordinaryKey);
-        if (map == null)
-        {
-            map = new ConcurrentHashMap<>();
-            dynamicStructureViewPool.put(ordinaryKey, map);
-        }
+        Map<DynamicViewKey, ViewPoolEntryHolder> map = dynamicStructureViewPool.computeIfAbsent(ordinaryKey,
+                k -> new ConcurrentHashMap<>());
 
-        ViewPoolEntryHolder q = map.get(key);
-        if (q == null)
-        {
-            q = new ViewPoolEntryHolder(maxCount);
-            map.put(key, q);
-        }
+        ViewPoolEntryHolder q = map.computeIfAbsent(key, k -> new ViewPoolEntryHolder(maxCount));
         if (!q.add(entry))
         {
             pushPartialStructureView(context, ordinaryKey, entry);
@@ -422,13 +409,9 @@ public class ViewPoolImpl extends ViewPool
         MetadataViewKey ordinaryKey = deriveViewKey(context, root);
         if (!dynamicStructureViewMetadataMap.containsKey(ordinaryKey))
         {
-            
-            Map<DynamicViewKey, ViewStructureMetadata> map = dynamicStructureViewMetadataMap.get(ordinaryKey);
-            if (map == null)
-            {
-                map = new ConcurrentHashMap<>();
-                dynamicStructureViewMetadataMap.put(ordinaryKey, map);
-            }
+            Map<DynamicViewKey, ViewStructureMetadata> map = dynamicStructureViewMetadataMap.computeIfAbsent(
+                    ordinaryKey, k -> new ConcurrentHashMap<>());
+
             RequestViewContext rvc = RequestViewContext.getCurrentInstance(context);
             
             Object state = saveViewRootState(context, root);
diff --git a/impl/src/main/java/org/apache/myfaces/view/facelets/tag/TagAttributesImpl.java
b/impl/src/main/java/org/apache/myfaces/view/facelets/tag/TagAttributesImpl.java
index a6bcc9d..cd03670 100644
--- a/impl/src/main/java/org/apache/myfaces/view/facelets/tag/TagAttributesImpl.java
+++ b/impl/src/main/java/org/apache/myfaces/view/facelets/tag/TagAttributesImpl.java
@@ -59,22 +59,12 @@ public final class TagAttributesImpl extends TagAttributes
         {
             namespacesSet.add(attribute.getNamespace());
 
-            
-            List<TagAttribute> tagAttributes = namespaceAttributesAsList.get(attribute.getNamespace());
-            if (tagAttributes == null)
-            {
-                tagAttributes = new ArrayList<>(attributes.length);
-                namespaceAttributesAsList.put(attribute.getNamespace(), tagAttributes);
-            }
+            List<TagAttribute> tagAttributes = namespaceAttributesAsList.computeIfAbsent(attribute.getNamespace(),
+                    k -> new ArrayList<>(attributes.length));
             tagAttributes.add(attribute);
             
-            
-            Map<String, TagAttribute> localeNameAttributes = namespaceLocalNameAttributes.get(attribute.getNamespace());
-            if (localeNameAttributes == null)
-            {
-                localeNameAttributes = new HashMap<>(attributes.length);
-                namespaceLocalNameAttributes.put(attribute.getNamespace(), localeNameAttributes);
-            }
+            Map<String, TagAttribute> localeNameAttributes = namespaceLocalNameAttributes.computeIfAbsent(
+                    attribute.getNamespace(), k -> new HashMap<>(attributes.length));
             localeNameAttributes.put(attribute.getLocalName(), attribute);
         }
 
diff --git a/impl/src/main/java/org/apache/myfaces/view/facelets/tag/composite/CreateDynamicCompositeComponentListener.java
b/impl/src/main/java/org/apache/myfaces/view/facelets/tag/composite/CreateDynamicCompositeComponentListener.java
index 1a7fb94..a599d69 100644
--- a/impl/src/main/java/org/apache/myfaces/view/facelets/tag/composite/CreateDynamicCompositeComponentListener.java
+++ b/impl/src/main/java/org/apache/myfaces/view/facelets/tag/composite/CreateDynamicCompositeComponentListener.java
@@ -119,7 +119,6 @@ public class CreateDynamicCompositeComponentListener
                 facetName = ComponentSupport.findFacetNameByComponentInstance(parent, component);
             }
             
-            
             try
             {
                 if (facetName != null)
diff --git a/impl/src/main/java/org/apache/myfaces/view/jsp/JspViewDeclarationLanguageBase.java
b/impl/src/main/java/org/apache/myfaces/view/jsp/JspViewDeclarationLanguageBase.java
index 96cbc80..2631887 100644
--- a/impl/src/main/java/org/apache/myfaces/view/jsp/JspViewDeclarationLanguageBase.java
+++ b/impl/src/main/java/org/apache/myfaces/view/jsp/JspViewDeclarationLanguageBase.java
@@ -157,7 +157,7 @@ public abstract class JspViewDeclarationLanguageBase extends ViewDeclarationLang
         // handle character encoding as of section 2.5.2.2 of JSF 1.1
         if(null != externalContext.getSession(false))
         {
-          externalContext.getSessionMap().put(ViewHandler.CHARACTER_ENCODING_KEY, 
+            externalContext.getSessionMap().put(ViewHandler.CHARACTER_ENCODING_KEY, 
                   externalContext.getResponseCharacterEncoding());
         }
 


Mime
View raw message