Skip navigation links

Package org.apfloat.spi

The apfloat Service Provider Interface (SPI).

See: Description

Package org.apfloat.spi Description

The apfloat Service Provider Interface (SPI).

The apfloat API is a high-level API that defines algorithms on the level of e.g. the Newton iteration for the inverse of a number. Behind this high-level API there is a lot of low-level functionality that makes all the arbitrary precision arithmetic happen. The digits of a large number are stored in an array of ints, for example. In fact, an Apfloat is structurally just a pointer to an ApfloatImpl, and most of the functionality of the Apfloat class is simply delegated to the underlying ApfloatImpl.

The apfloat SPI defines the general interface for the low-level things that must happen behind the scenes of the high-level API. An actual implementation of the SPI can be optimized for different things, for example:

A Service Provider is only required to implement the BuilderFactory interface, and actually only the BuilderFactory.getApfloatBuilder() method in this interface. All apfloat implementations (ApfloatImpl) are created through the ApfloatBuilder interface's methods. The rest of the interfaces in the SPI exist only for the convenience of the default apfloat SPI implementations (org.apfloat.internal).

The apfloat SPI suggests the usage of various patterns, as encouraged by the specification of all the interfaces in the SPI. These patterns include:

Associations of the SPI classes are shown in a class diagram format below:

Class diagram

The class implementing BuilderFactory that is used in creating apfloat implementations is defined in the ApfloatContext. You can set the BuilderFactory instance programmatically by calling ApfloatContext.setBuilderFactory(BuilderFactory), for example:

BuilderFactory builderFactory = new MyBuilderFactory();
ApfloatContext.getContext().setBuilderFactory(builderFactory);
It's a lot easier to specify this to happen automatically whenever your program starts. To do this just specify the BuilderFactory class name in the apfloat.properties file (or the apfloat ResourceBundle if you use one). For example, the apfloat.properties file might contain the line:
builderFactory=org.mycompany.MyBuilderFactory
For more details about configuring the apfloat BuilderFactory, see the documentation for ApfloatContext.
See Also:
org.apfloat.internal
Skip navigation links

Copyright © 2017. All rights reserved.