com.github.jonross.seq4j.Fns.java Source code

Java tutorial

Introduction

Here is the source code for com.github.jonross.seq4j.Fns.java

Source

/*
 * Copyright (c) 2012, Jonathan Ross <jonross@alum.mit.edu>
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included
 * in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 * DEALINGS IN THE SOFTWARE.
 */

package com.github.jonross.seq4j;

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

import com.google.common.base.Function;
import com.google.common.base.Functions;
import com.google.common.base.Predicate;

/**
 * This class provides pass-throughs to many of the commonly used static {@link Function} and
 * {@link Predicate} builders in Guava and Seq4J, so you need no longer worry about which
 * class to <code>static import</code>.  The name is very short so that if you don't
 * <code>static import</code> it, it still won't clutter your code.
 */

public class Fns {
    /** @see CollectionHelpers#addTo(Collection) */
    public static <T> Function<T, Void> addTo(final Collection<T> collection) {
        return SeqMisc.addTo(collection);
    }

    /** @see CollectionHelpers#addTo(Map, Function) */
    public static <T, K> Function<T, Void> addTo(final Map<K, T> map,
            final Function<? super T, ? extends K> keyMaker) {
        return SeqMisc.addTo(map, keyMaker);
    }

    /** @see Functions#toStringFunction() */
    public static Function<Object, String> asString() {
        return Functions.toStringFunction();
    }

    /** @see Functions#compose(Function, Function) */
    public static <A, B, C> Function<A, C> compose(Function<B, C> g, Function<A, ? extends B> f) {
        return Functions.compose(g, f);
    }

    /** @see SeqMisc#lookup(Map) */
    public static <K, V> Function<K, V> lookup(Map<K, V> map) {
        return SeqMisc.lookup(map);
    }

    /** @see SeqMisc#lookup(Map, Object) */
    public static <K, V> Function<K, V> lookup(Map<K, ? extends V> map, V defaultValue) {
        return SeqMisc.lookup(map, defaultValue);
    }

    /** @see SeqMisc#unique() */
    public static Predicate<Object> unique() {
        return SeqMisc.unique();
    }
}