This project has retired. For details please refer to its Attic page.
AbstractPageFetcher xref

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   * http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.chemistry.opencmis.client.runtime.util;
20  
21  import java.math.BigInteger;
22  import java.util.List;
23  
24  /**
25   * Abstract page fetcher.
26   *
27   * @param <T> the type of items fetched
28   */
29  public abstract class AbstractPageFetcher<T> {
30  
31      protected long maxNumItems;
32  
33      protected AbstractPageFetcher(long maxNumItems) {
34          this.maxNumItems = maxNumItems;
35      }
36  
37      /**
38       * Fetches the given page from the server.
39       *
40       * @param skipCount initial offset where to start fetching
41       */
42      protected abstract Page<T> fetchPage(long skipCount);
43  
44      /**
45       * A fetched page.
46       *
47       * @param <T> the type of items fetched
48       */
49      public static class Page<T> {
50          private final List<T> items;
51          private final Long totalNumItems;
52          private final Boolean hasMoreItems;
53  
54          public Page(List<T> items, BigInteger totalNumItems, Boolean hasMoreItems) {
55              this.items = items;
56              this.totalNumItems = totalNumItems == null ? null
57                      : Long.valueOf(totalNumItems.longValue());
58              this.hasMoreItems = hasMoreItems;
59          }
60  
61          public Page(List<T> items, long totalNumItems, boolean hasMoreItems) {
62              this.items = items;
63              this.totalNumItems = Long.valueOf(totalNumItems);
64              this.hasMoreItems = Boolean.valueOf(hasMoreItems);
65          }
66  
67          public List<T> getItems() {
68              return items;
69          }
70  
71          public Long getTotalNumItems() {
72              return totalNumItems;
73          }
74  
75          public Boolean getHasMoreItems() {
76              return hasMoreItems;
77          }
78      }
79  
80      public void setMaxNumItems(int maxNumItems) {
81          this.maxNumItems = maxNumItems;
82      }
83  
84  }