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 Thu, 07 Mar 2019 11:06:15 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 9d77186  refactored
9d77186 is described below

commit 9d7718632cbb6067725fa70bbd804c4d6a0b08fc
Author: Thomas Andraschko <tandraschko@apache.org>
AuthorDate: Thu Mar 7 12:06:10 2019 +0100

    refactored
---
 .../apache/myfaces/util/AbstractAttributeMap.java  | 16 +++----
 .../util/AbstractThreadSafeAttributeMap.java       | 15 ++++--
 .../org/apache/myfaces/util/ArrayIterator.java     | 54 ++++++++++++++++++++++
 .../facelets/tag/jstl/core/ForEachHandler.java     | 34 +-------------
 .../tag/jstl/core/LegacyForEachHandler.java        | 35 +-------------
 5 files changed, 73 insertions(+), 81 deletions(-)

diff --git a/impl/src/main/java/org/apache/myfaces/util/AbstractAttributeMap.java b/impl/src/main/java/org/apache/myfaces/util/AbstractAttributeMap.java
index a2ad9a2..ab42857 100644
--- a/impl/src/main/java/org/apache/myfaces/util/AbstractAttributeMap.java
+++ b/impl/src/main/java/org/apache/myfaces/util/AbstractAttributeMap.java
@@ -22,9 +22,9 @@ import java.util.AbstractMap;
 import java.util.AbstractSet;
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.Collections;
 import java.util.Enumeration;
 import java.util.Iterator;
-import java.util.List;
 import java.util.Map;
 import java.util.NoSuchElementException;
 import java.util.Set;
@@ -44,15 +44,10 @@ public abstract class AbstractAttributeMap<V> extends AbstractMap<String,
V>
     @Override
     public void clear()
     {
-        final List<String> names = new ArrayList<String>();
-        for (final Enumeration<String> e = getAttributeNames(); e.hasMoreElements();)
-        {
-            names.add(e.nextElement());
-        }
-
-        for (String name : names)
+        final ArrayList<String> names = Collections.list(getAttributeNames());
+        for (int i = 0; i < names.size(); i++)
         {
-            removeAttribute(name);
+            removeAttribute(names.get(i));
         }
     }
 
@@ -218,6 +213,7 @@ public abstract class AbstractAttributeMap<V> extends AbstractMap<String,
V>
         protected final Enumeration<String> _e = getAttributeNames();
         protected String _currentKey;
 
+        @Override
         public void remove()
         {
             // remove() may cause ConcurrentModificationException.
@@ -230,11 +226,13 @@ public abstract class AbstractAttributeMap<V> extends AbstractMap<String,
V>
             AbstractAttributeMap.this.remove(_currentKey);
         }
 
+        @Override
         public boolean hasNext()
         {
             return _e.hasMoreElements();
         }
 
