org.xmlunit.util.Linqy Maven / Gradle / Ivy
The newest version!
/*
This file is licensed 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.xmlunit.util;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.NoSuchElementException;
/**
* A couple of (functional) sequence processing constructs.
*/
public final class Linqy {
private Linqy() { /* no instances */ }
/**
* Turns the iterable into a list.
* @param i the iterable
* @param element type
* @return a list containing all elements of the Iterable passed in
*/
public static List asList(Iterable i) {
if (i instanceof Collection) {
return new ArrayList((Collection) i);
}
ArrayList a = new ArrayList();
for (E e : i) {
a.add(e);
}
return a;
}
/**
* Turns an iterable into its type-safe cousin.
* @param i the iterable
* @param target element type
* @return a type-safe iterable containing all elements of the Iterable passed in
*/
public static Iterable cast(final Iterable i) {
return map(i, new Mapper