View Javadoc

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      @Override
39      public ItemIterable<T> skipTo(long position) {
40          if (position != 0) {
41              throw new IllegalArgumentException(String.valueOf(position));
42          }
43          return this;
44      }
45  
46      @Override
47      public ItemIterable<T> getPage() {
48          return this;
49      }
50  
51      @Override
52      public ItemIterable<T> getPage(int maxNumItems) {
53          return this;
54      }
55  
56      @Override
57      @SuppressWarnings("unchecked")
58      public Iterator<T> iterator() {
59          return (Iterator<T>) EmptyIterator.INSTANCE;
60      }
61  
62      @Override
63      public long getPageNumItems() {
64          return 0;
65      }
66  
67      @Override
68      public boolean getHasMoreItems() {
69          return false;
70      }
71  
72      @Override
73      public long getTotalNumItems() {
74          return 0;
75      }
76  
77      /**
78       * An empty iterator.
79       */
80      public static class EmptyIterator<V> implements Iterator<V> {
81          public static final Iterator<?> INSTANCE = new EmptyIterator<Object>();
82  
83          @Override
84          public boolean hasNext() {
85              return false;
86          }
87  
88          @Override
89          public V next() {
90              throw new NoSuchElementException();
91          }
92  
93          @Override
94          public void remove() {
95              throw new UnsupportedOperationException();
96          }
97      }
98  
99  }