RobotCore 1.0
WPILib port to raspberry Pi
Loading...
Searching...
No Matches
org.wpilib.units.UnitBuilder< U extends Unit > Class Template Reference

Classes

class  MappingBuilder
interface  UnitConstructorFunction

Public Member Functions

 UnitBuilder (U base)
UnitBuilder< U > offset (double offset)
MappingBuilder mappingInputRange (double minBase, double maxBase)
UnitBuilder< U > fromBase (UnaryFunction fromBase)
UnitBuilder< U > toBase (UnaryFunction toBase)
UnitBuilder< U > named (String name)
UnitBuilder< U > symbol (String symbol)
UnitBuilder< U > splitInto (double fraction)
UnitBuilder< U > aggregate (double aggregation)
U make (UnitConstructorFunction< U > constructor)
U make ()

Detailed Description

Builder used for easily deriving new units from existing ones. When deriving a new unit, the base unit class must redeclare the constructor (U, UnaryFunction, UnaryFunction, String, String). The unit builder class will invoke this constructor automatically and build the new unit. Alternatively, new units can be derived by passing an explicit constructor function to make(UnitConstructorFunction).

Parameters
<U>the type of the unit

Definition at line 21 of file UnitBuilder.java.

Constructor & Destructor Documentation

◆ UnitBuilder()

org.wpilib.units.UnitBuilder< U extends Unit >.UnitBuilder ( U base)

Creates a new unit builder object, building off of a base unit. The base unit does not have to be the base unit of its unit system; furlongs work just as well here as meters.

Parameters
basethe unit to base the new unit off of

Definition at line 34 of file UnitBuilder.java.

Member Function Documentation

◆ aggregate()

UnitBuilder< U > org.wpilib.units.UnitBuilder< U extends Unit >.aggregate ( double aggregation)

Helper for defining units that are a scalar multiple of the base unit, such as kilometers being 1000x of the base unit (meters).

Parameters
aggregationthe magnitude required for a measure in the base unit to equal a magnitude of 1 in the derived unit
Returns
the unit builder, for continued chaining

Definition at line 180 of file UnitBuilder.java.

◆ fromBase()

UnitBuilder< U > org.wpilib.units.UnitBuilder< U extends Unit >.fromBase ( UnaryFunction fromBase)

Sets the conversion function to transform values in the base unit to values in the derived unit.

Parameters
fromBasethe conversion function
Returns
the unit builder, for continued chaining

Definition at line 115 of file UnitBuilder.java.

◆ make() [1/2]

U org.wpilib.units.UnitBuilder< U extends Unit >.make ( )

Creates the new unit based off of the builder methods called prior.

Returns
the new derived unit
Exceptions
NullPointerExceptionif the unit conversions, unit name, or unit symbol were not set
RuntimeExceptionif the base unit does not define a constructor accepting the conversion functions, unit name, and unit symbol - in that order

Definition at line 246 of file UnitBuilder.java.

◆ make() [2/2]

U org.wpilib.units.UnitBuilder< U extends Unit >.make ( UnitConstructorFunction< U > constructor)

Creates the new unit based off of the builder methods called prior, passing them to a provided constructor function.

Parameters
constructorthe function to use to create the new derived unit
Returns
the new derived unit
Exceptions
NullPointerExceptionif the unit conversions, unit name, or unit symbol were not set

Definition at line 224 of file UnitBuilder.java.

◆ mappingInputRange()

MappingBuilder org.wpilib.units.UnitBuilder< U extends Unit >.mappingInputRange ( double minBase,
double maxBase )

Defines a mapping for values within the given input range. This method call should be immediately followed by .toOutputRange, eg mappingInputRange(1,
2).toOutputRange(3, 4)
, which will return the unit builder for continued chaining.

Parameters
minBasethe minimum input value (does not have to be absolute)
maxBasethe maximum output value (does not have to be absolute)
Returns
a builder object used to define the output range

Definition at line 104 of file UnitBuilder.java.

◆ named()

UnitBuilder< U > org.wpilib.units.UnitBuilder< U extends Unit >.named ( String name)

Sets the name of the new unit.

Parameters
namethe new name
Returns
the unit builder, for continued chaining

Definition at line 138 of file UnitBuilder.java.

◆ offset()

UnitBuilder< U > org.wpilib.units.UnitBuilder< U extends Unit >.offset ( double offset)

Sets the unit conversions based on a simple offset. The new unit will have its values equal to (base value - offset).

Parameters
offsetthe offset
Returns
this builder

Definition at line 45 of file UnitBuilder.java.

◆ splitInto()

UnitBuilder< U > org.wpilib.units.UnitBuilder< U extends Unit >.splitInto ( double fraction)

Helper for defining units that are a scalar fraction of the base unit, such as centimeters being 1/100th of the base unit (meters). The fraction value is specified as the denominator of the fraction, so a centimeter definition would use splitInto(100) instead of
splitInto(1/100.0)
.

Parameters
fractionthe denominator portion of the fraction of the base unit that a value of 1 in the derived unit corresponds to
Returns
the unit builder, for continued chaining

Definition at line 164 of file UnitBuilder.java.

◆ symbol()

UnitBuilder< U > org.wpilib.units.UnitBuilder< U extends Unit >.symbol ( String symbol)

Sets the symbol of the new unit.

Parameters
symbolthe new symbol
Returns
the unit builder, for continued chaining

Definition at line 149 of file UnitBuilder.java.

◆ toBase()

UnitBuilder< U > org.wpilib.units.UnitBuilder< U extends Unit >.toBase ( UnaryFunction toBase)

Sets the conversion function to transform values in the derived unit to values in the base unit.

Parameters
toBasethe conversion function
Returns
the unit builder, for continued chaining

Definition at line 127 of file UnitBuilder.java.


The documentation for this class was generated from the following file: