This project has retired. For details please refer to its Attic page.
Iterables 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  
20  package org.apache.chemistry.opencmis.jcr.util;
21  
22  import org.apache.commons.collections.iterators.EmptyIterator;
23  import org.apache.commons.collections.iterators.IteratorChain;
24  import org.apache.commons.collections.iterators.SingletonIterator;
25  
26  import java.util.Iterator;
27  
28  public class Iterables {
29      private Iterables() {}
30  
31      public static <T> Iterable<T> concat(final Iterable<T> it1, final Iterable<T> it2) {
32          return new Iterable<T>() {
33              @SuppressWarnings("unchecked")
34              public Iterator<T> iterator() {
35                  return new IteratorChain(it1.iterator(), it2.iterator());
36              }
37          };
38      }
39  
40      public static <T> Iterable<T> singleton(final T element) {
41          return new Iterable<T>() {
42              @SuppressWarnings("unchecked")
43              public Iterator<T> iterator() {
44                  return new SingletonIterator(element);
45              }
46          };
47      }
48  
49      public static <T> Iterable<T> empty() {
50          return new Iterable<T>() {
51              @SuppressWarnings("unchecked")
52              public Iterator<T> iterator() {
53                  return EmptyIterator.INSTANCE;
54              }
55          };
56      }
57  }