You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by da...@apache.org on 2015/09/21 13:42:02 UTC
[1/2] wicket git commit: Removed copy of children for get(int)
Repository: wicket
Updated Branches:
refs/heads/WICKET-5981 d7cf97499 -> 3677e6b96
Removed copy of children for get(int)
Copying the children for getting a component by index seemed wasteful,
implemented get using iterator.
Project: http://git-wip-us.apache.org/repos/asf/wicket/repo
Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/5271f27c
Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/5271f27c
Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/5271f27c
Branch: refs/heads/WICKET-5981
Commit: 5271f27c8f6a2f451f3587f8313af0c6da84f9c6
Parents: d7cf974
Author: Martijn Dashorst <ma...@gmail.com>
Authored: Mon Sep 21 13:40:42 2015 +0200
Committer: Martijn Dashorst <ma...@gmail.com>
Committed: Mon Sep 21 13:40:42 2015 +0200
----------------------------------------------------------------------
.../java/org/apache/wicket/MarkupContainer.java | 14 ++++-
.../org/apache/wicket/MarkupContainerTest.java | 64 ++++++++++++++++++++
2 files changed, 77 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/wicket/blob/5271f27c/wicket-core/src/main/java/org/apache/wicket/MarkupContainer.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/MarkupContainer.java b/wicket-core/src/main/java/org/apache/wicket/MarkupContainer.java
index ca79052..5f0d035 100644
--- a/wicket-core/src/main/java/org/apache/wicket/MarkupContainer.java
+++ b/wicket-core/src/main/java/org/apache/wicket/MarkupContainer.java
@@ -1007,12 +1007,24 @@ public abstract class MarkupContainer extends Component implements Iterable<Comp
* the number of children.
*
* @param index
+ * the index of the child in this container
* @throws ArrayIndexOutOfBoundsException
+ * when {@code index} exceeds {@code size()}
* @return child component at the specified index
*/
public final Component get(int index)
{
- return copyChildren().get(index);
+ Component childAtIndex = null;
+ Iterator<Component> childIterator = iterator();
+ while (index-- >= 0 && childIterator.hasNext())
+ {
+ childAtIndex = childIterator.next();
+ }
+ if(childAtIndex == null)
+ {
+ throw new ArrayIndexOutOfBoundsException(Integer.toString(index));
+ }
+ return childAtIndex;
}
/**
http://git-wip-us.apache.org/repos/asf/wicket/blob/5271f27c/wicket-core/src/test/java/org/apache/wicket/MarkupContainerTest.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/test/java/org/apache/wicket/MarkupContainerTest.java b/wicket-core/src/test/java/org/apache/wicket/MarkupContainerTest.java
index 4c24c02..b21757d 100644
--- a/wicket-core/src/test/java/org/apache/wicket/MarkupContainerTest.java
+++ b/wicket-core/src/test/java/org/apache/wicket/MarkupContainerTest.java
@@ -16,6 +16,10 @@
*/
package org.apache.wicket;
+import static org.hamcrest.CoreMatchers.is;
+
+import java.util.NoSuchElementException;
+
import org.apache.wicket.markup.IMarkupResourceStreamProvider;
import org.apache.wicket.markup.html.WebComponent;
import org.apache.wicket.markup.html.WebMarkupContainer;
@@ -23,6 +27,7 @@ import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.util.resource.IResourceStream;
import org.apache.wicket.util.resource.StringResourceStream;
import org.apache.wicket.util.tester.WicketTestCase;
+import org.junit.Assert;
import org.junit.Test;
@@ -109,6 +114,65 @@ public class MarkupContainerTest extends WicketTestCase
}
/**
+ * Tests the get(int) method of MarkupContainer.
+ */
+ @Test
+ public void getIndexed()
+ {
+ MarkupContainer c = new WebMarkupContainer("parent");
+ Component c1 = new WebComponent("c1");
+ Component c2 = new WebComponent("c2");
+
+ c.add(c1);
+ c.add(c2);
+
+ assertThat(c.get(0), is(c1));
+ assertThat(c.get(1), is(c2));
+ }
+
+ /**
+ * Tests the get(int) method of MarkupContainer when the index exceeds the number of children.
+ */
+ @Test(expected = ArrayIndexOutOfBoundsException.class)
+ public void getIndexedArrayIndexOutOfBoundsException()
+ {
+ MarkupContainer c = new WebMarkupContainer("parent");
+ c.get(0);
+ }
+
+ /**
+ * Tests the swap method.
+ */
+ @Test
+ public void swap()
+ {
+ MarkupContainer c = new WebMarkupContainer("parent");
+ Component c1 = new WebComponent("c1");
+ Component c2 = new WebComponent("c2");
+ Component c3 = new WebComponent("c3");
+
+ c.add(c1);
+ c.add(c2);
+ c.add(c3);
+
+ assertThat(c.get(0), is(c1));
+ assertThat(c.get(1), is(c2));
+ assertThat(c.get(2), is(c3));
+
+ c.swap(0, 1);
+
+ assertThat(c.get(0), is(c2));
+ assertThat(c.get(1), is(c1));
+ assertThat(c.get(2), is(c3));
+
+ c.swap(0, 2);
+
+ assertThat(c.get(0), is(c3));
+ assertThat(c.get(1), is(c1));
+ assertThat(c.get(2), is(c2));
+ }
+
+ /**
* https://issues.apache.org/jira/browse/WICKET-4006
*/
@Test(expected = IllegalArgumentException.class)
Re: [2/2] wicket git commit: Deprecated MarkupContainer#get(int),
swap(int, int)
Posted by Martin Grigorov <mg...@apache.org>.
fine too!
Martin Grigorov
Wicket Training and Consulting
https://twitter.com/mtgrigorov
On Mon, Sep 21, 2015 at 1:51 PM, Martijn Dashorst <
martijn.dashorst@gmail.com> wrote:
> or WICKET8? makes grepping easy for these kinds of things.
>
> Martijn
>
> On Mon, Sep 21, 2015 at 1:45 PM, Martin Grigorov <mg...@apache.org>
> wrote:
> > On Mon, Sep 21, 2015 at 1:42 PM, <da...@apache.org> wrote:
> >
> >> Deprecated MarkupContainer#get(int), swap(int,int)
> >>
> >> Both methods are deemed unnecessary and are slated for deletion in
> wicket
> >> 8.
> >>
> >>
> >> Project: http://git-wip-us.apache.org/repos/asf/wicket/repo
> >> Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/3677e6b9
> >> Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/3677e6b9
> >> Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/3677e6b9
> >>
> >> Branch: refs/heads/WICKET-5981
> >> Commit: 3677e6b96e1c04eb8162ec40fe789a0fff8d532b
> >> Parents: 5271f27
> >> Author: Martijn Dashorst <ma...@gmail.com>
> >> Authored: Mon Sep 21 13:41:51 2015 +0200
> >> Committer: Martijn Dashorst <ma...@gmail.com>
> >> Committed: Mon Sep 21 13:41:51 2015 +0200
> >>
> >> ----------------------------------------------------------------------
> >> .../main/java/org/apache/wicket/MarkupContainer.java | 12
> ++++++++----
> >> 1 file changed, 8 insertions(+), 4 deletions(-)
> >> ----------------------------------------------------------------------
> >>
> >>
> >>
> >>
> http://git-wip-us.apache.org/repos/asf/wicket/blob/3677e6b9/wicket-core/src/main/java/org/apache/wicket/MarkupContainer.java
> >> ----------------------------------------------------------------------
> >> diff --git
> >> a/wicket-core/src/main/java/org/apache/wicket/MarkupContainer.java
> >> b/wicket-core/src/main/java/org/apache/wicket/MarkupContainer.java
> >> index 5f0d035..c87bd00 100644
> >> --- a/wicket-core/src/main/java/org/apache/wicket/MarkupContainer.java
> >> +++ b/wicket-core/src/main/java/org/apache/wicket/MarkupContainer.java
> >> @@ -1011,7 +1011,9 @@ public abstract class MarkupContainer extends
> >> Component implements Iterable<Comp
> >> * @throws ArrayIndexOutOfBoundsException
> >> * when {@code index} exceeds {@code size()}
> >> * @return child component at the specified index
> >> + * @deprecated this method is marked for deletion for WICKET-8
> >>
> >
> > WICKET-8 is a bit confusing because it looks like a JIRA ticket
> >
> > Before we have used Wicket.next and Wicket 7.0, so I suggest to use
> "Wicket
> > 8.0.0" instead
> >
> >
> >> */
> >> + @Deprecated
> >> public final Component get(int index)
> >> {
> >> Component childAtIndex = null;
> >> @@ -1626,20 +1628,22 @@ public abstract class MarkupContainer extends
> >> Component implements Iterable<Comp
> >> * index of first component to be swapped
> >> * @param idx2
> >> * index of second component to be swapped
> >> + * @deprecated this method is marked for deletion for WICKET-8
> >> */
> >> + @Deprecated
> >> public final void swap(int idx1, int idx2)
> >> {
> >> int size = children_size();
> >> if (idx1 < 0 || idx1 >= size)
> >> {
> >> - throw new IndexOutOfBoundsException("Argument
> idx
> >> is out of bounds: " + idx1 + "<>[0," +
> >> - size + ")");
> >> + throw new IndexOutOfBoundsException(
> >> + "Argument idx is out of bounds: " +
> idx1 +
> >> "<>[0," + size + ")");
> >> }
> >>
> >> if (idx2 < 0 || idx2 >= size)
> >> {
> >> - throw new IndexOutOfBoundsException("Argument
> idx
> >> is out of bounds: " + idx2 + "<>[0," +
> >> - size + ")");
> >> + throw new IndexOutOfBoundsException(
> >> + "Argument idx is out of bounds: " +
> idx2 +
> >> "<>[0," + size + ")");
> >> }
> >>
> >> if (idx1 == idx2)
> >>
> >>
>
>
>
> --
> Become a Wicket expert, learn from the best: http://wicketinaction.com
>
Re: [2/2] wicket git commit: Deprecated MarkupContainer#get(int),
swap(int, int)
Posted by Martijn Dashorst <ma...@gmail.com>.
or WICKET8? makes grepping easy for these kinds of things.
Martijn
On Mon, Sep 21, 2015 at 1:45 PM, Martin Grigorov <mg...@apache.org> wrote:
> On Mon, Sep 21, 2015 at 1:42 PM, <da...@apache.org> wrote:
>
>> Deprecated MarkupContainer#get(int), swap(int,int)
>>
>> Both methods are deemed unnecessary and are slated for deletion in wicket
>> 8.
>>
>>
>> Project: http://git-wip-us.apache.org/repos/asf/wicket/repo
>> Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/3677e6b9
>> Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/3677e6b9
>> Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/3677e6b9
>>
>> Branch: refs/heads/WICKET-5981
>> Commit: 3677e6b96e1c04eb8162ec40fe789a0fff8d532b
>> Parents: 5271f27
>> Author: Martijn Dashorst <ma...@gmail.com>
>> Authored: Mon Sep 21 13:41:51 2015 +0200
>> Committer: Martijn Dashorst <ma...@gmail.com>
>> Committed: Mon Sep 21 13:41:51 2015 +0200
>>
>> ----------------------------------------------------------------------
>> .../main/java/org/apache/wicket/MarkupContainer.java | 12 ++++++++----
>> 1 file changed, 8 insertions(+), 4 deletions(-)
>> ----------------------------------------------------------------------
>>
>>
>>
>> http://git-wip-us.apache.org/repos/asf/wicket/blob/3677e6b9/wicket-core/src/main/java/org/apache/wicket/MarkupContainer.java
>> ----------------------------------------------------------------------
>> diff --git
>> a/wicket-core/src/main/java/org/apache/wicket/MarkupContainer.java
>> b/wicket-core/src/main/java/org/apache/wicket/MarkupContainer.java
>> index 5f0d035..c87bd00 100644
>> --- a/wicket-core/src/main/java/org/apache/wicket/MarkupContainer.java
>> +++ b/wicket-core/src/main/java/org/apache/wicket/MarkupContainer.java
>> @@ -1011,7 +1011,9 @@ public abstract class MarkupContainer extends
>> Component implements Iterable<Comp
>> * @throws ArrayIndexOutOfBoundsException
>> * when {@code index} exceeds {@code size()}
>> * @return child component at the specified index
>> + * @deprecated this method is marked for deletion for WICKET-8
>>
>
> WICKET-8 is a bit confusing because it looks like a JIRA ticket
>
> Before we have used Wicket.next and Wicket 7.0, so I suggest to use "Wicket
> 8.0.0" instead
>
>
>> */
>> + @Deprecated
>> public final Component get(int index)
>> {
>> Component childAtIndex = null;
>> @@ -1626,20 +1628,22 @@ public abstract class MarkupContainer extends
>> Component implements Iterable<Comp
>> * index of first component to be swapped
>> * @param idx2
>> * index of second component to be swapped
>> + * @deprecated this method is marked for deletion for WICKET-8
>> */
>> + @Deprecated
>> public final void swap(int idx1, int idx2)
>> {
>> int size = children_size();
>> if (idx1 < 0 || idx1 >= size)
>> {
>> - throw new IndexOutOfBoundsException("Argument idx
>> is out of bounds: " + idx1 + "<>[0," +
>> - size + ")");
>> + throw new IndexOutOfBoundsException(
>> + "Argument idx is out of bounds: " + idx1 +
>> "<>[0," + size + ")");
>> }
>>
>> if (idx2 < 0 || idx2 >= size)
>> {
>> - throw new IndexOutOfBoundsException("Argument idx
>> is out of bounds: " + idx2 + "<>[0," +
>> - size + ")");
>> + throw new IndexOutOfBoundsException(
>> + "Argument idx is out of bounds: " + idx2 +
>> "<>[0," + size + ")");
>> }
>>
>> if (idx1 == idx2)
>>
>>
--
Become a Wicket expert, learn from the best: http://wicketinaction.com
Re: [2/2] wicket git commit: Deprecated MarkupContainer#get(int),
swap(int, int)
Posted by Martin Grigorov <mg...@apache.org>.
On Mon, Sep 21, 2015 at 1:42 PM, <da...@apache.org> wrote:
> Deprecated MarkupContainer#get(int), swap(int,int)
>
> Both methods are deemed unnecessary and are slated for deletion in wicket
> 8.
>
>
> Project: http://git-wip-us.apache.org/repos/asf/wicket/repo
> Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/3677e6b9
> Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/3677e6b9
> Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/3677e6b9
>
> Branch: refs/heads/WICKET-5981
> Commit: 3677e6b96e1c04eb8162ec40fe789a0fff8d532b
> Parents: 5271f27
> Author: Martijn Dashorst <ma...@gmail.com>
> Authored: Mon Sep 21 13:41:51 2015 +0200
> Committer: Martijn Dashorst <ma...@gmail.com>
> Committed: Mon Sep 21 13:41:51 2015 +0200
>
> ----------------------------------------------------------------------
> .../main/java/org/apache/wicket/MarkupContainer.java | 12 ++++++++----
> 1 file changed, 8 insertions(+), 4 deletions(-)
> ----------------------------------------------------------------------
>
>
>
> http://git-wip-us.apache.org/repos/asf/wicket/blob/3677e6b9/wicket-core/src/main/java/org/apache/wicket/MarkupContainer.java
> ----------------------------------------------------------------------
> diff --git
> a/wicket-core/src/main/java/org/apache/wicket/MarkupContainer.java
> b/wicket-core/src/main/java/org/apache/wicket/MarkupContainer.java
> index 5f0d035..c87bd00 100644
> --- a/wicket-core/src/main/java/org/apache/wicket/MarkupContainer.java
> +++ b/wicket-core/src/main/java/org/apache/wicket/MarkupContainer.java
> @@ -1011,7 +1011,9 @@ public abstract class MarkupContainer extends
> Component implements Iterable<Comp
> * @throws ArrayIndexOutOfBoundsException
> * when {@code index} exceeds {@code size()}
> * @return child component at the specified index
> + * @deprecated this method is marked for deletion for WICKET-8
>
WICKET-8 is a bit confusing because it looks like a JIRA ticket
Before we have used Wicket.next and Wicket 7.0, so I suggest to use "Wicket
8.0.0" instead
> */
> + @Deprecated
> public final Component get(int index)
> {
> Component childAtIndex = null;
> @@ -1626,20 +1628,22 @@ public abstract class MarkupContainer extends
> Component implements Iterable<Comp
> * index of first component to be swapped
> * @param idx2
> * index of second component to be swapped
> + * @deprecated this method is marked for deletion for WICKET-8
> */
> + @Deprecated
> public final void swap(int idx1, int idx2)
> {
> int size = children_size();
> if (idx1 < 0 || idx1 >= size)
> {
> - throw new IndexOutOfBoundsException("Argument idx
> is out of bounds: " + idx1 + "<>[0," +
> - size + ")");
> + throw new IndexOutOfBoundsException(
> + "Argument idx is out of bounds: " + idx1 +
> "<>[0," + size + ")");
> }
>
> if (idx2 < 0 || idx2 >= size)
> {
> - throw new IndexOutOfBoundsException("Argument idx
> is out of bounds: " + idx2 + "<>[0," +
> - size + ")");
> + throw new IndexOutOfBoundsException(
> + "Argument idx is out of bounds: " + idx2 +
> "<>[0," + size + ")");
> }
>
> if (idx1 == idx2)
>
>
[2/2] wicket git commit: Deprecated MarkupContainer#get(int), swap(int,
int)
Posted by da...@apache.org.
Deprecated MarkupContainer#get(int), swap(int,int)
Both methods are deemed unnecessary and are slated for deletion in wicket 8.
Project: http://git-wip-us.apache.org/repos/asf/wicket/repo
Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/3677e6b9
Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/3677e6b9
Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/3677e6b9
Branch: refs/heads/WICKET-5981
Commit: 3677e6b96e1c04eb8162ec40fe789a0fff8d532b
Parents: 5271f27
Author: Martijn Dashorst <ma...@gmail.com>
Authored: Mon Sep 21 13:41:51 2015 +0200
Committer: Martijn Dashorst <ma...@gmail.com>
Committed: Mon Sep 21 13:41:51 2015 +0200
----------------------------------------------------------------------
.../main/java/org/apache/wicket/MarkupContainer.java | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/wicket/blob/3677e6b9/wicket-core/src/main/java/org/apache/wicket/MarkupContainer.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/MarkupContainer.java b/wicket-core/src/main/java/org/apache/wicket/MarkupContainer.java
index 5f0d035..c87bd00 100644
--- a/wicket-core/src/main/java/org/apache/wicket/MarkupContainer.java
+++ b/wicket-core/src/main/java/org/apache/wicket/MarkupContainer.java
@@ -1011,7 +1011,9 @@ public abstract class MarkupContainer extends Component implements Iterable<Comp
* @throws ArrayIndexOutOfBoundsException
* when {@code index} exceeds {@code size()}
* @return child component at the specified index
+ * @deprecated this method is marked for deletion for WICKET-8
*/
+ @Deprecated
public final Component get(int index)
{
Component childAtIndex = null;
@@ -1626,20 +1628,22 @@ public abstract class MarkupContainer extends Component implements Iterable<Comp
* index of first component to be swapped
* @param idx2
* index of second component to be swapped
+ * @deprecated this method is marked for deletion for WICKET-8
*/
+ @Deprecated
public final void swap(int idx1, int idx2)
{
int size = children_size();
if (idx1 < 0 || idx1 >= size)
{
- throw new IndexOutOfBoundsException("Argument idx is out of bounds: " + idx1 + "<>[0," +
- size + ")");
+ throw new IndexOutOfBoundsException(
+ "Argument idx is out of bounds: " + idx1 + "<>[0," + size + ")");
}
if (idx2 < 0 || idx2 >= size)
{
- throw new IndexOutOfBoundsException("Argument idx is out of bounds: " + idx2 + "<>[0," +
- size + ")");
+ throw new IndexOutOfBoundsException(
+ "Argument idx is out of bounds: " + idx2 + "<>[0," + size + ")");
}
if (idx1 == idx2)