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

com.ibasco.agql.core.util.Functions Maven / Gradle / Ivy

There is a newer version: 1.2.2
Show newest version
/*
 * Copyright (c) 2022 Asynchronous Game Query Library
 *
 * 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.ibasco.agql.core.util;

import org.jetbrains.annotations.ApiStatus;
import java.util.function.Function;

/**
 * Utilities for Functional Interfaces
 *
 * @author Rafael Luis Ibasco
 */
@ApiStatus.Internal
public class Functions {

    /** Constant TRUE */
    public static final Function TRUE = unused -> true;

    /** Constant FALSE */
    public static final Function FALSE = unused -> false;

    /**
     * 

Cast argument to it's returning type

* * @param a * a A object * @param * The captured type of the parameter * @param * The captured return type * * @return The casted instance */ public static B cast(A a) { //noinspection unchecked return (B) a; } /** *

Cast argument into the captured type

* * @param b * a B object * @param * a B class * @param * a C class * * @return a C object */ public static C convert(B b) { //noinspection unchecked return (C) b; } /** *

returnArg.

* * @param a * a A object * @param
* a A class * * @return a A object */ public static A returnArg(A a) { return a; } /** *

Select first argument of the function and return it

* * @param a * a A object * @param b * a B object * @param
* a A class * @param * a B class * * @return a A object */ public static A selectFirst(A a, B b) { return a; } /** *

Select second argument of the function and return it

* * @param a * a A object * @param b * a B object * @param
* a A class * @param * a B class * * @return a B object */ public static B selectSecond(A a, B b) { return b; } /** *

isTypeOf.

* * @param v * a {@link java.lang.Object} object * @param arr * a {@link java.lang.Class} object * * @return a boolean */ public static boolean isTypeOf(Object v, Class... arr) { if (arr == null || arr.length == 0) return false; for (Class c : arr) { if (c.equals(v.getClass())) return true; } return false; } }