+        @Override
         public E next()
         {
             _currentKey = _e.nextElement();
diff --git a/impl/src/main/java/org/apache/myfaces/util/AbstractThreadSafeAttributeMap.java
b/impl/src/main/java/org/apache/myfaces/util/AbstractThreadSafeAttributeMap.java
index 6ef03c4..a7f41b0 100755
--- a/impl/src/main/java/org/apache/myfaces/util/AbstractThreadSafeAttributeMap.java
+++ b/impl/src/main/java/org/apache/myfaces/util/AbstractThreadSafeAttributeMap.java
@@ -20,11 +20,11 @@ package org.apache.myfaces.util;
 
 import java.util.AbstractMap;
 import java.util.AbstractSet;
+import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.Enumeration;
 import java.util.Iterator;
-import java.util.List;
 import java.util.Map;
 import java.util.NoSuchElementException;
 import java.util.Set;
@@ -44,11 +44,10 @@ public abstract class AbstractThreadSafeAttributeMap<V> extends
AbstractMap<Stri
     @Override
     public void clear()
     {
-        final List<String> names = Collections.list(getAttributeNames());
-
-        for (String name : names)
+        final ArrayList<String> names = Collections.list(getAttributeNames());
+        for (int i = 0; i < names.size(); i++)
         {
-            removeAttribute(name);
+            removeAttribute(names.get(i));
         }
     }
 
@@ -208,6 +207,7 @@ public abstract class AbstractThreadSafeAttributeMap<V> extends
AbstractMap<Stri
         protected final Iterator<String> _i = Collections.list(getAttributeNames()).iterator();
         protected String _currentKey;
 
+        @Override
         public void remove()
         {
             if (_currentKey == null)
@@ -217,11 +217,13 @@ public abstract class AbstractThreadSafeAttributeMap<V> extends
AbstractMap<Stri
             AbstractThreadSafeAttributeMap.this.remove(_currentKey);
         }
 
+        @Override
         public boolean hasNext()
         {
             return _i.hasNext();
         }
 
+        @Override
         public E next()
         {
             _currentKey = _i.next();
@@ -370,16 +372,19 @@ public abstract class AbstractThreadSafeAttributeMap<V> extends
AbstractMap<Stri
             _currentKey = currentKey;
         }
 
+        @Override
         public String getKey()
         {
             return _currentKey;
         }
 
+        @Override
         public V getValue()
         {
             return AbstractThreadSafeAttributeMap.this.get(_currentKey);
         }
 
+        @Override
         public V setValue(final V value)
         {
             return AbstractThreadSafeAttributeMap.this.put(_currentKey, value);
diff --git a/impl/src/main/java/org/apache/myfaces/util/ArrayIterator.java b/impl/src/main/java/org/apache/myfaces/util/ArrayIterator.java
new file mode 100644
index 0000000..7fb2428
--- /dev/null
+++ b/impl/src/main/java/org/apache/myfaces/util/ArrayIterator.java
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.util;
+
+import java.lang.reflect.Array;
+import java.util.Iterator;
+
+public class ArrayIterator implements Iterator<Object>
+{
+    protected final Object array;
+    protected int i;
+    protected final int len;
+
+    public ArrayIterator(Object src)
+    {
+        this.i = 0;
+        this.array = src;
+        this.len = Array.getLength(src);
+    }
+
+    @Override
+    public boolean hasNext()
+    {
+        return this.i < this.len;
+    }
+
+    @Override
+    public Object next()
+    {
+        return Array.get(this.array, this.i++);
+    }
+
+    @Override
+    public void remove()
+    {
+        throw new UnsupportedOperationException();
+    }
+}
diff --git a/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jstl/core/ForEachHandler.java
b/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jstl/core/ForEachHandler.java
index e002783..6072812 100644
--- a/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jstl/core/ForEachHandler.java
+++ b/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jstl/core/ForEachHandler.java
@@ -20,7 +20,6 @@ package org.apache.myfaces.view.facelets.tag.jstl.core;
 
 import java.io.IOException;
 import java.io.Serializable;
-import java.lang.reflect.Array;
 import java.util.Collection;
 import java.util.Iterator;
 import java.util.List;
@@ -41,6 +40,7 @@ import javax.faces.view.facelets.TagHandler;
 
 import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFFaceletAttribute;
 import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFFaceletTag;
+import org.apache.myfaces.util.ArrayIterator;
 import org.apache.myfaces.view.facelets.AbstractFaceletContext;
 import org.apache.myfaces.view.facelets.FaceletCompositionContext;
 import org.apache.myfaces.view.facelets.PageContext;
@@ -62,38 +62,6 @@ import org.apache.myfaces.view.facelets.tag.jsf.FaceletState;
 public final class ForEachHandler extends TagHandler implements ComponentContainerHandler
 {
 
-    private static class ArrayIterator implements Iterator<Object>
-    {
-        protected final Object array;
-        protected int i;
-        protected final int len;
-
-        public ArrayIterator(Object src)
-        {
-            this.i = 0;
-            this.array = src;
-            this.len = Array.getLength(src);
-        }
-
-        @Override
-        public boolean hasNext()
-        {
-            return this.i < this.len;
-        }
-
-        @Override
-        public Object next()
-        {
-            return Array.get(this.array, this.i++);
-        }
-
-        @Override
-        public void remove()
-        {
-            throw new UnsupportedOperationException();
-        }
-    }
-
     /**
      * If items specified:
      * Iteration begins at the item located at the
diff --git a/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jstl/core/LegacyForEachHandler.java
b/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jstl/core/LegacyForEachHandler.java
index a360f69..c66141c 100644
--- a/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jstl/core/LegacyForEachHandler.java
+++ b/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jstl/core/LegacyForEachHandler.java
@@ -19,7 +19,6 @@
 package org.apache.myfaces.view.facelets.tag.jstl.core;
 
 import java.io.IOException;
-import java.lang.reflect.Array;
 import java.util.Collection;
 import java.util.Iterator;
 import java.util.List;
@@ -35,6 +34,7 @@ import javax.faces.view.facelets.TagAttribute;
 import javax.faces.view.facelets.TagAttributeException;
 import javax.faces.view.facelets.TagConfig;
 import javax.faces.view.facelets.TagHandler;
+import org.apache.myfaces.util.ArrayIterator;
 
 import org.apache.myfaces.view.facelets.AbstractFaceletContext;
 import org.apache.myfaces.view.facelets.FaceletCompositionContext;
@@ -59,39 +59,6 @@ import org.apache.myfaces.view.facelets.tag.jsf.ComponentSupport;
 //@JSFFaceletTag(name="c:forEach")
 public final class LegacyForEachHandler extends TagHandler implements ComponentContainerHandler
 {
-
-    private static class ArrayIterator implements Iterator<Object>
-    {
-        protected final Object array;
-        protected int i;
-        protected final int len;
-
-        public ArrayIterator(Object src)
-        {
-            this.i = 0;
-            this.array = src;
-            this.len = Array.getLength(src);
-        }
-
-        @Override
-        public boolean hasNext()
-        {
-            return this.i < this.len;
-        }
-
-        @Override
-        public Object next()
-        {
-            return Array.get(this.array, this.i++);
-        }
-
-        @Override
-        public void remove()
-        {
-            throw new UnsupportedOperationException();
-        }
-    }
-
     /**
      * If items specified:
      * Iteration begins at the item located at the


Mime
View raw message