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

org.neo4j.helpers.Functions Maven / Gradle / Ivy

/*
 * Copyright (c) 2002-2015 "Neo Technology,"
 * Network Engine for Objects in Lund AB [http://neotechnology.com]
 *
 * This file is part of Neo4j.
 *
 * Neo4j is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see .
 */
package org.neo4j.helpers;

import java.util.Map;

/**
 * @deprecated use {@link org.neo4j.function.Functions} instead.
 */
@Deprecated
public final class Functions
{
    @Deprecated
    public static  Function map( final Map map )
    {
        return new Function()
        {
            @Override
            public To apply( From from )
            {
                return map.get( from );
            }
        };
    }

    @Deprecated
    public static  Function withDefaults( final org.neo4j.function.Function defaults, final org.neo4j.function.Function f )
    {
        return new Function()
        {
            @Override
            public To apply( From from )
            {
                To to = f.apply( from );

                if ( to == null )
                {
                    return defaults.apply( from );
                }
                else
                {
                    return to;
                }
            }
        };
    }

    @Deprecated
    public static  Function nullFunction()
    {
        return new Function()
        {
            @Override
            public To apply( From from )
            {
                return null; // Always return null
            }
        };
    }

    @Deprecated
    public static  Function constant( final To value )
    {
        return new Function()
        {
            @Override
            public To apply( From from )
            {
                return value;
            }
        };
    }

    @Deprecated
    public static  Function identity()
    {
        return new Function()
        {
            @Override
            public T apply( T from )
            {
                return from;
            }
        };
    }

    @Deprecated
    public static  Function2, Function, Function> compose()
    {
        return new Function2, Function, Function>()
        {
            @Override
            public Function apply( final Function f1, final Function f2 )
            {
                return new Function()
                {
                    @Override
                    public To apply( From from )
                    {
                        return f2.apply( f1.apply( from ) );
                    }
                };
            }
        };
    }

    @Deprecated
    public static  Function2, Function2, Function2> compose2()
    {
        return new Function2, Function2, Function2>()
        {
            @Override
            public Function2 apply( final Function2 function1, final Function2 function2 )
            {
                return new Function2()
                {
                    @Override
                    public T1 apply( T1 from1, T2 from2 )
                    {
                        return function1.apply( function2.apply( from1, from2 ), from2 );
                    }
                };
            }
        };
    }

    @Deprecated
    public static Function TO_STRING = new Function()
    {
        @Override
        public String apply( Object from )
        {
            if (from != null)
            {
                return from.toString();
            }
            else
            {
                return "";
            }
        }
    };

    @Deprecated
    public static  Function cast( final Class to )
    {
        return new Function()
        {
            @Override
            public TO apply( FROM from )
            {
                return to.cast( from );
            }

            @Override
            public String toString()
            {
                return "cast(to=" + to.getName() + ")";
            }
        };
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy