Author: nbelaevski
Date: 2011-03-11 10:36:17 -0500 (Fri, 11 Mar 2011)
New Revision: 22170
Added:
branches/4.0.X/ui/iteration/ui/src/main/java/org/richfaces/component/DataTableDataChilderIterator.java
Removed:
branches/4.0.X/ui/iteration/ui/src/main/java/org/richfaces/component/DataTableDataIterator.java
branches/4.0.X/ui/iteration/ui/src/main/java/org/richfaces/component/DataTableIteratorBase.java
branches/4.0.X/ui/iteration/ui/src/test/java/org/richfaces/component/IteratorBaseTest.java
Modified:
branches/4.0.X/ui/iteration/ui/src/main/java/org/richfaces/component/DataTableColumnsIterator.java
branches/4.0.X/ui/iteration/ui/src/main/java/org/richfaces/component/DataTableFixedChildrenIterator.java
branches/4.0.X/ui/iteration/ui/src/main/java/org/richfaces/component/UIDataTableBase.java
branches/4.0.X/ui/iteration/ui/src/test/java/org/richfaces/component/UIDataTableTest.java
Log:
https://issues.jboss.org/browse/RF-10734
Reviewed by Konstantin
Modified:
branches/4.0.X/ui/iteration/ui/src/main/java/org/richfaces/component/DataTableColumnsIterator.java
===================================================================
---
branches/4.0.X/ui/iteration/ui/src/main/java/org/richfaces/component/DataTableColumnsIterator.java 2011-03-11
15:36:16 UTC (rev 22169)
+++
branches/4.0.X/ui/iteration/ui/src/main/java/org/richfaces/component/DataTableColumnsIterator.java 2011-03-11
15:36:17 UTC (rev 22170)
@@ -24,34 +24,38 @@
import java.util.Iterator;
+import javax.faces.component.UIColumn;
import javax.faces.component.UIComponent;
+import com.google.common.collect.AbstractIterator;
+
/**
* Iterator for all children table columns.
*
* @author asmirnov
*
*/
-class DataTableColumnsIterator extends DataTableIteratorBase<UIComponent> {
+class DataTableColumnsIterator extends AbstractIterator<UIComponent> {
- protected Iterator<UIComponent> childrenIterator;
-
- public DataTableColumnsIterator(UIComponent dataTable) {
- this.childrenIterator = dataTable.getChildren().iterator();
+ private Iterator<UIComponent> childrenIterator;
+
+ public DataTableColumnsIterator(UIComponent component) {
+ super();
+ this.childrenIterator = component.getChildren().iterator();
}
- protected UIComponent nextItem() {
- while (childrenIterator != null && childrenIterator.hasNext()) {
+ @Override
+ protected UIComponent computeNext() {
+ while (childrenIterator.hasNext()) {
UIComponent child = childrenIterator.next();
- if (child instanceof javax.faces.component.UIColumn || child instanceof
Column) {
+
+ if (child instanceof UIColumn || child instanceof Column) {
return child;
}
}
-
- // TODO nick - free childrenIterator field
-
- return null;
+
+ return endOfData();
}
-
+
}
Added:
branches/4.0.X/ui/iteration/ui/src/main/java/org/richfaces/component/DataTableDataChilderIterator.java
===================================================================
---
branches/4.0.X/ui/iteration/ui/src/main/java/org/richfaces/component/DataTableDataChilderIterator.java
(rev 0)
+++
branches/4.0.X/ui/iteration/ui/src/main/java/org/richfaces/component/DataTableDataChilderIterator.java 2011-03-11
15:36:17 UTC (rev 22170)
@@ -0,0 +1,69 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2011, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.richfaces.component;
+
+import java.util.Iterator;
+
+import javax.faces.component.UIColumn;
+import javax.faces.component.UIComponent;
+
+import com.google.common.collect.AbstractIterator;
+import com.google.common.collect.Iterators;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+class DataTableDataChilderIterator extends AbstractIterator<UIComponent> {
+
+ private Iterator<UIComponent> dataTableChildren;
+
+ private Iterator<UIComponent> columnChildren = Iterators.emptyIterator();
+
+ public DataTableDataChilderIterator(UIComponent dataTable) {
+ super();
+ this.dataTableChildren = dataTable.getChildren().iterator();
+ }
+
+ @Override
+ protected UIComponent computeNext() {
+ while (columnChildren.hasNext() || dataTableChildren.hasNext()) {
+ if (columnChildren.hasNext()) {
+ return columnChildren.next();
+ }
+
+ UIComponent child = dataTableChildren.next();
+ if (child instanceof UIColumn || child instanceof AbstractColumn) {
+ columnChildren = child.getChildren().iterator();
+ } else {
+ columnChildren = Iterators.emptyIterator();
+ return child;
+ }
+ }
+
+ dataTableChildren = Iterators.emptyIterator();
+ columnChildren = Iterators.emptyIterator();
+
+ return endOfData();
+ }
+
+}
Deleted:
branches/4.0.X/ui/iteration/ui/src/main/java/org/richfaces/component/DataTableDataIterator.java
===================================================================
---
branches/4.0.X/ui/iteration/ui/src/main/java/org/richfaces/component/DataTableDataIterator.java 2011-03-11
15:36:16 UTC (rev 22169)
+++
branches/4.0.X/ui/iteration/ui/src/main/java/org/richfaces/component/DataTableDataIterator.java 2011-03-11
15:36:17 UTC (rev 22170)
@@ -1,71 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright ${year}, Red Hat, Inc. and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-
-package org.richfaces.component;
-
-import java.util.Iterator;
-
-import javax.faces.component.UIColumn;
-import javax.faces.component.UIComponent;
-
-
-class DataTableDataIterator extends DataTableIteratorBase<UIComponent> {
-
- private Iterator<UIComponent> facetsIterator;
-
- private Iterator<UIComponent> childrenIterator;
-
- public DataTableDataIterator(UIDataTableBase dataTable) {
- this.childrenIterator = dataTable.getChildren().iterator();
- this.facetsIterator = dataTable.getFacets().values().iterator();
- }
-
- protected UIComponent nextItem() {
-
- UIComponent nextColumn = null;
- while (nextColumn == null && childrenIterator.hasNext()) {
- UIComponent child = childrenIterator.next();
- if ((child instanceof UIColumn) || (child instanceof Column)) {
- nextColumn = child;
- }
- }
-
- // TODO nick - free childrenIterator
-
- while (nextColumn == null && facetsIterator.hasNext()) {
- nextColumn = facetsIterator.next();
- }
-
- // TODO nick - free facetsIterator
-
- return nextColumn;
- }
-
- protected Iterator<UIComponent> getFacetsIterator() {
- return this.facetsIterator;
- }
-
- protected Iterator<UIComponent> getChildrenIterator() {
- return this.childrenIterator;
- }
-
-}
Modified:
branches/4.0.X/ui/iteration/ui/src/main/java/org/richfaces/component/DataTableFixedChildrenIterator.java
===================================================================
---
branches/4.0.X/ui/iteration/ui/src/main/java/org/richfaces/component/DataTableFixedChildrenIterator.java 2011-03-11
15:36:16 UTC (rev 22169)
+++
branches/4.0.X/ui/iteration/ui/src/main/java/org/richfaces/component/DataTableFixedChildrenIterator.java 2011-03-11
15:36:17 UTC (rev 22170)
@@ -27,56 +27,45 @@
import javax.faces.component.UIColumn;
import javax.faces.component.UIComponent;
+import com.google.common.collect.AbstractIterator;
+import com.google.common.collect.Iterators;
-class DataTableFixedChildrenIterator extends DataTableDataIterator {
- private Iterator<UIComponent> currentColumnIterator;
+class DataTableFixedChildrenIterator extends AbstractIterator<UIComponent> {
- public DataTableFixedChildrenIterator(UIDataTableBase dataTable) {
- super(dataTable);
+ private Iterator<UIComponent> facetsIterator;
+
+ private Iterator<UIComponent> dataTableChildren;
+
+ private Iterator<UIComponent> columnFacets = Iterators.emptyIterator();
+
+ public DataTableFixedChildrenIterator(UIComponent dataTable) {
+ super();
+
+ this.facetsIterator = dataTable.getFacets().values().iterator();
+ this.dataTableChildren = dataTable.getChildren().iterator();
}
- protected UIComponent nextItem() {
- UIComponent next = null;
-
- if (currentColumnIterator != null && currentColumnIterator.hasNext()) {
- next = currentColumnIterator.next();
- checkColumnIterator();
+ @Override
+ protected UIComponent computeNext() {
+ if (facetsIterator.hasNext()) {
+ return facetsIterator.next();
}
-
- if (next == null) {
- Iterator<UIComponent> childrenIterator = getChildrenIterator();
- while (next == null && childrenIterator.hasNext()) {
- UIComponent child = childrenIterator.next();
- if ((child instanceof UIColumn) && child.isRendered()) {
- currentColumnIterator = getChildFacetIterator(child);
- next = nextItem();
- }
+
+ while (columnFacets.hasNext() || dataTableChildren.hasNext()) {
+ if (columnFacets.hasNext()) {
+ return columnFacets.next();
}
+
+ UIComponent child = dataTableChildren.next();
+ if (child instanceof UIColumn || child instanceof AbstractColumn) {
+ columnFacets = child.getFacets().values().iterator();
+ }
}
- if (next == null) {
- next = getNextFacet();
- }
- return next;
- }
+ dataTableChildren = Iterators.emptyIterator();
+ columnFacets = Iterators.emptyIterator();
- protected UIComponent getNextFacet() {
- Iterator<UIComponent> facetsIterator = getFacetsIterator();
- if(facetsIterator.hasNext()) {
- return facetsIterator.next();
- }
- return null;
+ return endOfData();
}
-
- protected void checkColumnIterator() {
- if (!currentColumnIterator.hasNext()) {
- currentColumnIterator = null;
- }
- }
-
- protected Iterator<UIComponent> getChildFacetIterator(UIComponent component) {
- return component.getFacets().values().iterator();
- }
-
}
Deleted:
branches/4.0.X/ui/iteration/ui/src/main/java/org/richfaces/component/DataTableIteratorBase.java
===================================================================
---
branches/4.0.X/ui/iteration/ui/src/main/java/org/richfaces/component/DataTableIteratorBase.java 2011-03-11
15:36:16 UTC (rev 22169)
+++
branches/4.0.X/ui/iteration/ui/src/main/java/org/richfaces/component/DataTableIteratorBase.java 2011-03-11
15:36:17 UTC (rev 22170)
@@ -1,72 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright ${year}, Red Hat, Inc. and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-package org.richfaces.component;
-
-import java.util.Iterator;
-import java.util.NoSuchElementException;
-
-/**
- * @author Anton Belevich
- * @author Nick Belaevski
- */
-public abstract class DataTableIteratorBase<E> implements Iterator<E> {
-
- private boolean isCompleted = false;
-
- private E next = null;
-
- private void setupNext() {
- if (!isCompleted) {
- if (next == null) {
- next = nextItem();
-
- if (next == null) {
- isCompleted = true;
- }
- }
- }
- }
-
- public boolean hasNext() {
- setupNext();
-
- return next != null;
- }
-
- public E next() {
- setupNext();
-
- if (next == null) {
- throw new NoSuchElementException();
- }
-
- E result = next;
- next = null;
- return result;
- }
-
- public void remove() {
- throw new UnsupportedOperationException("Iterator is read-only");
- }
-
- protected abstract E nextItem();
-}
Modified:
branches/4.0.X/ui/iteration/ui/src/main/java/org/richfaces/component/UIDataTableBase.java
===================================================================
---
branches/4.0.X/ui/iteration/ui/src/main/java/org/richfaces/component/UIDataTableBase.java 2011-03-11
15:36:16 UTC (rev 22169)
+++
branches/4.0.X/ui/iteration/ui/src/main/java/org/richfaces/component/UIDataTableBase.java 2011-03-11
15:36:17 UTC (rev 22170)
@@ -32,7 +32,6 @@
import java.util.Map;
import java.util.Set;
-import javax.faces.component.UIColumn;
import javax.faces.component.UIComponent;
import javax.faces.component.visit.VisitCallback;
import javax.faces.component.visit.VisitContext;
@@ -42,7 +41,6 @@
import javax.faces.event.PhaseId;
import javax.faces.event.PreRenderComponentEvent;
-import org.ajax4jsf.component.IterationStateHolder;
import org.ajax4jsf.model.DataVisitor;
import org.ajax4jsf.model.ExtendedDataModel;
import org.ajax4jsf.model.Range;
@@ -173,7 +171,7 @@
}
protected Iterator<UIComponent> dataChildren() {
- return new DataTableDataIterator(this);
+ return new DataTableDataChilderIterator(this);
}
public boolean isColumnFacetPresent(String facetName) {
@@ -394,50 +392,4 @@
return SUPPORTED_META_COMPONENTS;
}
- private boolean isStateful(UIComponent component) {
- if (component instanceof IterationStateHolder) {
- return true;
- }
-
- if (component instanceof UIColumn || component instanceof Column) {
- return false;
- }
-
- return true;
- }
-
- @Override
- protected void saveChildState(FacesContext facesContext) {
- Iterator<UIComponent> dataChildren = dataChildren();
- while (dataChildren.hasNext()) {
- UIComponent child = dataChildren.next();
-
- if (isStateful(child)) {
- saveChildState(facesContext, child);
- } else {
- for (UIComponent grandKid: child.getChildren()) {
- saveChildState(facesContext, grandKid);
- }
- }
- }
- }
-
- @Override
- protected void restoreChildState(FacesContext facesContext) {
- Iterator<UIComponent> dataChildren = dataChildren();
- while (dataChildren.hasNext()) {
- UIComponent child = dataChildren.next();
-
- if (isStateful(child)) {
- restoreChildState(facesContext, child);
- } else {
- //reset cached clientId
- child.setId(child.getId());
-
- for (UIComponent grandKid: child.getChildren()) {
- restoreChildState(facesContext, grandKid);
- }
- }
- }
- }
}
Deleted:
branches/4.0.X/ui/iteration/ui/src/test/java/org/richfaces/component/IteratorBaseTest.java
===================================================================
---
branches/4.0.X/ui/iteration/ui/src/test/java/org/richfaces/component/IteratorBaseTest.java 2011-03-11
15:36:16 UTC (rev 22169)
+++
branches/4.0.X/ui/iteration/ui/src/test/java/org/richfaces/component/IteratorBaseTest.java 2011-03-11
15:36:17 UTC (rev 22170)
@@ -1,150 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2009, Red Hat, Inc. and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-package org.richfaces.component;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.List;
-import java.util.NoSuchElementException;
-
-import org.junit.Test;
-
-
-/**
- * @author Nick Belaevski
- */
-public class IteratorBaseTest {
-
- private static final List<String> strings =
Collections.unmodifiableList(Arrays.asList("a", "b", "c"));
-
- private static class IteratorImpl<E> extends DataTableIteratorBase<E> {
-
- private Iterator<E> iterator;
-
- public IteratorImpl(List<E> list) {
- super();
-
- this.iterator = list.iterator();
- }
-
- @Override
- protected E nextItem() {
- if (iterator.hasNext()) {
- return iterator.next();
- }
-
- return null;
- }
-
- }
-
- private Iterator<String> createTestIterator(List<String> list) {
- return new IteratorImpl<String>(list);
- }
-
- private Iterator<String> createStringsIterator() {
- return createTestIterator(strings);
- }
-
- private Iterator<String> createEmptyIterator() {
- return createTestIterator(Collections.<String>emptyList());
- }
-
- @Test
- public void testIteration() throws Exception {
- Iterator<String> testIterator = createStringsIterator();
- assertTrue(testIterator.hasNext());
- assertEquals("a", testIterator.next());
- assertTrue(testIterator.hasNext());
- assertEquals("b", testIterator.next());
- assertTrue(testIterator.hasNext());
- assertEquals("c", testIterator.next());
- assertFalse(testIterator.hasNext());
- try {
- testIterator.next();
-
- fail();
- } catch (NoSuchElementException e) {
- //should be thrown - ignore
- }
- }
-
- @Test
- public void testIterationWithoutHasNext() throws Exception {
- Iterator<String> testIterator = createStringsIterator();
- assertEquals("a", testIterator.next());
- assertEquals("b", testIterator.next());
- assertEquals("c", testIterator.next());
- try {
- testIterator.next();
-
- fail();
- } catch (NoSuchElementException e) {
- //should be thrown - ignore
- }
- assertFalse(testIterator.hasNext());
- }
-
- @Test
- public void testEmptyList() throws Exception {
- Iterator<String> testIterator = createEmptyIterator();
- assertFalse(testIterator.hasNext());
- try {
- testIterator.next();
-
- fail();
- } catch (NoSuchElementException e) {
- //should be thrown - ignore
- }
- }
-
- @Test
- public void testEmptyListWithoutHasNext() throws Exception {
- Iterator<String> testIterator = createEmptyIterator();
- try {
- testIterator.next();
-
- fail();
- } catch (NoSuchElementException e) {
- //should be thrown - ignore
- }
- }
-
- @Test
- public void testRemove() throws Exception {
- Iterator<String> testIterator = createStringsIterator();
- testIterator.next();
- try {
- testIterator.remove();
-
- fail();
- } catch (Exception e) {
- //unsupported - ignore
- }
- }
-}
Modified:
branches/4.0.X/ui/iteration/ui/src/test/java/org/richfaces/component/UIDataTableTest.java
===================================================================
---
branches/4.0.X/ui/iteration/ui/src/test/java/org/richfaces/component/UIDataTableTest.java 2011-03-11
15:36:16 UTC (rev 22169)
+++
branches/4.0.X/ui/iteration/ui/src/test/java/org/richfaces/component/UIDataTableTest.java 2011-03-11
15:36:17 UTC (rev 22170)
@@ -144,7 +144,7 @@
*/
@Test
public void testDataChildren() {
- Assert.assertTrue(table.dataChildren() instanceof DataTableDataIterator);
+ Assert.assertTrue(table.dataChildren() instanceof DataTableDataChilderIterator);
}
/**