You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by mg...@apache.org on 2018/11/11 20:14:25 UTC

wicket git commit: Deprecate ArrayListStack in favour of ArrayDeque

Repository: wicket
Updated Branches:
  refs/heads/master ba98e8800 -> 7cfa536d6


Deprecate ArrayListStack in favour of ArrayDeque

Also remove HandleArrayListStack, as it was package-private, and never used.


Project: http://git-wip-us.apache.org/repos/asf/wicket/repo
Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/7cfa536d
Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/7cfa536d
Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/7cfa536d

Branch: refs/heads/master
Commit: 7cfa536d687a181d73bc2e38d1e7ffc3e0032f0e
Parents: ba98e88
Author: Jezza <je...@gmail.com>
Authored: Thu Feb 15 23:43:06 2018 +0100
Committer: Martin Tzvetanov Grigorov <mg...@apache.org>
Committed: Sun Nov 11 22:08:37 2018 +0200

----------------------------------------------------------------------
 .../java/org/apache/wicket/DequeueContext.java  |  26 +--
 .../apache/wicket/markup/parser/TagStack.java   |  12 +-
 .../markup/parser/filter/HtmlHandler.java       |   4 +-
 .../parser/filter/WicketLinkTagHandler.java     |   6 +-
 .../wicket/extensions/wizard/WizardModel.java   |   4 +-
 .../wicket/util/collections/ArrayListStack.java |   2 +
 .../wicket/util/io/HandleArrayListStack.java    | 197 -------------------
 7 files changed, 29 insertions(+), 222 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/wicket/blob/7cfa536d/wicket-core/src/main/java/org/apache/wicket/DequeueContext.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/DequeueContext.java b/wicket-core/src/main/java/org/apache/wicket/DequeueContext.java
index 92c66f9..9c431e9 100644
--- a/wicket-core/src/main/java/org/apache/wicket/DequeueContext.java
+++ b/wicket-core/src/main/java/org/apache/wicket/DequeueContext.java
@@ -16,10 +16,11 @@
  */
 package org.apache.wicket;
 
+import java.util.ArrayDeque;
+
 import org.apache.wicket.markup.ComponentTag;
 import org.apache.wicket.markup.IMarkupFragment;
 import org.apache.wicket.markup.MarkupElement;
-import org.apache.wicket.util.collections.ArrayListStack;
 
 /**
  * Context for component dequeueing. Keeps track of markup position and container stack.
@@ -32,34 +33,34 @@ public final class DequeueContext
 	private final IMarkupFragment markup;
 	private int index;
 	private ComponentTag next;
-	private ArrayListStack<ComponentTag> tags = new ArrayListStack<>();
+	private ArrayDeque<ComponentTag> tags = new ArrayDeque<>();
 	private final boolean skipFirst;
 	private ComponentTag first;
 
-	private ArrayListStack<MarkupContainer> containers = new ArrayListStack<>();
+	private ArrayDeque<MarkupContainer> containers = new ArrayDeque<>();
 
 	/** A bookmark for the DequeueContext stack */
 	public static final class Bookmark
 	{
 		private final int index;
 		private final ComponentTag next;
-		private final ArrayListStack<ComponentTag> tags;
-		private final ArrayListStack<MarkupContainer> containers;
+		private final ArrayDeque<ComponentTag> tags;
+		private final ArrayDeque<MarkupContainer> containers;
 
 		private Bookmark(DequeueContext parser)
 		{
 			this.index = parser.index;
 			this.next = parser.next;
-			this.tags = new ArrayListStack<>(parser.tags);
-			this.containers = new ArrayListStack<>(parser.containers);
+			this.tags = new ArrayDeque<>(parser.tags);
+			this.containers = new ArrayDeque<>(parser.containers);
 		}
 
 		private void restore(DequeueContext parser)
 		{
 			parser.index = index;
 			parser.next = next;
-			parser.tags = new ArrayListStack<>(tags);
-			parser.containers = new ArrayListStack<>(containers);
+			parser.tags = new ArrayDeque<>(tags);
+			parser.containers = new ArrayDeque<>(containers);
 		}
 	}
 
@@ -226,9 +227,9 @@ public final class DequeueContext
 		}
 
 		DequeueTagAction action;
