Package edu.wpi.first.units
Class CombinatoryUnitCache<A extends Unit,B extends Unit,Out extends Unit>
java.lang.Object
edu.wpi.first.units.CombinatoryUnitCache<A,B,Out>
- Type Parameters:
A
- the type of the first unit to be combinedB
- the type of the second unit to be combinedOut
- the type of the combinatorial unit
public final class CombinatoryUnitCache<A extends Unit,B extends Unit,Out extends Unit>
extends Object
A helper class for creating and caching combined unit objects. This helps to reduce unnecessary
object allocation by reusing already-created units.
-
Constructor Summary
ConstructorDescriptionCombinatoryUnitCache
(BiFunction<? super A, ? super B, ? extends Out> constructor) Creates a new combinatory unit cache. -
Method Summary
-
Constructor Details
-
CombinatoryUnitCache
Creates a new combinatory unit cache. The cache is initially empty and is not shared across instances.- Parameters:
constructor
- the constructor function to use to create new combined units
-
-
Method Details
-
combine
Combines two units together and returns the result. The resulting units are cached and will be returned on successive calls to avoid allocating many duplicate objects. The combination output type is determined by the factory function passed into the cache's constructor.- Parameters:
a
- the first unitb
- the second unit- Returns:
- the combined unit
-