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

com.gs.collections.api.ordered.ReversibleIterable Maven / Gradle / Ivy

/*
 * Copyright 2015 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.api.ordered;

import com.gs.collections.api.LazyIterable;
import com.gs.collections.api.block.function.Function;
import com.gs.collections.api.block.function.Function2;
import com.gs.collections.api.block.function.primitive.BooleanFunction;
import com.gs.collections.api.block.function.primitive.ByteFunction;
import com.gs.collections.api.block.function.primitive.CharFunction;
import com.gs.collections.api.block.function.primitive.DoubleFunction;
import com.gs.collections.api.block.function.primitive.FloatFunction;
import com.gs.collections.api.block.function.primitive.IntFunction;
import com.gs.collections.api.block.function.primitive.LongFunction;
import com.gs.collections.api.block.function.primitive.ShortFunction;
import com.gs.collections.api.block.predicate.Predicate;
import com.gs.collections.api.block.predicate.Predicate2;
import com.gs.collections.api.block.procedure.Procedure;
import com.gs.collections.api.multimap.ordered.ReversibleIterableMultimap;
import com.gs.collections.api.ordered.primitive.ReversibleBooleanIterable;
import com.gs.collections.api.ordered.primitive.ReversibleByteIterable;
import com.gs.collections.api.ordered.primitive.ReversibleCharIterable;
import com.gs.collections.api.ordered.primitive.ReversibleDoubleIterable;
import com.gs.collections.api.ordered.primitive.ReversibleFloatIterable;
import com.gs.collections.api.ordered.primitive.ReversibleIntIterable;
import com.gs.collections.api.ordered.primitive.ReversibleLongIterable;
import com.gs.collections.api.ordered.primitive.ReversibleShortIterable;
import com.gs.collections.api.partition.ordered.PartitionReversibleIterable;
import com.gs.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(new Procedure()
     * {
     *     public void value(Person person)
     *     {
     *         LOGGER.info(person.getName());
     *     }
     * });
     * 
*/ void reverseForEach(Procedure procedure); /** * Returns a reversed view of this ReversibleIterable. */ LazyIterable asReversed(); /** * 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. */ 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. */ ReversibleIterable dropWhile(Predicate predicate); PartitionReversibleIterable partitionWhile(Predicate predicate); ReversibleIterable distinct(); ReversibleIterable select(Predicate predicate);

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

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

PartitionReversibleIterable partitionWith(Predicate2 predicate, P parameter); ReversibleIterable selectInstancesOf(Class clazz); ReversibleIterable collect(Function function); ReversibleIterable collectWith(Function2 function, P parameter); ReversibleIterable collectIf(Predicate predicate, Function function); ReversibleIterable flatCollect(Function> function); ReversibleBooleanIterable collectBoolean(BooleanFunction booleanFunction); ReversibleByteIterable collectByte(ByteFunction byteFunction); ReversibleCharIterable collectChar(CharFunction charFunction); ReversibleDoubleIterable collectDouble(DoubleFunction doubleFunction); ReversibleFloatIterable collectFloat(FloatFunction floatFunction); ReversibleIntIterable collectInt(IntFunction intFunction); ReversibleLongIterable collectLong(LongFunction longFunction); ReversibleShortIterable collectShort(ShortFunction shortFunction); ReversibleIterableMultimap groupBy(Function function); ReversibleIterableMultimap groupByEach(Function> function); ReversibleIterable> zip(Iterable that); ReversibleIterable> zipWithIndex(); }