com.gs.collections.impl.lazy.LazyIterableAdapter Maven / Gradle / Ivy
Show all versions of gs-collections Show documentation
/*
* Copyright 2011 Goldman Sachs.
*
* Licensed 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 com.gs.collections.impl.lazy;
import java.util.Collection;
import java.util.Iterator;
import com.gs.collections.api.LazyIterable;
import com.gs.collections.api.block.function.Function;
import com.gs.collections.api.block.predicate.Predicate;
import com.gs.collections.api.block.procedure.Procedure;
import com.gs.collections.api.block.procedure.Procedure2;
import com.gs.collections.api.block.procedure.primitive.ObjectIntProcedure;
import com.gs.collections.impl.UnmodifiableIteratorAdapter;
import com.gs.collections.impl.utility.Iterate;
import com.gs.collections.impl.utility.LazyIterate;
import net.jcip.annotations.Immutable;
/**
* A LazyIterableAdapter wraps any iterable with the LazyIterable interface.
*/
@Immutable
public class LazyIterableAdapter
extends AbstractLazyIterable
{
private final Iterable adapted;
public LazyIterableAdapter(Iterable newAdapted)
{
this.adapted = newAdapted;
}
public void forEach(Procedure super T> procedure)
{
Iterate.forEach(this.adapted, procedure);
}
public void forEachWithIndex(ObjectIntProcedure super T> objectIntProcedure)
{
Iterate.forEachWithIndex(this.adapted, objectIntProcedure);
}
public void forEachWith(Procedure2 super T, ? super P> procedure, P parameter)
{
Iterate.forEachWith(this.adapted, procedure, parameter);
}
public Iterator iterator()
{
return new UnmodifiableIteratorAdapter(this.adapted.iterator());
}
@Override
public > R into(R target)
{
Iterate.addAllIterable(this.adapted, target);
return target;
}
@Override
public LazyIterable select(Predicate super T> predicate)
{
return LazyIterate.select(this.adapted, predicate);
}
@Override
public LazyIterable reject(Predicate super T> predicate)
{
return LazyIterate.reject(this.adapted, predicate);
}
@Override
public LazyIterable collect(Function super T, ? extends V> function)
{
return LazyIterate.collect(this.adapted, function);
}
@Override
public LazyIterable flatCollect(Function super T, ? extends Iterable> function)
{
return LazyIterate.flatCollect(this.adapted, function);
}
@Override
public LazyIterable collectIf(Predicate super T> predicate, Function super T, ? extends V> function)
{
return LazyIterate.collectIf(this.adapted, predicate, function);
}
@Override
public LazyIterable take(int count)
{
return LazyIterate.take(this.adapted, count);
}
@Override
public LazyIterable drop(int count)
{
return LazyIterate.drop(this.adapted, count);
}
@Override
public LazyIterable distinct()
{
return LazyIterate.distinct(this.adapted);
}
@Override
public Object[] toArray()
{
return Iterate.toArray(this.adapted);
}
@Override
public int size()
{
return Iterate.sizeOf(this.adapted);
}
}