Top Description Fields Constructors Methods
tech.units.indriya.internal.function.simplify

pack-priv final Class CompositionTask

extends Object
Class Inheritance
Imports
java.util.Arrays, .List, java.util.function.BiPredicate, .BinaryOperator, javax.measure.UnitConverter, tech.units.indriya.function.AbstractConverter

Package private normal-form yielding worker task.
Author
Andi Huber
Since
2.0
Version
1.0

Field Summary

Modifier and TypeField and Description
private AbstractConverter[]
private final BiPredicate<AbstractConverter, AbstractConverter>
private final BinaryOperator<AbstractConverter>
private final BiPredicate<AbstractConverter, AbstractConverter>
private final BiPredicate<AbstractConverter, AbstractConverter>

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public AbstractConverter
reduceToNormalForm(List<? extends UnitConverter> conversionSteps)

Description of a brute-force approach:

Given 'conversionSteps' a list of converters, where order matters, we form a permutation group of all allowed permutations 'reachable' through 'allowed' swapping.

private static AbstractConverter
sequenceToConverter(AbstractConverter[] sequence)

converts an array of converters to a single converter object

private void
sortToNormalFormOrder(AbstractConverter[] arrayOfConverters)

sorts an array of converters to normal-form order

private int

Returns:

the number of simplifications that could be found and were applied
trySimplify
()

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

arrayOfConvertersback to summary
private AbstractConverter[] arrayOfConverters
canReduceback to summary
private final BiPredicate<AbstractConverter, AbstractConverter> canReduce
doReduceback to summary
private final BinaryOperator<AbstractConverter> doReduce
isNormalFormOrderWhenCommutativeback to summary
private final BiPredicate<AbstractConverter, AbstractConverter> isNormalFormOrderWhenCommutative
isNormalFormOrderWhenIdentityback to summary
private final BiPredicate<AbstractConverter, AbstractConverter> isNormalFormOrderWhenIdentity

Constructor Detail

CompositionTaskback to summary
pack-priv CompositionTask(BiPredicate<AbstractConverter, AbstractConverter> isNormalFormOrderWhenIdentity, BiPredicate<AbstractConverter, AbstractConverter> isNormalFormOrderWhenCommutative, BiPredicate<AbstractConverter, AbstractConverter> canReduce, BinaryOperator<AbstractConverter> doReduce)

Method Detail

reduceToNormalFormback to summary
public AbstractConverter reduceToNormalForm(List<? extends UnitConverter> conversionSteps)

Description of a brute-force approach:

Given 'conversionSteps' a list of converters, where order matters, we form a permutation group of all allowed permutations 'reachable' through 'allowed' swapping. Swapping is allowed for 2 consecutive converters that are both multiply transformations (x.isLinear()==true). We search this permutation group for any sequence of converters, that allows simplification:

For every pair of consecutive converters within a sequence, check whether a simplification is possible (a.isSimpleCompositionWith(b)), then apply simplification and start over.

Finally sort according to normal-form order.

sequenceToConverterback to summary
private static AbstractConverter sequenceToConverter(AbstractConverter[] sequence)

converts an array of converters to a single converter object

sortToNormalFormOrderback to summary
private void sortToNormalFormOrder(AbstractConverter[] arrayOfConverters)

sorts an array of converters to normal-form order

trySimplifyback to summary
private int trySimplify()
Returns:int

the number of simplifications that could be found and were applied