You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@chemistry.apache.org by dc...@apache.org on 2010/04/23 22:34:58 UTC
svn commit: r937510 - in
/incubator/chemistry/opencmis/trunk/chemistry-opencmis-client:
chemistry-opencmis-client-api/src/main/java/org/apache/chemistry/opencmis/client/api/
chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/cli...
Author: dcaruana
Date: Fri Apr 23 20:34:58 2010
New Revision: 937510
URL: http://svn.apache.org/viewvc?rev=937510&view=rev
Log:
Paging List Interface changes:
- PagingIterable: add PagingIterable<T> getPage();
- PagingIterable: add PagingIterator<T> iterator();
- PagingIterable: add PagingIterator<T> getIterator();
- PagingIterator: add boolean getHasMoreItems();
Implementations:
- CollectionIterable/Iterator : for iterating through complete CMIS collection
- PageIterable/Iterator : for iterating through a page only
- AbstractIterator : base iterator implementation
Tests:
- PagingListTest: add testHasMoreItems
- PagingListTest: add loopPage
Added:
incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/util/AbstractIterator.java (with props)
incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/util/CollectionIterable.java (contents, props changed)
- copied, changed from r937239, incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/util/DefaultPagingIterable.java
incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/util/CollectionIterator.java (contents, props changed)
- copied, changed from r937239, incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/util/DefaultPagingIterator.java
incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/util/PageIterable.java (with props)
incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/util/PageIterator.java (with props)
Removed:
incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/util/DefaultPagingIterable.java
incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/util/DefaultPagingIterator.java
Modified:
incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-api/src/main/java/org/apache/chemistry/opencmis/client/api/PagingIterable.java
incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-api/src/main/java/org/apache/chemistry/opencmis/client/api/PagingIterator.java
incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/AbstractPersistentCmisObject.java
incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/PersistentFolderImpl.java
incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/PersistentSessionImpl.java
incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/test/java/org/apache/chemistry/opencmis/client/runtime/PagingListTest.java
Modified: incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-api/src/main/java/org/apache/chemistry/opencmis/client/api/PagingIterable.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-api/src/main/java/org/apache/chemistry/opencmis/client/api/PagingIterable.java?rev=937510&r1=937509&r2=937510&view=diff
==============================================================================
--- incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-api/src/main/java/org/apache/chemistry/opencmis/client/api/PagingIterable.java (original)
+++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-api/src/main/java/org/apache/chemistry/opencmis/client/api/PagingIterable.java Fri Apr 23 20:34:58 2010
@@ -19,8 +19,7 @@
package org.apache.chemistry.opencmis.client.api;
/**
- * Iterable for CMIS collections that allows ability to skip to specific
- * position.
+ * Iterable for CMIS collections that allows ability to skip to specific position.
*
* @param <T>
*/
@@ -30,8 +29,28 @@ public interface PagingIterable<T> exten
* Skip to position within CMIS collection
*
* @param position
- * @return iterable whose starting point is the specicied skip to position
+ * @return iterable whose starting point is the specified skip to position
*/
PagingIterable<T> skipTo(long position);
+ /**
+ * Gets an iterable for the current page within the CMIS collection
+ *
+ * @return iterable for current page
+ */
+ PagingIterable<T> getPage();
+
+ /*
+ * (non-Javadoc)
+ * @see java.lang.Iterable#iterator()
+ */
+ PagingIterator<T> iterator();
+
+ /**
+ * Getter version of iterator()
+ *
+ * @see java.lang.Iterable#iterator()
+ * @return iterator
+ */
+ PagingIterator<T> getIterator();
}
Modified: incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-api/src/main/java/org/apache/chemistry/opencmis/client/api/PagingIterator.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-api/src/main/java/org/apache/chemistry/opencmis/client/api/PagingIterator.java?rev=937510&r1=937509&r2=937510&view=diff
==============================================================================
--- incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-api/src/main/java/org/apache/chemistry/opencmis/client/api/PagingIterator.java (original)
+++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-api/src/main/java/org/apache/chemistry/opencmis/client/api/PagingIterator.java Fri Apr 23 20:34:58 2010
@@ -28,13 +28,21 @@ import java.util.Iterator;
public interface PagingIterator<T> extends Iterator<T> {
/**
- * Returns the current position within the iterator.
+ * Returns the current position within the CMIS collection.
*
* @return iterator position
*/
long getPosition();
/**
+ * Returns whether the repository contains additional items beyond the page of
+ * items already fetched.
+ *
+ * @return true => further page requests will be made to the repository
+ */
+ boolean getHasMoreItems();
+
+ /**
* Returns the total number of items. If the repository knows the total
* number of items in a result set, the repository SHOULD include the number
* here. If the repository does not know the number of items in a result
@@ -45,5 +53,5 @@ public interface PagingIterator<T> exten
* @return total number of items or (-1)
*/
long getTotalNumItems();
-
+
}
Modified: incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/AbstractPersistentCmisObject.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/AbstractPersistentCmisObject.java?rev=937510&r1=937509&r2=937510&view=diff
==============================================================================
--- incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/AbstractPersistentCmisObject.java (original)
+++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/AbstractPersistentCmisObject.java Fri Apr 23 20:34:58 2010
@@ -40,7 +40,7 @@ import org.apache.chemistry.opencmis.cli
import org.apache.chemistry.opencmis.client.api.Relationship;
import org.apache.chemistry.opencmis.client.api.Rendition;
import org.apache.chemistry.opencmis.client.runtime.util.AbstractPageFetch;
-import org.apache.chemistry.opencmis.client.runtime.util.DefaultPagingIterable;
+import org.apache.chemistry.opencmis.client.runtime.util.CollectionIterable;
import org.apache.chemistry.opencmis.commons.PropertyIds;
import org.apache.chemistry.opencmis.commons.api.Ace;
import org.apache.chemistry.opencmis.commons.api.Acl;
@@ -738,7 +738,7 @@ public abstract class AbstractPersistent
final RelationshipService relationshipService = getBinding().getRelationshipService();
final OperationContext ctxt = new OperationContextImpl(context);
- return new DefaultPagingIterable<Relationship>(new AbstractPageFetch<Relationship>() {
+ return new CollectionIterable<Relationship>(new AbstractPageFetch<Relationship>() {
@Override
protected AbstractPageFetch.PageFetchResult<Relationship> fetchPage(long skipCount) {
Modified: incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/PersistentFolderImpl.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/PersistentFolderImpl.java?rev=937510&r1=937509&r2=937510&view=diff
==============================================================================
--- incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/PersistentFolderImpl.java (original)
+++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/PersistentFolderImpl.java Fri Apr 23 20:34:58 2010
@@ -39,7 +39,7 @@ import org.apache.chemistry.opencmis.cli
import org.apache.chemistry.opencmis.client.api.Tree;
import org.apache.chemistry.opencmis.client.runtime.util.AbstractPageFetch;
import org.apache.chemistry.opencmis.client.runtime.util.ContainerImpl;
-import org.apache.chemistry.opencmis.client.runtime.util.DefaultPagingIterable;
+import org.apache.chemistry.opencmis.client.runtime.util.CollectionIterable;
import org.apache.chemistry.opencmis.commons.PropertyIds;
import org.apache.chemistry.opencmis.commons.api.Ace;
import org.apache.chemistry.opencmis.commons.api.ContentStream;
@@ -293,7 +293,7 @@ public class PersistentFolderImpl extend
final ObjectFactory objectFactory = getSession().getObjectFactory();
final OperationContext ctxt = new OperationContextImpl(context);
- return new DefaultPagingIterable<Document>(new AbstractPageFetch<Document>() {
+ return new CollectionIterable<Document>(new AbstractPageFetch<Document>() {
@Override
protected AbstractPageFetch.PageFetchResult<Document> fetchPage(long skipCount) {
@@ -352,7 +352,7 @@ public class PersistentFolderImpl extend
final ObjectFactory objectFactory = getSession().getObjectFactory();
final OperationContext ctxt = new OperationContextImpl(context);
- return new DefaultPagingIterable<CmisObject>(new AbstractPageFetch<CmisObject>() {
+ return new CollectionIterable<CmisObject>(new AbstractPageFetch<CmisObject>() {
@Override
protected AbstractPageFetch.PageFetchResult<CmisObject> fetchPage(long skipCount) {
Modified: incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/PersistentSessionImpl.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/PersistentSessionImpl.java?rev=937510&r1=937509&r2=937510&view=diff
==============================================================================
--- incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/PersistentSessionImpl.java (original)
+++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/PersistentSessionImpl.java Fri Apr 23 20:34:58 2010
@@ -47,7 +47,7 @@ import org.apache.chemistry.opencmis.cli
import org.apache.chemistry.opencmis.client.runtime.repository.PersistentObjectFactoryImpl;
import org.apache.chemistry.opencmis.client.runtime.util.AbstractPageFetch;
import org.apache.chemistry.opencmis.client.runtime.util.ContainerImpl;
-import org.apache.chemistry.opencmis.client.runtime.util.DefaultPagingIterable;
+import org.apache.chemistry.opencmis.client.runtime.util.CollectionIterable;
import org.apache.chemistry.opencmis.commons.SessionParameter;
import org.apache.chemistry.opencmis.commons.api.Ace;
import org.apache.chemistry.opencmis.commons.api.CmisBinding;
@@ -253,7 +253,7 @@ public class PersistentSessionImpl imple
final ObjectFactory objectFactory = getObjectFactory();
final OperationContext ctxt = new OperationContextImpl(context);
- return new DefaultPagingIterable<Document>(new AbstractPageFetch<Document>() {
+ return new CollectionIterable<Document>(new AbstractPageFetch<Document>() {
@Override
protected AbstractPageFetch.PageFetchResult<Document> fetchPage(long skipCount) {
@@ -518,7 +518,7 @@ public class PersistentSessionImpl imple
final RepositoryService repositoryService = getBinding().getRepositoryService();
final ObjectFactory objectFactory = this.getObjectFactory();
- return new DefaultPagingIterable<ObjectType>(new AbstractPageFetch<ObjectType>() {
+ return new CollectionIterable<ObjectType>(new AbstractPageFetch<ObjectType>() {
@Override
protected AbstractPageFetch.PageFetchResult<ObjectType> fetchPage(long skipCount) {
@@ -612,7 +612,7 @@ public class PersistentSessionImpl imple
final ObjectFactory objectFactory = this.getObjectFactory();
final OperationContext ctxt = new OperationContextImpl(context);
- return new DefaultPagingIterable<QueryResult>(new AbstractPageFetch<QueryResult>() {
+ return new CollectionIterable<QueryResult>(new AbstractPageFetch<QueryResult>() {
@Override
protected AbstractPageFetch.PageFetchResult<QueryResult> fetchPage(long skipCount) {
Added: incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/util/AbstractIterator.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/util/AbstractIterator.java?rev=937510&view=auto
==============================================================================
--- incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/util/AbstractIterator.java (added)
+++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/util/AbstractIterator.java Fri Apr 23 20:34:58 2010
@@ -0,0 +1,158 @@
+/*
+ * 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.chemistry.opencmis.client.runtime.util;
+
+import org.apache.chemistry.opencmis.client.api.PagingIterator;
+import org.apache.chemistry.opencmis.client.runtime.util.AbstractPageFetch.PageFetchResult;
+
+/**
+ * Abstract <code>PagingIterator</code> implementation.
+ *
+ * @param <T>
+ */
+public abstract class AbstractIterator<T> implements PagingIterator<T> {
+
+ private long skipCount;
+ private int skipOffset;
+ private AbstractPageFetch<T> pageFetch;
+
+ private PageFetchResult<T> page = null;
+ private Long totalItems = null;
+ private Boolean hasMoreItems = null;
+
+ /**
+ * Construct
+ *
+ * @param skipCount
+ * @param pageFetch
+ */
+ public AbstractIterator(long skipCount, AbstractPageFetch<T> pageFetch) {
+ this.skipCount = skipCount;
+ this.pageFetch = pageFetch;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.apache.chemistry.opencmis.client.api.util.PagingIterator#getPosition
+ * ()
+ */
+ public long getPosition() {
+ return skipCount + skipOffset;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.apache.chemistry.opencmis.client.api.PagingIterator#getTotalNumItems()
+ */
+ public long getTotalNumItems() {
+ if (totalItems == null) {
+ totalItems = -1L;
+ PageFetchResult<T> page = getCurrentPage();
+ if (page != null) {
+ // set number of items
+ if (page.getTotalItems() != null) {
+ totalItems = page.getTotalItems().longValue();
+ }
+ }
+ }
+ return totalItems;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.apache.chemistry.opencmis.client.api.PagingIterator#getHasMoreItems()
+ */
+ public boolean getHasMoreItems() {
+ if (hasMoreItems == null) {
+ hasMoreItems = false;
+ PageFetchResult<T> page = getCurrentPage();
+ if (page != null) {
+ if (page.getHasMoreItems() != null) {
+ hasMoreItems = page.getHasMoreItems().booleanValue();
+ }
+ }
+ }
+ return hasMoreItems;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.util.Iterator#remove()
+ */
+ public void remove() {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * Gets current skip count
+ *
+ * @return skip count
+ */
+ protected long getSkipCount() {
+ return skipCount;
+ }
+
+ /**
+ * Gets current skip offset (from skip count)
+ *
+ * @return skip offset
+ */
+ protected int getSkipOffset() {
+ return skipOffset;
+ }
+
+ /**
+ * Increment the skip offset by one
+ *
+ * @return incremented skip offset
+ */
+ protected int incrementSkipOffset() {
+ return skipOffset++;
+ }
+
+ /**
+ * Gets the current page of items within collection
+ *
+ * @return current page
+ */
+ protected PageFetchResult<T> getCurrentPage() {
+ if (page == null) {
+ page = pageFetch.fetchPage(skipCount);
+ }
+ return page;
+ }
+
+ /**
+ * Skip to the next page of items within collection
+ *
+ * @return next page
+ */
+ protected PageFetchResult<T> incrementPage() {
+ skipCount += skipOffset;
+ skipOffset = 0;
+ totalItems = null;
+ hasMoreItems = null;
+ page = pageFetch.fetchPage(skipCount);
+ return page;
+ }
+
+}
Propchange: incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/util/AbstractIterator.java
------------------------------------------------------------------------------
svn:eol-style = native
Copied: incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/util/CollectionIterable.java (from r937239, incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/util/DefaultPagingIterable.java)
URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/util/CollectionIterable.java?p2=incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/util/CollectionIterable.java&p1=incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/util/DefaultPagingIterable.java&r1=937239&r2=937510&rev=937510&view=diff
==============================================================================
--- incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/util/DefaultPagingIterable.java (original)
+++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/util/CollectionIterable.java Fri Apr 23 20:34:58 2010
@@ -18,14 +18,13 @@
*/
package org.apache.chemistry.opencmis.client.runtime.util;
-import java.util.Iterator;
-
import org.apache.chemistry.opencmis.client.api.PagingIterable;
+import org.apache.chemistry.opencmis.client.api.PagingIterator;
/**
- * Base <code>PagingIterable</code> implementation.
+ * CMIS Collection Iterable
*/
-public class DefaultPagingIterable<T> implements PagingIterable<T> {
+public class CollectionIterable<T> implements PagingIterable<T> {
private AbstractPageFetch<T> pageFetch;
private long skipCount;
@@ -35,7 +34,7 @@ public class DefaultPagingIterable<T> im
*
* @param pageFetch
*/
- public DefaultPagingIterable(AbstractPageFetch<T> pageFetch) {
+ public CollectionIterable(AbstractPageFetch<T> pageFetch) {
this(0, pageFetch);
}
@@ -45,7 +44,7 @@ public class DefaultPagingIterable<T> im
* @param position
* @param pageFetch
*/
- private DefaultPagingIterable(long position, AbstractPageFetch<T> pageFetch) {
+ protected CollectionIterable(long position, AbstractPageFetch<T> pageFetch) {
this.pageFetch = pageFetch;
this.skipCount = position;
}
@@ -55,18 +54,34 @@ public class DefaultPagingIterable<T> im
*
* @see java.lang.Iterable#iterator()
*/
- public Iterator<T> iterator() {
- return new DefaultPagingIterator<T>(skipCount, pageFetch);
+ public PagingIterator<T> iterator() {
+ return new CollectionIterator<T>(skipCount, pageFetch);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.chemistry.opencmis.client.api.PagingIterable#getIterator()
+ */
+ public PagingIterator<T> getIterator() {
+ return iterator();
}
/*
* (non-Javadoc)
*
- * @see
- * org.apache.chemistry.opencmis.client.api.util.PagingIterable#skipTo(long)
+ * @see org.apache.chemistry.opencmis.client.api.util.PagingIterable#skipTo(long)
*/
public PagingIterable<T> skipTo(long position) {
- return new DefaultPagingIterable<T>(position, pageFetch);
+ return new CollectionIterable<T>(position, pageFetch);
}
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.chemistry.opencmis.client.api.PagingIterable#getPage()
+ */
+ public PagingIterable<T> getPage() {
+ return new PageIterable<T>(skipCount, pageFetch);
+ }
}
Propchange: incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/util/CollectionIterable.java
------------------------------------------------------------------------------
svn:eol-style = native
Copied: incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/util/CollectionIterator.java (from r937239, incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/util/DefaultPagingIterator.java)
URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/util/CollectionIterator.java?p2=incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/util/CollectionIterator.java&p1=incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/util/DefaultPagingIterator.java&r1=937239&r2=937510&rev=937510&view=diff
==============================================================================
--- incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/util/DefaultPagingIterator.java (original)
+++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/util/CollectionIterator.java Fri Apr 23 20:34:58 2010
@@ -20,23 +20,14 @@ package org.apache.chemistry.opencmis.cl
import java.util.List;
-import org.apache.chemistry.opencmis.client.api.PagingIterator;
import org.apache.chemistry.opencmis.client.runtime.util.AbstractPageFetch.PageFetchResult;
/**
- * Base <code>PagingIterator</code> implementation.
+ * Iterator for iterating over all items in a CMIS Collection.
*
* @param <T>
*/
-public class DefaultPagingIterator<T> implements PagingIterator<T> {
-
- private long skipCount;
- private int skipOffset = 0;
-
- private AbstractPageFetch<T> pageFetch;
-
- private Long totalItems = null;
- private PageFetchResult<T> page = null;
+public class CollectionIterator<T> extends AbstractIterator<T> {
/**
* Construct
@@ -44,42 +35,8 @@ public class DefaultPagingIterator<T> im
* @param skipCount
* @param pageFetch
*/
- public DefaultPagingIterator(long skipCount, AbstractPageFetch<T> pageFetch) {
- this.skipCount = skipCount;
- this.pageFetch = pageFetch;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
- * org.apache.chemistry.opencmis.client.api.util.PagingIterator#getPosition
- * ()
- */
- public long getPosition() {
- return skipCount + skipOffset;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
- * org.apache.chemistry.opencmis.client.api.util.PagingIterator#getTotalNumItems
- * ()
- */
- public long getTotalNumItems() {
- if (totalItems == null) {
- PageFetchResult<T> page = getPage();
- if (page != null) {
- // set number of items
- if (page.getTotalItems() != null) {
- totalItems = page.getTotalItems().longValue();
- } else {
- totalItems = -1L;
- }
- }
- }
- return totalItems;
+ public CollectionIterator(long skipCount, AbstractPageFetch<T> pageFetch) {
+ super(skipCount, pageFetch);
}
/*
@@ -88,7 +45,17 @@ public class DefaultPagingIterator<T> im
* @see java.util.Iterator#hasNext()
*/
public boolean hasNext() {
- if (!hasMoreItems()) {
+ PageFetchResult<T> page = getCurrentPage();
+ if (page == null) {
+ return false;
+ }
+
+ List<T> items = page.getPage();
+ if (items != null && getSkipOffset() < items.size()) {
+ return true;
+ }
+
+ if (!getHasMoreItems()) {
return false;
}
@@ -98,7 +65,7 @@ public class DefaultPagingIterator<T> im
return true;
}
- return (skipCount + skipOffset) < totalItems;
+ return (getSkipCount() + getSkipOffset()) < totalItems;
}
/*
@@ -107,60 +74,26 @@ public class DefaultPagingIterator<T> im
* @see java.util.Iterator#next()
*/
public T next() {
- PageFetchResult<T> currentPage = getPage();
- // skipOffset++;
+ PageFetchResult<T> page = getCurrentPage();
+ if (page == null) {
+ return null;
+ }
- List<T> items = currentPage.getPage();
+ List<T> items = page.getPage();
if (items == null || items.isEmpty()) {
return null;
}
- if (skipOffset == items.size()) {
- skipCount += skipOffset;
- skipOffset = 0;
- this.page = pageFetch.fetchPage(skipCount);
- this.totalItems = null;
- currentPage = this.page;
- if (currentPage != null) {
- items = currentPage.getPage();
- }
+ if (getSkipOffset() == items.size()) {
+ page = incrementPage();
+ items = page == null ? null : page.getPage();
}
- if (items == null || items.isEmpty() || skipOffset == items.size()) {
+ if (items == null || items.isEmpty() || getSkipOffset() == items.size()) {
return null;
}
- return items.get(skipOffset++);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see java.util.Iterator#remove()
- */
- public void remove() {
- throw new UnsupportedOperationException();
- }
-
- private boolean hasMoreItems() {
- PageFetchResult<T> page = getPage();
- if (page == null) {
- return false;
- }
- if (skipOffset < page.getPage().size()) {
- return true;
- }
- if (page.getHasMoreItems() != null) {
- return page.getHasMoreItems().booleanValue();
- }
- return false;
- }
-
- private PageFetchResult<T> getPage() {
- if (page == null) {
- page = pageFetch.fetchPage(skipCount);
- }
- return page;
+ return items.get(incrementSkipOffset());
}
}
Propchange: incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/util/CollectionIterator.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/util/PageIterable.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/util/PageIterable.java?rev=937510&view=auto
==============================================================================
--- incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/util/PageIterable.java (added)
+++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/util/PageIterable.java Fri Apr 23 20:34:58 2010
@@ -0,0 +1,86 @@
+/*
+ * 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.chemistry.opencmis.client.runtime.util;
+
+import org.apache.chemistry.opencmis.client.api.PagingIterable;
+import org.apache.chemistry.opencmis.client.api.PagingIterator;
+
+/**
+ * Iterable for a CMIS Collection Page
+ */
+public class PageIterable<T> implements PagingIterable<T> {
+
+ private AbstractPageFetch<T> pageFetch;
+ private long skipCount;
+
+ /**
+ * Construct
+ *
+ * @param pageFetch
+ */
+ public PageIterable(AbstractPageFetch<T> pageFetch) {
+ this(0, pageFetch);
+ }
+
+ /**
+ * Construct
+ *
+ * @param position
+ * @param pageFetch
+ */
+ protected PageIterable(long position, AbstractPageFetch<T> pageFetch) {
+ this.pageFetch = pageFetch;
+ this.skipCount = position;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.Iterable#iterator()
+ */
+ public PagingIterator<T> iterator() {
+ return new PageIterator<T>(skipCount, pageFetch);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.chemistry.opencmis.client.api.PagingIterable#getIterator()
+ */
+ public PagingIterator<T> getIterator() {
+ return iterator();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.chemistry.opencmis.client.api.util.PagingIterable#skipTo(long)
+ */
+ public PagingIterable<T> skipTo(long position) {
+ return new CollectionIterable<T>(position, pageFetch);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.apache.chemistry.opencmis.client.api.PagingIterable#getPage()
+ */
+ public PagingIterable<T> getPage() {
+ return new PageIterable<T>(skipCount, pageFetch);
+ }
+}
Propchange: incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/util/PageIterable.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/util/PageIterator.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/util/PageIterator.java?rev=937510&view=auto
==============================================================================
--- incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/util/PageIterator.java (added)
+++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/util/PageIterator.java Fri Apr 23 20:34:58 2010
@@ -0,0 +1,79 @@
+/*
+ * 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.chemistry.opencmis.client.runtime.util;
+
+import java.util.List;
+
+import org.apache.chemistry.opencmis.client.runtime.util.AbstractPageFetch.PageFetchResult;
+
+/**
+ * Iterator for iterating over a page of items in a CMIS Collection.
+ *
+ * @param <T>
+ */
+public class PageIterator<T> extends AbstractIterator<T> {
+
+ /**
+ * Construct
+ *
+ * @param skipCount
+ * @param pageFetch
+ */
+ public PageIterator(long skipCount, AbstractPageFetch<T> pageFetch) {
+ super(skipCount, pageFetch);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.util.Iterator#hasNext()
+ */
+ public boolean hasNext() {
+ PageFetchResult<T> page = getCurrentPage();
+ if (page == null) {
+ return false;
+ }
+
+ List<T> items = page.getPage();
+ if (items == null || getSkipOffset() >= items.size()) {
+ return false;
+ }
+
+ return true;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.util.Iterator#next()
+ */
+ public T next() {
+ PageFetchResult<T> page = getCurrentPage();
+ if (page == null) {
+ return null;
+ }
+
+ List<T> items = page.getPage();
+ if (items == null || items.isEmpty() || getSkipOffset() == items.size()) {
+ return null;
+ }
+
+ return items.get(incrementSkipOffset());
+ }
+}
Propchange: incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/util/PageIterator.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/test/java/org/apache/chemistry/opencmis/client/runtime/PagingListTest.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/test/java/org/apache/chemistry/opencmis/client/runtime/PagingListTest.java?rev=937510&r1=937509&r2=937510&view=diff
==============================================================================
--- incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/test/java/org/apache/chemistry/opencmis/client/runtime/PagingListTest.java (original)
+++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/test/java/org/apache/chemistry/opencmis/client/runtime/PagingListTest.java Fri Apr 23 20:34:58 2010
@@ -28,7 +28,7 @@ import java.util.List;
import org.apache.chemistry.opencmis.client.api.PagingIterable;
import org.apache.chemistry.opencmis.client.api.PagingIterator;
import org.apache.chemistry.opencmis.client.runtime.util.AbstractPageFetch;
-import org.apache.chemistry.opencmis.client.runtime.util.DefaultPagingIterable;
+import org.apache.chemistry.opencmis.client.runtime.util.CollectionIterable;
import org.junit.Test;
public class PagingListTest {
@@ -38,7 +38,7 @@ public class PagingListTest {
private String[] data0 = {};
private PagingIterable<String> getIterable(final String[] data, final long pageSize) {
- return new DefaultPagingIterable<String>(new AbstractPageFetch<String>() {
+ return new CollectionIterable<String>(new AbstractPageFetch<String>() {
@Override
protected PageFetchResult<String> fetchPage(long skipCount) {
@@ -118,7 +118,37 @@ public class PagingListTest {
}
@Test
+ public void loopPage() {
+ this.loopPage(this.data10, 0, 5);
+ this.loopPage(this.data10, 1, 5);
+ this.loopPage(this.data10, 2, 5);
+ this.loopPage(this.data10, 3, 5);
+
+ this.loopPage(this.data10, 8, 5);
+ this.loopPage(this.data10, 9, 5);
+ this.loopPage(this.data10, 10, 5);
+ // this.loopPage(100, 5); skip out of bound
+
+ // this.loopPage(0, 0);
+ this.loopPage(this.data10, 0, 1);
+ this.loopPage(this.data10, 0, 10);
+ this.loopPage(this.data10, 0, 100);
+
+ // this.loopPage(0, 0);
+ this.loopPage(this.data10, 10, 1);
+ this.loopPage(this.data10, 10, 10);
+ this.loopPage(this.data10, 10, 100);
+
+ this.loopPage(this.data1, 0, 5);
+ this.loopPage(this.data1, 1, 5);
+
+ this.loopPage(this.data0, 0, 5);
+ }
+
+ @Test
public void totalNumItems() {
+ System.out.println("\ntotalNumItems");
+
int pageSize = 5;
PagingIterable<String> p = this.getIterable(this.data10, pageSize);
assertNotNull(p);
@@ -132,6 +162,23 @@ public class PagingListTest {
assertEquals(this.data10.length, i.getTotalNumItems());
}
+ @Test
+ public void totalHasMoreItems() {
+ System.out.println("\ntotalHasMoreItems");
+
+ int pageSize = 5;
+ PagingIterable<String> p = this.getIterable(this.data10, pageSize);
+ assertNotNull(p);
+ PagingIterator<String> i = (PagingIterator<String>) p.iterator();
+ assertNotNull(i);
+ assertEquals(true, i.getHasMoreItems());
+ for (int idx = 0; i.hasNext() && idx < (pageSize + 1); idx++) {
+ i.next();
+ }
+ assertEquals(pageSize + 1, i.getPosition());
+ assertEquals(false, i.getHasMoreItems());
+ }
+
private void loopSkip(String[] data, int skipCount, int pageSize) {
System.out.println("\nloopSkip (" + skipCount + ", " + pageSize + ")");
@@ -160,6 +207,7 @@ public class PagingListTest {
int count = 0;
for (String s : p) {
assertNotNull(s);
+ assertEquals("A" + count, s);
System.out.print(s + " ");
count++;
}
@@ -167,4 +215,23 @@ public class PagingListTest {
assertEquals(data.length, count);
}
+ private void loopPage(String[] data, int skipCount, int pageSize) {
+ System.out.println("\nloopPage (" + skipCount + ", " + pageSize + ")");
+
+ PagingIterable<String> p = this.getIterable(data, pageSize);
+ assertNotNull(p);
+ PagingIterable<String> pp = p.skipTo(skipCount).getPage();
+ assertNotNull(pp);
+
+ int count = 0;
+ for (String s : pp) {
+ assertNotNull(s);
+ assertEquals("A" + (count + skipCount), s);
+ System.out.print(s + " ");
+ count++;
+ }
+ System.out.print("\n");
+ assertEquals(Math.min(data.length - skipCount, pageSize), count);
+ }
+
}