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 combined
B - the type of the second unit to be combined
Out - 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 Details

    • CombinatoryUnitCache

      public CombinatoryUnitCache(BiFunction<? super A,? super B,? extends Out> constructor)
      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

      public Out combine(A a, B b)
      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 unit
      b - the second unit
      Returns:
      the combined unit