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

io.polyglotted.common.util.CollUtil Maven / Gradle / Ivy

package io.polyglotted.common.util;

import com.google.common.base.Function;
import com.google.common.base.Predicate;
import com.google.common.collect.Collections2;
import com.google.common.collect.FluentIterable;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;

import java.util.Collection;
import java.util.List;
import java.util.Map;

import static com.google.common.base.Predicates.not;
import static io.polyglotted.common.util.NullUtil.nonNull;

@SuppressWarnings({"unused", "unchecked", "Guava", "StaticPseudoFunctionalStyleMethod", "ConstantConditions", "WeakerAccess"})
public abstract class CollUtil {

    public static  Map filterKeys(Map map, final Predicate predicate) { return Maps.filterKeys(map, predicate); }

    public static  Map filterKeysNeg(Map map, final Predicate predicate) { return Maps.filterKeys(map, not(predicate)); }

    public static  Map filterValues(Map map, final Predicate predicate) { return Maps.filterValues(map, predicate); }

    public static  Map filterValuesNeg(Map map, final Predicate pred) { return Maps.filterValues(map, not(pred)); }

    public static  Map uniqueIndex(Iterable values, Function function) { return Maps.uniqueIndex(values, function); }

    public static  Collection asColl(Object value, Collection defaulted) { return nonNull((Collection) value, defaulted); }

    public static  Collection filterColl(Collection coll, Predicate predicate) { return Collections2.filter(coll, predicate); }

    public static  Collection filterCollNeg(Collection coll, Predicate pred) { return Collections2.filter(coll, not(pred)); }

    public static  Collection transformColl(Collection coll, Function fn) { return Collections2.transform(coll, fn); }

    public static  List transformList(List list, Function fn) { return Lists.transform(list, fn); }

    public static  FluentIterable fluent(Iterable list) { return FluentIterable.from(list); }

    public static  FluentIterable transform(Iterable list, final Function fn) {
        return (FluentIterable) Iterables.transform(list, fn);
    }

    public static  FluentIterable filter(Iterable list, Predicate predicate) {
        return (FluentIterable) Iterables.filter(list, predicate);
    }

    public static  FluentIterable filterNeg(Iterable list, Predicate predicate) {
        return (FluentIterable) Iterables.filter(list, not(predicate));
    }

    public static  FluentIterable concat(Iterable... inputs) { return FluentIterable.concat(inputs); }

    public static  FluentIterable concat(Iterable a, Iterable b) { return FluentIterable.concat(a, b); }

    public static  T[] toArray(Iterable iterable, Class type) { return Iterables.toArray(iterable, type); }

    public static  E firstOf(Iterable list) { return firstOf(list, null); }

    public static  E firstOf(Iterable list, E defaulted) { return Iterables.getFirst(list, defaulted); }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy