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

com.gs.collections.impl.block.factory.Functions0 Maven / Gradle / Ivy

Go to download

GS Collections is a collections framework for Java. It has JDK-compatible List, Set and Map implementations with a rich API and set of utility classes that work with any JDK compatible Collections, Arrays, Maps or Strings. The iteration protocol was inspired by the Smalltalk collection framework.

There is a newer version: 7.0.3
Show newest version
/*
 * Copyright 2013 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.block.factory;

import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;

import com.gs.collections.api.bag.MutableBag;
import com.gs.collections.api.block.function.Function0;
import com.gs.collections.api.list.MutableList;
import com.gs.collections.api.map.MutableMap;
import com.gs.collections.api.set.MutableSet;
import com.gs.collections.impl.block.function.PassThruFunction0;
import com.gs.collections.impl.factory.Bags;
import com.gs.collections.impl.factory.Lists;
import com.gs.collections.impl.factory.Maps;
import com.gs.collections.impl.factory.Sets;

public final class Functions0
{
    private static final NewFastListFunction NEW_FAST_LIST_FUNCTION = new NewFastListFunction();
    private static final NewUnifiedSetFunction NEW_UNIFIED_SET_FUNCTION = new NewUnifiedSetFunction();
    private static final NewHashBagFunction NEW_HASH_BAG_FUNCTION = new NewHashBagFunction();
    private static final NewUnifiedMapFunction NEW_UNIFIED_MAP_FUNCTION = new NewUnifiedMapFunction();
    private static final NullFunction NULL_FUNCTION = new NullFunction();
    private static final AtomicIntegerZeroFunction ATOMIC_INTEGER_ZERO = new AtomicIntegerZeroFunction();
    private static final AtomicLongZeroFunction ATOMIC_LONG_ZERO = new AtomicLongZeroFunction();
    private static final IntegerZeroFunction INTEGER_ZERO = new IntegerZeroFunction();

    private Functions0()
    {
        throw new AssertionError("Suppress default constructor for noninstantiability");
    }

    public static  Function0> newFastList()
    {
        return (Function0>) NEW_FAST_LIST_FUNCTION;
    }

    public static  Function0> newUnifiedSet()
    {
        return (Function0>) NEW_UNIFIED_SET_FUNCTION;
    }

    public static  Function0> newHashBag()
    {
        return (Function0>) NEW_HASH_BAG_FUNCTION;
    }

    public static  Function0> newUnifiedMap()
    {
        return (Function0>) NEW_UNIFIED_MAP_FUNCTION;
    }

    public static  Function0 nullValue()
    {
        return (Function0) NULL_FUNCTION;
    }

    public static  Function0 value(T t)
    {
        return new PassThruFunction0(t);
    }

    public static Function0 zeroAtomicInteger()
    {
        return ATOMIC_INTEGER_ZERO;
    }

    public static Function0 zeroAtomicLong()
    {
        return ATOMIC_LONG_ZERO;
    }

    private static final class NewFastListFunction implements Function0>
    {
        private static final long serialVersionUID = 1L;

        public MutableList value()
        {
            return Lists.mutable.of();
        }
    }

    private static final class NewUnifiedMapFunction implements Function0>
    {
        private static final long serialVersionUID = 1L;

        public MutableMap value()
        {
            return Maps.mutable.of();
        }
    }

    private static final class NewUnifiedSetFunction implements Function0>
    {
        private static final long serialVersionUID = 1L;

        public MutableSet value()
        {
            return Sets.mutable.of();
        }
    }

    private static final class NewHashBagFunction implements Function0>
    {
        private static final long serialVersionUID = 1L;

        public MutableBag value()
        {
            return Bags.mutable.of();
        }
    }

    private static class NullFunction implements Function0
    {
        private static final long serialVersionUID = 1L;

        public T value()
        {
            return null;
        }
    }

    private static class IntegerZeroFunction implements Function0
    {
        private static final long serialVersionUID = 1L;

        public Integer value()
        {
            return Integer.valueOf(0);
        }
    }

    private static class AtomicIntegerZeroFunction implements Function0
    {
        private static final long serialVersionUID = 1L;

        public AtomicInteger value()
        {
            return new AtomicInteger(0);
        }
    }

    private static class AtomicLongZeroFunction implements Function0
    {
        private static final long serialVersionUID = 1L;

        public AtomicLong value()
        {
            return new AtomicLong(0);
        }
    }
}