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

org.apfloat.internal.IntBuilderFactory Maven / Gradle / Ivy

There is a newer version: 1.14.0
Show newest version
package org.apfloat.internal;

import org.apfloat.ApfloatRuntimeException;

import org.apfloat.spi.AdditionBuilder;
import org.apfloat.spi.BuilderFactory;
import org.apfloat.spi.ApfloatBuilder;
import org.apfloat.spi.DataStorageBuilder;
import org.apfloat.spi.ConvolutionBuilder;
import org.apfloat.spi.NTTBuilder;
import org.apfloat.spi.MatrixBuilder;
import org.apfloat.spi.CarryCRTBuilder;

/**
 * Factory class for getting instances of the various builder classes needed
 * to build an ApfloatImpl with the int data element type.
 *
 * @version 1.7.0
 * @author Mikko Tommila
 */

public class IntBuilderFactory
    implements BuilderFactory
{
    /**
     * Default constructor.
     */

    public IntBuilderFactory()
    {
    }

    public ApfloatBuilder getApfloatBuilder()
    {
        return IntBuilderFactory.apfloatBuilder;
    }

    public DataStorageBuilder getDataStorageBuilder()
    {
        return IntBuilderFactory.dataStorageBuilder;
    }

    public  AdditionBuilder getAdditionBuilder(Class elementType)
        throws IllegalArgumentException
    {
        if (!Integer.TYPE.equals(elementType))
        {
           throw new IllegalArgumentException("Unsupported element type: " + elementType);
        }
        @SuppressWarnings("unchecked")
        AdditionBuilder additionBuilder = (AdditionBuilder) IntBuilderFactory.additionBuilder;
        return additionBuilder;
    }

    public ConvolutionBuilder getConvolutionBuilder()
    {
        return IntBuilderFactory.convolutionBuilder;
    }

    public NTTBuilder getNTTBuilder()
    {
        return IntBuilderFactory.nttBuilder;
    }

    public MatrixBuilder getMatrixBuilder()
    {
        return IntBuilderFactory.matrixBuilder;
    }

    public  CarryCRTBuilder getCarryCRTBuilder(Class elementArrayType)
        throws IllegalArgumentException
    {
        if (!int[].class.equals(elementArrayType))
        {
           throw new IllegalArgumentException("Unsupported element array type: " + elementArrayType);
        }
        @SuppressWarnings("unchecked")
        CarryCRTBuilder carryCRTBuilder = (CarryCRTBuilder) IntBuilderFactory.carryCRTBuilder;
        return carryCRTBuilder;
    }

    public Class getElementType()
    {
        return Integer.TYPE;
    }

    public Class getElementArrayType()
    {
        return int[].class;
    }

    public int getElementSize()
    {
        return 4;
    }

    public void shutdown()
        throws ApfloatRuntimeException
    {
        DiskDataStorage.cleanUp();
    }

    public void gc()
        throws ApfloatRuntimeException
    {
        System.gc();
        System.gc();
        System.runFinalization();
        DiskDataStorage.gc();
    }

    private static ApfloatBuilder apfloatBuilder = new IntApfloatBuilder();
    private static DataStorageBuilder dataStorageBuilder = new IntDataStorageBuilder();
    private static AdditionBuilder additionBuilder = new IntAdditionBuilder();
    private static ConvolutionBuilder convolutionBuilder = new IntConvolutionBuilder();
    private static NTTBuilder nttBuilder = new IntNTTBuilder();
    private static MatrixBuilder matrixBuilder = new IntMatrixBuilder();
    private static CarryCRTBuilder carryCRTBuilder = new IntCarryCRTBuilder();
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy