This project has retired. For details please refer to its Attic page.
EmptyItemIterable 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.util.Iterator;
22  import java.util.NoSuchElementException;
23  
24  import org.apache.chemistry.opencmis.client.api.ItemIterable;
25  
26  /**
27   * An empty item iterable.
28   */
29  public class EmptyItemIterable<T> implements ItemIterable<T> {
30  
31      public static final EmptyItemIterable<?> INSTANCE = new EmptyItemIterable<Object>();
32  
33      @SuppressWarnings("unchecked")
34      public static <U> EmptyItemIterable<U> instance() {
35          return (EmptyItemIterable<U>) INSTANCE;
36      }
37  
38      public ItemIterable<T> skipTo(long position) {
39          if (position != 0) {
40              throw new IllegalArgumentException(String.valueOf(position));
41          }
42          return this;
43      }
44  
45      public ItemIterable<T> getPage() {
46          return this;
47      }
48  
49      public ItemIterable<T> getPage(int maxNumItems) {
50          return this;
51      }
52  
53      @SuppressWarnings("unchecked")
54      public Iterator<T> iterator() {
55          return (Iterator<T>) EmptyIterator.INSTANCE;
56      }
57  
58      public long getPageNumItems() {
59          return 0;
60      }
61  
62      public boolean getHasMoreItems() {
63          return false;
64      }
65  
66      public long getTotalNumItems() {
67          return 0;
68      }
69  
70      /**
71       * An empty iterator.
72       */
73      public static class EmptyIterator<V> implements Iterator<V> {
74          public static final Iterator<?> INSTANCE = new EmptyIterator<Object>();
75  
76          public boolean hasNext() {
77              return false;
78          }
79  
80          public V next() {
81              throw new NoSuchElementException();
82          }
83  
84          public void remove() {
85              throw new UnsupportedOperationException();
86          }
87      }
88  
89  }