net.sf.staccatocommons.collections.stream.internal.CollectionStream Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of staccatissimo-collections Show documentation
Show all versions of staccatissimo-collections Show documentation
Collections library of the Staccatissimo project, focused on providing new abstractions
that mix object oriented and functional programming style for dealing with iterable objects.
The newest version!
/**
* Copyright (c) 2010-2012, The StaccatoCommons Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; version 3 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*/
package net.sf.staccatocommons.collections.stream.internal;
import java.util.Collection;
import java.util.List;
import java.util.Set;
import net.sf.staccatocommons.collections.iterable.Iterables;
import net.sf.staccatocommons.iterators.thriter.Thriterator;
import net.sf.staccatocommons.iterators.thriter.Thriterators;
import net.sf.staccatocommons.restrictions.check.NonNull;
/**
*
* @author flbulgarelli
*
* @param
*/
public class CollectionStream extends StrictStream {
private final Collection extends A> collection;
/**
* Creates a new {@link CollectionStream}
*
* @param collection
* the collection to wrap
*/
public CollectionStream(@NonNull Collection extends A> collection) {
this.collection = collection;
}
@Override
public final int size() {
return collection.size();
}
@Override
public final boolean contains(A element) {
return collection.contains(element);
}
@Override
public boolean isEmpty() {
return collection.isEmpty();
}
@Override
public final Thriterator iterator() {
return Thriterators.from(collection.iterator());
}
@Override
public List toList() {
return Iterables.toList(getCollection());
}
public Set toSet() {
return Iterables.toSet(getCollection());
}
@Override
public A[] toArray(Class super A> clazz) {
return toArray(clazz, getCollection());
}
protected Collection getCollection() {
return (Collection) collection;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy