All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.eclipse.collections.api.ordered.ReversibleIterable Maven / Gradle / Ivy

There is a newer version: 12.0.0.M3
Show newest version
/*
 * Copyright (c) 2018 Goldman Sachs and others.
 * 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.api.ordered;

import org.eclipse.collections.api.LazyIterable;
import org.eclipse.collections.api.block.function.Function;
import org.eclipse.collections.api.block.function.Function2;
import org.eclipse.collections.api.block.function.primitive.BooleanFunction;
import org.eclipse.collections.api.block.function.primitive.ByteFunction;
import org.eclipse.collections.api.block.function.primitive.CharFunction;
import org.eclipse.collections.api.block.function.primitive.DoubleFunction;
import org.eclipse.collections.api.block.function.primitive.FloatFunction;
import org.eclipse.collections.api.block.function.primitive.IntFunction;
import org.eclipse.collections.api.block.function.primitive.LongFunction;
import org.eclipse.collections.api.block.function.primitive.ObjectIntToObjectFunction;
import org.eclipse.collections.api.block.function.primitive.ShortFunction;
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.primitive.ObjectIntProcedure;
import org.eclipse.collections.api.multimap.ordered.ReversibleIterableMultimap;
import org.eclipse.collections.api.ordered.primitive.ReversibleBooleanIterable;
import org.eclipse.collections.api.ordered.primitive.ReversibleByteIterable;
import org.eclipse.collections.api.ordered.primitive.ReversibleCharIterable;
import org.eclipse.collections.api.ordered.primitive.ReversibleDoubleIterable;
import org.eclipse.collections.api.ordered.primitive.ReversibleFloatIterable;
import org.eclipse.collections.api.ordered.primitive.ReversibleIntIterable;
import org.eclipse.collections.api.ordered.primitive.ReversibleLongIterable;
import org.eclipse.collections.api.ordered.primitive.ReversibleShortIterable;
import org.eclipse.collections.api.partition.ordered.PartitionReversibleIterable;
import org.eclipse.collections.api.tuple.Pair;

/**
 * A ReversibleIterable is an ordered iterable that you can iterate over forwards or backwards. Besides being ordered,
 * it has methods that support efficient iteration from the end, including {@link #asReversed()} and
 * {@link #reverseForEach(Procedure)}.
 *
 * @since 5.0
 */
public interface ReversibleIterable extends OrderedIterable
{
    /**
     * Evaluates the procedure for each element of the list iterating in reverse order.
     *
     * 
e.g.
     * people.reverseForEach(person -> LOGGER.info(person.getName()));
     * 
*/ default void reverseForEach(Procedure procedure) { if (this.notEmpty()) { this.forEach(this.size() - 1, 0, procedure); } } /** * Evaluates the procedure for each element and it's index in reverse order. *
e.g.
     * people.reverseForEachWithIndex((person, index) ->
     *         LOGGER.info("Index: " + index + " person: " + person.getName()));
     * 
* * @since 9.0.0 */ default void reverseForEachWithIndex(ObjectIntProcedure procedure) { if (this.notEmpty()) { this.forEachWithIndex(this.size() - 1, 0, procedure); } } /** * Returns a reversed view of this ReversibleIterable. */ default LazyIterable asReversed() { throw new UnsupportedOperationException(this.getClass().getSimpleName() + ".asReversed() not implemented yet"); } /** * Returns a new ReversibleIterable in reverse order. * * @since 6.0.0 */ ReversibleIterable toReversed(); /** * Returns the index of the last element of the {@code ReversibleIterable} for which the {@code predicate} evaluates to true. * Returns -1 if no element evaluates true for the {@code predicate}. * * @since 6.0 */ int detectLastIndex(Predicate predicate); /** * Returns the first {@code count} elements of the iterable * or all the elements in the iterable if {@code count} is greater than the length of * the iterable. * * @param count the number of items to take. * @throws IllegalArgumentException if {@code count} is less than zero * @since 6.0 */ ReversibleIterable take(int count); /** * Returns the initial elements that satisfy the Predicate. Short circuits at the first element which does not * satisfy the Predicate. */ @Override ReversibleIterable takeWhile(Predicate predicate); /** * Returns an iterable after skipping the first {@code count} elements * or an empty iterable if the {@code count} is greater than the length of the iterable. * * @param count the number of items to drop. * @throws IllegalArgumentException if {@code count} is less than zero * @since 6.0 */ ReversibleIterable drop(int count); /** * Returns the final elements that do not satisfy the Predicate. Short circuits at the first element which does * satisfy the Predicate. */ @Override ReversibleIterable dropWhile(Predicate predicate); @Override PartitionReversibleIterable partitionWhile(Predicate predicate); @Override ReversibleIterable distinct(); @Override ReversibleIterable tap(Procedure procedure); @Override ReversibleIterable select(Predicate predicate); @Override

ReversibleIterable selectWith(Predicate2 predicate, P parameter); @Override ReversibleIterable reject(Predicate predicate); @Override

ReversibleIterable rejectWith(Predicate2 predicate, P parameter); @Override PartitionReversibleIterable partition(Predicate predicate); @Override

PartitionReversibleIterable partitionWith(Predicate2 predicate, P parameter); @Override ReversibleIterable selectInstancesOf(Class clazz); @Override ReversibleIterable collect(Function function); /** * @since 9.1. */ @Override default ReversibleIterable collectWithIndex(ObjectIntToObjectFunction function) { int[] index = {0}; return this.collect(each -> function.valueOf(each, index[0]++)); } @Override ReversibleIterable collectWith(Function2 function, P parameter); @Override ReversibleIterable collectIf(Predicate predicate, Function function); @Override ReversibleIterable flatCollect(Function> function); /** * @since 9.2 */ @Override default ReversibleIterable flatCollectWith(Function2> function, P parameter) { return this.flatCollect(each -> function.apply(each, parameter)); } @Override ReversibleBooleanIterable collectBoolean(BooleanFunction booleanFunction); @Override ReversibleByteIterable collectByte(ByteFunction byteFunction); @Override ReversibleCharIterable collectChar(CharFunction charFunction); @Override ReversibleDoubleIterable collectDouble(DoubleFunction doubleFunction); @Override ReversibleFloatIterable collectFloat(FloatFunction floatFunction); @Override ReversibleIntIterable collectInt(IntFunction intFunction); @Override ReversibleLongIterable collectLong(LongFunction longFunction); @Override ReversibleShortIterable collectShort(ShortFunction shortFunction); @Override ReversibleIterableMultimap groupBy(Function function); @Override ReversibleIterableMultimap groupByEach(Function> function); @Override ReversibleIterable> zip(Iterable that); @Override ReversibleIterable> zipWithIndex(); }