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

com.fluxtion.ext.streaming.builder.factory.Primitive2NumberStreamBuilder Maven / Gradle / Ivy

/*
 * Copyright (C) 2021 V12 Technology Ltd
 *  All rights reserved.
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the Server Side Public License, version 1,
 *  as published by MongoDB, Inc.
 *
 *  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
 *  Server Side Public License for more details.
 *
 *  You should have received a copy of the Server Side Public License
 *  along with this program.  If not, see 
 *  .
 */
package com.fluxtion.ext.streaming.builder.factory;

import com.fluxtion.api.partition.LambdaReflection;
import com.fluxtion.api.partition.LambdaReflection.SerializableFunction;
import com.fluxtion.api.partition.LambdaReflection.SerializableSupplier;
import com.fluxtion.ext.streaming.api.Wrapper;
import com.fluxtion.ext.streaming.api.stream.Argument;
import static com.fluxtion.ext.streaming.api.stream.Argument.arg;
import com.fluxtion.ext.streaming.api.stream.StreamFunctions;
import static com.fluxtion.ext.streaming.builder.factory.MappingBuilder.map;
import org.apache.commons.lang3.ClassUtils;

/**
 *
 * @author gregp
 */
public interface Primitive2NumberStreamBuilder {

    public static  LambdaReflection.SerializableFunction int2Num() {
        return StreamFunctions::asInt;
    }

    public static  LambdaReflection.SerializableFunction long2Num() {
        return StreamFunctions::asLong;
    }

    public static  LambdaReflection.SerializableFunction double2Num() {
        return StreamFunctions::asDouble;
    }

    public static  Wrapper primitive2Num(Argument arg) {
        final Class returnType = arg.getAccessor().getReturnType();
        Class wrapperType = ClassUtils.primitiveToWrapper(returnType);
        if (wrapperType == Integer.class || wrapperType == Short.class || wrapperType == Byte.class) {
            Wrapper intWrapper = map(int2Num(), arg);
            return intWrapper;
        } else if (wrapperType == Long.class) {
            Wrapper intWrapper = map(long2Num(), arg);
            return intWrapper;
        }
        return map(double2Num(), arg);
    }

    public static  Wrapper primitive2Num(SerializableFunction supplier) {
        return primitive2Num(arg(supplier));
    }

    public static  Wrapper primitive2Num(SerializableSupplier supplier) {
        return primitive2Num(arg(supplier));
    }

    public static  Wrapper primitive2Num(Wrapper wrapper, SerializableFunction supplier) {
        return primitive2Num(arg(wrapper, supplier));
    }

    public static  Wrapper primitive2Num(Wrapper wrapper) {
        return primitive2Num(arg(wrapper));
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy