org.eclipse.collections.impl.lazy.LazyIterableAdapter Maven / Gradle / Ivy
Show all versions of eclipse-collections Show documentation
/*
* Copyright (c) 2021 Goldman Sachs.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Eclipse Distribution License v. 1.0 which accompany this distribution.
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*/
package org.eclipse.collections.impl.lazy;
import java.util.Collection;
import java.util.Iterator;
import java.util.Optional;
import org.eclipse.collections.api.LazyIterable;
import org.eclipse.collections.api.block.function.Function;
import org.eclipse.collections.api.block.predicate.Predicate;
import org.eclipse.collections.api.block.predicate.Predicate2;
import org.eclipse.collections.api.block.procedure.Procedure;
import org.eclipse.collections.api.block.procedure.Procedure2;
import org.eclipse.collections.api.block.procedure.primitive.ObjectIntProcedure;
import org.eclipse.collections.impl.UnmodifiableIteratorAdapter;
import org.eclipse.collections.impl.utility.Iterate;
import org.eclipse.collections.impl.utility.LazyIterate;
/**
* A LazyIterableAdapter wraps any iterable with the LazyIterable interface.
*/
public class LazyIterableAdapter
extends AbstractLazyIterable
{
private final Iterable adapted;
public LazyIterableAdapter(Iterable newAdapted)
{
this.adapted = newAdapted;
}
@Override
public void each(Procedure super T> procedure)
{
Iterate.forEach(this.adapted, procedure);
}
@Override
public void forEachWithIndex(ObjectIntProcedure super T> objectIntProcedure)
{
Iterate.forEachWithIndex(this.adapted, objectIntProcedure);
}
@Override
public void forEachWith(Procedure2 super T, ? super P> procedure, P parameter)
{
Iterate.forEachWith(this.adapted, procedure, parameter);
}
@Override
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 takeWhile(Predicate super T> predicate)
{
return LazyIterate.takeWhile(this.adapted, predicate);
}
@Override
public LazyIterable dropWhile(Predicate super T> predicate)
{
return LazyIterate.dropWhile(this.adapted, predicate);
}
@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);
}
@Override
public boolean isEmpty()
{
return Iterate.isEmpty(this.adapted);
}
@Override
public boolean anySatisfy(Predicate super T> predicate)
{
return Iterate.anySatisfy(this.adapted, predicate);
}
@Override
public boolean allSatisfy(Predicate super T> predicate)
{
return Iterate.allSatisfy(this.adapted, predicate);
}
@Override
public boolean noneSatisfy(Predicate super T> predicate)
{
return Iterate.noneSatisfy(this.adapted, predicate);
}
@Override
public boolean anySatisfyWith(Predicate2 super T, ? super P> predicate, P parameter)
{
return Iterate.anySatisfyWith(this.adapted, predicate, parameter);
}
@Override
public
boolean allSatisfyWith(Predicate2 super T, ? super P> predicate, P parameter)
{
return Iterate.allSatisfyWith(this.adapted, predicate, parameter);
}
@Override
public
boolean noneSatisfyWith(Predicate2 super T, ? super P> predicate, P parameter)
{
return Iterate.noneSatisfyWith(this.adapted, predicate, parameter);
}
@Override
public T getFirst()
{
return Iterate.getFirst(this.adapted);
}
@Override
public T getLast()
{
return Iterate.getLast(this.adapted);
}
@Override
public T detect(Predicate super T> predicate)
{
return Iterate.detect(this.adapted, predicate);
}
@Override
public
T detectWith(Predicate2 super T, ? super P> predicate, P parameter)
{
return Iterate.detectWith(this.adapted, predicate, parameter);
}
@Override
public Optional detectOptional(Predicate super T> predicate)
{
return Iterate.detectOptional(this.adapted, predicate);
}
@Override
public Optional detectWithOptional(Predicate2 super T, ? super P> predicate, P parameter)
{
return Iterate.detectWithOptional(this.adapted, predicate, parameter);
}
}