-		for (int i = containers.size() - 1; i >= 0; i--)
+		for (MarkupContainer container : containers)
 		{
-			action = containers.get(i).canDequeueTag((open));
+			action = container.canDequeueTag(open);
 			if (action != null)
 			{
 				return action;
@@ -286,9 +287,8 @@ public final class DequeueContext
 	 */
 	public Component findComponentToDequeue(ComponentTag tag)
 	{
-		for (int j = containers.size() - 1; j >= 0; j--)
+		for (MarkupContainer container : containers)
 		{
-			MarkupContainer container = containers.get(j);
 			Component child = container.findComponentToDequeue(tag);
 			if (child != null)
 			{

http://git-wip-us.apache.org/repos/asf/wicket/blob/7cfa536d/wicket-core/src/main/java/org/apache/wicket/markup/parser/TagStack.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/markup/parser/TagStack.java b/wicket-core/src/main/java/org/apache/wicket/markup/parser/TagStack.java
index 12f9b48..2f4ccb6 100644
--- a/wicket-core/src/main/java/org/apache/wicket/markup/parser/TagStack.java
+++ b/wicket-core/src/main/java/org/apache/wicket/markup/parser/TagStack.java
@@ -17,13 +17,14 @@
 package org.apache.wicket.markup.parser;
 
 import java.text.ParseException;
+import java.util.ArrayDeque;
 import java.util.HashMap;
+import java.util.Iterator;
 import java.util.Map;
 
 import org.apache.wicket.markup.ComponentTag;
 import org.apache.wicket.markup.WicketParseException;
 import org.apache.wicket.markup.parser.filter.HtmlHandler;
-import org.apache.wicket.util.collections.ArrayListStack;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -50,7 +51,7 @@ public class TagStack
 	}
 
 	/** Tag stack to find balancing tags */
-	final private ArrayListStack<ComponentTag> stack = new ArrayListStack<ComponentTag>();
+	final private ArrayDeque<ComponentTag> stack = new ArrayDeque<ComponentTag>();
 	private boolean debug;
 
 	/**
@@ -166,12 +167,13 @@ public class TagStack
 		// If there's still a non-simple tag left, it's an error
 		if (stack.size() > 0)
 		{
-			for (int i = 0; i < stack.size(); i++)
+			Iterator<ComponentTag> it = stack.descendingIterator();
+			while (it.hasNext())
 			{
-				ComponentTag tag = stack.get(i);
+				ComponentTag tag = it.next();
 				if (!requiresCloseTag(tag.getName()))
 				{
-					stack.pop();
+					it.remove();
 				}
 				else
 				{

http://git-wip-us.apache.org/repos/asf/wicket/blob/7cfa536d/wicket-core/src/main/java/org/apache/wicket/markup/parser/filter/HtmlHandler.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/markup/parser/filter/HtmlHandler.java b/wicket-core/src/main/java/org/apache/wicket/markup/parser/filter/HtmlHandler.java
index c5c6f89..8b95d73 100644
--- a/wicket-core/src/main/java/org/apache/wicket/markup/parser/filter/HtmlHandler.java
+++ b/wicket-core/src/main/java/org/apache/wicket/markup/parser/filter/HtmlHandler.java
@@ -17,6 +17,7 @@
 package org.apache.wicket.markup.parser.filter;
 
 import java.text.ParseException;
+import java.util.ArrayDeque;
 import java.util.HashMap;
 import java.util.Map;
 
@@ -26,7 +27,6 @@ import org.apache.wicket.markup.MarkupElement;
 import org.apache.wicket.markup.MarkupException;
 import org.apache.wicket.markup.WicketParseException;
 import org.apache.wicket.markup.parser.AbstractMarkupFilter;
-import org.apache.wicket.util.collections.ArrayListStack;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -43,7 +43,7 @@ public final class HtmlHandler extends AbstractMarkupFilter
 	private static final Logger log = LoggerFactory.getLogger(HtmlHandler.class);
 
 	/** Tag stack to find balancing tags */
-	final private ArrayListStack<ComponentTag> stack = new ArrayListStack<ComponentTag>();
+	final private ArrayDeque<ComponentTag> stack = new ArrayDeque<ComponentTag>();
 
 	/** Map of simple tags. */
 	private static final Map<String, Boolean> doesNotRequireCloseTag = new HashMap<String, Boolean>();

http://git-wip-us.apache.org/repos/asf/wicket/blob/7cfa536d/wicket-core/src/main/java/org/apache/wicket/markup/parser/filter/WicketLinkTagHandler.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/markup/parser/filter/WicketLinkTagHandler.java b/wicket-core/src/main/java/org/apache/wicket/markup/parser/filter/WicketLinkTagHandler.java
index 8244d25..a0f75fe 100644
--- a/wicket-core/src/main/java/org/apache/wicket/markup/parser/filter/WicketLinkTagHandler.java
+++ b/wicket-core/src/main/java/org/apache/wicket/markup/parser/filter/WicketLinkTagHandler.java
@@ -17,6 +17,7 @@
 package org.apache.wicket.markup.parser.filter;
 
 import java.text.ParseException;
+import java.util.ArrayDeque;
 
 import org.apache.wicket.Application;
 import org.apache.wicket.Component;
@@ -30,7 +31,6 @@ import org.apache.wicket.markup.WicketTag;
 import org.apache.wicket.markup.html.TransparentWebMarkupContainer;
 import org.apache.wicket.markup.parser.AbstractMarkupFilter;
 import org.apache.wicket.markup.resolver.IComponentResolver;
-import org.apache.wicket.util.collections.ArrayListStack;
 import org.apache.wicket.util.string.StringValueConversionException;
 import org.apache.wicket.util.string.Strings;
 import org.apache.wicket.util.value.IValueMap;
@@ -61,7 +61,7 @@ public class WicketLinkTagHandler extends AbstractMarkupFilter implements ICompo
 	public static final String AUTOLINK_ID = "_autolink_";
 
 	/** Allow to have link regions within link regions */
-	private ArrayListStack<Boolean> autolinkStatus;
+	private ArrayDeque<Boolean> autolinkStatus;
 
 	/** Current status */
 	private boolean autolinking = true;
@@ -127,7 +127,7 @@ public class WicketLinkTagHandler extends AbstractMarkupFilter implements ICompo
 					{
 						if (autolinkStatus == null)
 						{
-							autolinkStatus = new ArrayListStack<>();
+							autolinkStatus = new ArrayDeque<>();
 						}
 
 						// remember the current setting to be reset after the

http://git-wip-us.apache.org/repos/asf/wicket/blob/7cfa536d/wicket-extensions/src/main/java/org/apache/wicket/extensions/wizard/WizardModel.java
----------------------------------------------------------------------
diff --git a/wicket-extensions/src/main/java/org/apache/wicket/extensions/wizard/WizardModel.java b/wicket-extensions/src/main/java/org/apache/wicket/extensions/wizard/WizardModel.java
index 8b28dac..613d3cd 100644
--- a/wicket-extensions/src/main/java/org/apache/wicket/extensions/wizard/WizardModel.java
+++ b/wicket-extensions/src/main/java/org/apache/wicket/extensions/wizard/WizardModel.java
@@ -16,12 +16,12 @@
  */
 package org.apache.wicket.extensions.wizard;
 
+import java.util.ArrayDeque;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Iterator;
 import java.util.List;
 
-import org.apache.wicket.util.collections.ArrayListStack;
 import org.apache.wicket.util.io.IClusterable;
 
 
@@ -73,7 +73,7 @@ public class WizardModel extends AbstractWizardModel
 	private final List<ICondition> conditions = new ArrayList<>();
 
 	/** State history. */
-	private final ArrayListStack<IWizardStep> history = new ArrayListStack<>();
+	private final ArrayDeque<IWizardStep> history = new ArrayDeque<>();
 
 	/** The wizard steps. */
 	private final List<IWizardStep> steps = new ArrayList<>();

http://git-wip-us.apache.org/repos/asf/wicket/blob/7cfa536d/wicket-util/src/main/java/org/apache/wicket/util/collections/ArrayListStack.java
----------------------------------------------------------------------
diff --git a/wicket-util/src/main/java/org/apache/wicket/util/collections/ArrayListStack.java b/wicket-util/src/main/java/org/apache/wicket/util/collections/ArrayListStack.java
index 6148a84..a57e675 100644
--- a/wicket-util/src/main/java/org/apache/wicket/util/collections/ArrayListStack.java
+++ b/wicket-util/src/main/java/org/apache/wicket/util/collections/ArrayListStack.java
@@ -27,7 +27,9 @@ import java.util.EmptyStackException;
  * 
  * @author Jonathan Locke
  * @param <T>
+ * @deprecated Scheduled to be removed with Wicket 9.x, use {@link java.util.ArrayDeque} instead.
  */
+@Deprecated
 public class ArrayListStack<T> extends ArrayList<T>
 {
 	private static final long serialVersionUID = 1L;

http://git-wip-us.apache.org/repos/asf/wicket/blob/7cfa536d/wicket-util/src/main/java/org/apache/wicket/util/io/HandleArrayListStack.java
----------------------------------------------------------------------
diff --git a/wicket-util/src/main/java/org/apache/wicket/util/io/HandleArrayListStack.java b/wicket-util/src/main/java/org/apache/wicket/util/io/HandleArrayListStack.java
deleted file mode 100644
index 02d58bc..0000000
--- a/wicket-util/src/main/java/org/apache/wicket/util/io/HandleArrayListStack.java
+++ /dev/null
@@ -1,197 +0,0 @@
-/*
- * 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.wicket.util.io;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.EmptyStackException;
-
-/**
- * TODO document me.
- * 
- * @author jcompagner
- * @param <T>
- *            type of object in stack
- */
-final class HandleArrayListStack<T> extends ArrayList<T>
-{
-	private static final long serialVersionUID = 1L;
-
-	/**
-	 * Construct.
-	 */
-	public HandleArrayListStack()
-	{
-		this(10);
-	}
-
-	/**
-	 * Construct.
-	 * 
-	 * @param collection
-	 *            The collection to add
-	 */
-	public HandleArrayListStack(final Collection<? extends T> collection)
-	{
-		super(collection);
-	}
-
-	/**
-	 * Construct.
-	 * 
-	 * @param initialCapacity
-	 *            Initial capacity of the stack
-	 */
-	public HandleArrayListStack(final int initialCapacity)
-	{
-		super(initialCapacity);
-	}
-
-	/**
-	 * Tests if this stack is empty.
-	 * 
-	 * @return <code>true</code> if and only if this stack contains no items; <code>false</code>
-	 *         otherwise.
-	 */
-	public final boolean empty()
-	{
-		return size() == 0;
-	}
-
-	/**
-	 * @see java.util.ArrayList#indexOf(java.lang.Object)
-	 */
-	@Override
-	public int indexOf(final Object elem)
-	{
-		int size = size();
-		if (elem == null)
-		{
-			for (int i = 0; i < size; i++)
-			{
-				if (get(i) == null)
-				{
-					return i;
-				}
-			}
-		}
-		else
-		{
-			for (int i = 0; i < size; i++)
-			{
-				if (elem == get(i))
-				{
-					return i;
-				}
-			}
-		}
-		return -1;
-	}
-
-	/**
-	 * @see java.util.ArrayList#lastIndexOf(java.lang.Object)
-	 */
-	@Override
-	public int lastIndexOf(final Object elem)
-	{
-		if (elem == null)
-		{
-			for (int i = size() - 1; i >= 0; i--)
-			{
-				if (get(i) == null)
-				{
-					return i;
-				}
-			}
-		}
-		else
-		{
-			for (int i = size() - 1; i >= 0; i--)
-			{
-				if (elem == get(i))
-				{
-					return i;
-				}
-			}
-		}
-		return -1;
-	}
-
-	/**
-	 * Looks at the object at the top of this stack without removing it.
-	 * 
-	 * @return The object at the top of this stack
-	 * @exception EmptyStackException
-	 *                If this stack is empty.
-	 */
-	public final T peek()
-	{
-		int size = size();
-		if (size == 0)
-		{
-			throw new EmptyStackException();
-		}
-		return get(size - 1);
-	}
-
-	/**
-	 * Removes the object at the top of this stack and returns that object.
-	 * 
-	 * @return The object at the top of this stack
-	 * @exception EmptyStackException
-	 *                If this stack is empty.
-	 */
-	public final T pop()
-	{
-		final T top = peek();
-		remove(size() - 1);
-		return top;
-	}
-
-	/**
-	 * Pushes an item onto the top of this stack.
-	 * 
-	 * @param item
-	 *            the item to be pushed onto this stack.
-	 */
-	public final void push(final T item)
-	{
-		add(item);
-	}
-
-	/**
-	 * Returns the 1-based position where an object is on this stack. If the object <tt>o</tt>
-	 * occurs as an item in this stack, this method returns the distance from the top of the stack
-	 * of the occurrence nearest the top of the stack; the topmost item on the stack is considered
-	 * to be at distance <tt>1</tt>. The <tt>equals</tt> method is used to compare <tt>o</tt> to the
-	 * items in this stack.
-	 * 
-	 * @param o
-	 *            the desired object.
-	 * @return the 1-based position from the top of the stack where the object is located; the
-	 *         return value <code>-1</code> indicates that the object is not on the stack.
-	 */
-	public final int search(final Object o)
-	{
-		int i = lastIndexOf(o);
-		if (i >= 0)
-		{
-			return size() - i;
-		}
-		return -1;
-	}
-}
\ No newline at end of file