Package com.gs.collections.impl.utility.internal.primitive

Source Code of com.gs.collections.impl.utility.internal.primitive.ShortIterableIterate

/*
* Copyright 2014 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.utility.internal.primitive;

import java.io.IOException;
import java.util.Collection;

import com.gs.collections.api.ShortIterable;
import com.gs.collections.api.block.function.primitive.ShortToObjectFunction;
import com.gs.collections.api.block.function.primitive.ObjectShortToObjectFunction;
import com.gs.collections.api.block.predicate.primitive.ShortPredicate;
import com.gs.collections.api.block.procedure.primitive.ShortProcedure;
import com.gs.collections.api.collection.primitive.MutableShortCollection;
import com.gs.collections.api.iterator.ShortIterator;

/**
* This file was automatically generated from template file primitiveIterableIterate.stg.
*
* @since 5.0
*/
public final class ShortIterableIterate
{
    private ShortIterableIterate()
    {
        throw new AssertionError("Suppress default constructor for noninstantiability");
    }

    public static boolean isEmpty(ShortIterable iterable)
    {
        return !iterable.shortIterator().hasNext();
    }

    public static boolean notEmpty(ShortIterable iterable)
    {
        return !ShortIterableIterate.isEmpty(iterable);
    }

    public static void forEach(ShortIterable iterable, ShortProcedure procedure)
    {
        ShortIteratorIterate.forEach(iterable.shortIterator(), procedure);
    }

    public static <R extends MutableShortCollection> R select(ShortIterable iterable, ShortPredicate predicate, R targetCollection)
    {
        return ShortIteratorIterate.select(iterable.shortIterator(), predicate, targetCollection);
    }

    public static <R extends MutableShortCollection> R reject(ShortIterable iterable, ShortPredicate predicate, R targetCollection)
    {
        return ShortIteratorIterate.reject(iterable.shortIterator(), predicate, targetCollection);
    }

    public static <V, R extends Collection<V>> R collect(
            ShortIterable iterable,
            ShortToObjectFunction<? extends V> function,
            R targetCollection)
    {
        return ShortIteratorIterate.collect(iterable.shortIterator(), function, targetCollection);
    }

    public static short detectIfNone(ShortIterable iterable, ShortPredicate predicate, short ifNone)
    {
        return ShortIteratorIterate.detectIfNone(iterable.shortIterator(), predicate, ifNone);
    }

    public static int count(ShortIterable iterable, ShortPredicate predicate)
    {
        return ShortIteratorIterate.count(iterable.shortIterator(), predicate);
    }

    public static boolean anySatisfy(ShortIterable iterable, ShortPredicate predicate)
    {
        return ShortIteratorIterate.anySatisfy(iterable.shortIterator(), predicate);
    }

    public static boolean allSatisfy(ShortIterable iterable, ShortPredicate predicate)
    {
        return ShortIteratorIterate.allSatisfy(iterable.shortIterator(), predicate);
    }

    public static boolean noneSatisfy(ShortIterable iterable, ShortPredicate predicate)
    {
        return ShortIteratorIterate.noneSatisfy(iterable.shortIterator(), predicate);
    }

    public static long sum(ShortIterable iterable)
    {
        return ShortIteratorIterate.sum(iterable.shortIterator());
    }

    public static short max(ShortIterable iterable)
    {
        return ShortIteratorIterate.max(iterable.shortIterator());
    }

    public static short maxIfEmpty(ShortIterable iterable, short ifEmpty)
    {
        if (ShortIterableIterate.isEmpty(iterable))
        {
            return ifEmpty;
        }
        return ShortIteratorIterate.max(iterable.shortIterator());
    }

    public static short min(ShortIterable iterable)
    {
        return ShortIteratorIterate.min(iterable.shortIterator());
    }

    public static short minIfEmpty(ShortIterable iterable, short ifEmpty)
    {
        if (ShortIterableIterate.isEmpty(iterable))
        {
            return ifEmpty;
        }
        return ShortIteratorIterate.min(iterable.shortIterator());
    }

    public static void appendString(
            ShortIterable iterable,
            Appendable appendable,
            String start,
            String separator,
            String end)
    {
        try
        {
            appendable.append(start);

            ShortIterator iterator = iterable.shortIterator();
            if (iterator.hasNext())
            {
                appendable.append(stringValueOfItem(iterable, iterator.next()));
                while (iterator.hasNext())
                {
                    appendable.append(separator);
                    appendable.append(stringValueOfItem(iterable, iterator.next()));
                }
            }

            appendable.append(end);
        }
        catch (IOException e)
        {
            throw new RuntimeException(e);
        }
    }

    public static <T> T injectInto(ShortIterable iterable, T injectedValue, ObjectShortToObjectFunction<? super T, ? extends T> function)
    {
        return ShortIteratorIterate.injectInto(iterable.shortIterator(), injectedValue, function);
    }

    private static <T> String stringValueOfItem(ShortIterable iterable, T item)
    {
        return item == iterable
                ? "(this " + iterable.getClass().getSimpleName() + ')'
                : String.valueOf(item);
    }
}
TOP

Related Classes of com.gs.collections.impl.utility.internal.primitive.ShortIterableIterate

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.