RobotCore 1.0
WPILib port to raspberry Pi
Loading...
Searching...
No Matches
org.wpilib.units.Unit Class Referenceabstract
Inheritance diagram for org.wpilib.units.Unit:
org.wpilib.units.AngleUnit org.wpilib.units.CurrentUnit org.wpilib.units.DimensionlessUnit org.wpilib.units.DistanceUnit org.wpilib.units.EnergyUnit org.wpilib.units.MassUnit org.wpilib.units.MultUnit< A extends Unit, B extends Unit > org.wpilib.units.PerUnit< N extends Unit, D extends Unit > org.wpilib.units.TemperatureUnit org.wpilib.units.TimeUnit org.wpilib.units.VoltageUnit

Public Member Functions

abstract Measure<?> of (double magnitude)
abstract Measure<?> ofBaseUnits (double baseUnitMagnitude)
Measure<?> zero ()
Measure<?> one ()
abstract Unit per (TimeUnit time)
Unit getBaseUnit ()
boolean isBaseUnit ()
double fromBaseUnits (double valueInBaseUnits)
double toBaseUnits (double valueInNativeUnits)
UnaryFunction getConverterToBase ()
UnaryFunction getConverterFromBase ()
boolean equivalent (Unit other)
boolean equals (Object o)
int hashCode ()
String name ()
String symbol ()
String toString ()

Protected Member Functions

 Unit (Unit baseUnit, UnaryFunction toBaseConverter, UnaryFunction fromBaseConverter, String name, String symbol)
 Unit (Unit baseUnit, double baseUnitEquivalent, String name, String symbol)

Detailed Description

Unit of measurement that defines a quantity, such as grams, meters, or seconds.

This is the base class for units. Actual units (such as Units#Grams and Units#Meters) can be found in the Units class.

Definition at line 15 of file Unit.java.

Constructor & Destructor Documentation

◆ Unit() [1/2]

org.wpilib.units.Unit.Unit ( Unit baseUnit,
UnaryFunction toBaseConverter,
UnaryFunction fromBaseConverter,
String name,
String symbol )
protected

Creates a new unit defined by its relationship to some base unit.

Parameters
baseUnitthe base unit, e.g. Meters for distances. Set this to null if the unit being constructed is its own base unit
toBaseConvertera function for converting units of this type to the base unit
fromBaseConvertera function for converting units of the base unit to this one
namethe name of the unit. This should be a singular noun (so "Meter", not "Meters")
symbolthe short symbol for the unit, such as "m" for meters or "lb." for pounds

Definition at line 38 of file Unit.java.

◆ Unit() [2/2]

org.wpilib.units.Unit.Unit ( Unit baseUnit,
double baseUnitEquivalent,
String name,
String symbol )
protected

Creates a new unit with the given name and multiplier to the base unit.

Parameters
baseUnitthe base unit, e.g. Meters for distances
baseUnitEquivalentthe multiplier to convert this unit to the base unit of this type. For example, meters has a multiplier of 1, mm has a multiplier of 1e3, and km has multiplier of 1e-3.
namethe name of the unit. This should be a singular noun (so "Meter", not "Meters")
symbolthe short symbol for the unit, such as "m" for meters or "lb." for pounds

Definition at line 64 of file Unit.java.

Member Function Documentation

◆ equals()

boolean org.wpilib.units.Unit.equals ( Object o)

Definition at line 216 of file Unit.java.

◆ equivalent()

boolean org.wpilib.units.Unit.equivalent ( Unit other)

Checks if this unit is equivalent to another one. Equivalence is determined by both units having the same base type and treat the same base unit magnitude as the same magnitude in their own units, to within Measure#EQUIVALENCE_THRESHOLD.

Parameters
otherthe unit to compare to.
Returns
true if both units are equivalent, false if not

Definition at line 198 of file Unit.java.

◆ fromBaseUnits()

double org.wpilib.units.Unit.fromBaseUnits ( double valueInBaseUnits)

Converts a value in terms of base units to a value in terms of this unit.

Parameters
valueInBaseUnitsthe value in base units to convert
Returns
the equivalent value in terms of this unit

Definition at line 156 of file Unit.java.

◆ getBaseUnit()

Unit org.wpilib.units.Unit.getBaseUnit ( )

Gets the base unit of measurement that this unit is derived from. If the unit is the base unit, the unit will be returned.

NOTE: Subclasses must override this method to provide the correct return type. Failing to do say will make unit combinations that use it break at runtime!


  Unit baseUnit = new Unit(null, ...);
  baseUnit.getBaseUnit(); // returns baseUnit

  Unit derivedUnit = new Unit(baseUnit, ...);
  derivedUnit.getBaseUnit(); // returns baseUnit
Returns
the base unit

Reimplemented in org.wpilib.units.AngleUnit, org.wpilib.units.CurrentUnit, org.wpilib.units.DimensionlessUnit, org.wpilib.units.DistanceUnit, org.wpilib.units.EnergyUnit, org.wpilib.units.MassUnit, org.wpilib.units.MultUnit< A extends Unit, B extends Unit >, org.wpilib.units.PerUnit< N extends Unit, D extends Unit >, org.wpilib.units.TemperatureUnit, org.wpilib.units.TimeUnit, and org.wpilib.units.VoltageUnit.

Definition at line 137 of file Unit.java.

◆ getConverterFromBase()

UnaryFunction org.wpilib.units.Unit.getConverterFromBase ( )

Gets the conversion function used to convert values to terms of this unit. This generally shouldn't need to be used directly; prefer fromBaseUnits(double) instead.

Returns
the conversion function

Definition at line 186 of file Unit.java.

◆ getConverterToBase()

UnaryFunction org.wpilib.units.Unit.getConverterToBase ( )

Gets the conversion function used to convert values to base unit terms. This generally shouldn't need to be used directly; prefer toBaseUnits(double) instead.

Returns
the conversion function

Definition at line 176 of file Unit.java.

◆ hashCode()

int org.wpilib.units.Unit.hashCode ( )

Definition at line 225 of file Unit.java.

◆ isBaseUnit()

boolean org.wpilib.units.Unit.isBaseUnit ( )

Checks if this unit is the base unit for its own system of measurement.

Returns
true if this is the base unit, false if not

Definition at line 146 of file Unit.java.

◆ name()

String org.wpilib.units.Unit.name ( )

Gets the name of this unit.

Returns
the unit's name

Definition at line 234 of file Unit.java.

◆ of()

abstract Measure<?> org.wpilib.units.Unit.of ( double magnitude)
abstract

Creates a new immutable measurement of the given magnitude in terms of this unit. Implementations are strongly recommended to sharpen the return type to a unit-specific measurement implementation.

Parameters
magnitudethe magnitude of the measurement.
Returns
the measurement object

Reimplemented in org.wpilib.units.AngleUnit, org.wpilib.units.CurrentUnit, org.wpilib.units.DimensionlessUnit, org.wpilib.units.DistanceUnit, org.wpilib.units.EnergyUnit, org.wpilib.units.MassUnit, org.wpilib.units.MultUnit< A extends Unit, B extends Unit >, org.wpilib.units.PerUnit< N extends Unit, D extends Unit >, org.wpilib.units.TemperatureUnit, org.wpilib.units.TimeUnit, and org.wpilib.units.VoltageUnit.

◆ ofBaseUnits()

abstract Measure<?> org.wpilib.units.Unit.ofBaseUnits ( double baseUnitMagnitude)
abstract

Creates a new immutable measurement of the given magnitude in terms of this unit's base unit. Implementations are strongly recommended to sharpen the return type to a unit-specific measurement implementation.

Parameters
baseUnitMagnitudethe magnitude in terms of the base unit
Returns
the measurement object

Reimplemented in org.wpilib.units.AngleUnit, org.wpilib.units.CurrentUnit, org.wpilib.units.DimensionlessUnit, org.wpilib.units.DistanceUnit, org.wpilib.units.EnergyUnit, org.wpilib.units.MassUnit, org.wpilib.units.MultUnit< A extends Unit, B extends Unit >, org.wpilib.units.PerUnit< N extends Unit, D extends Unit >, org.wpilib.units.TemperatureUnit, org.wpilib.units.TimeUnit, and org.wpilib.units.VoltageUnit.

◆ one()

Measure<?> org.wpilib.units.Unit.one ( )

Gets a measure with a magnitude of 1.0 in terms of this unit. The returned object is guaranteed to be of the same type returned by of(double). Subclasses are encouraged to override this method to sharpen the return type.

Returns
a measure of magnitude 1.0 in terms of this unit

Reimplemented in org.wpilib.units.AngleUnit, org.wpilib.units.CurrentUnit, org.wpilib.units.DimensionlessUnit, org.wpilib.units.DistanceUnit, org.wpilib.units.EnergyUnit, org.wpilib.units.MassUnit, org.wpilib.units.MultUnit< A extends Unit, B extends Unit >, org.wpilib.units.PerUnit< N extends Unit, D extends Unit >, org.wpilib.units.TemperatureUnit, org.wpilib.units.TimeUnit, and org.wpilib.units.VoltageUnit.

Definition at line 106 of file Unit.java.

◆ per()

abstract Unit org.wpilib.units.Unit.per ( TimeUnit time)
abstract

Combines this unit with a unit of time. This often - but not always - results in a velocity. Subclasses should sharpen the return type to be unit-specific.

Parameters
timethe unit of time
Returns
the combined unit

Reimplemented in org.wpilib.units.AngleUnit, org.wpilib.units.CurrentUnit, org.wpilib.units.DimensionlessUnit, org.wpilib.units.DistanceUnit, org.wpilib.units.EnergyUnit, org.wpilib.units.MassUnit, org.wpilib.units.MultUnit< A extends Unit, B extends Unit >, org.wpilib.units.PerUnit< N extends Unit, D extends Unit >, org.wpilib.units.TemperatureUnit, org.wpilib.units.TimeUnit, and org.wpilib.units.VoltageUnit.

◆ symbol()

String org.wpilib.units.Unit.symbol ( )

Gets the symbol of this unit.

Returns
the unit's symbol

Definition at line 243 of file Unit.java.

◆ toBaseUnits()

double org.wpilib.units.Unit.toBaseUnits ( double valueInNativeUnits)

Converts a value in terms of this unit to a value in terms of the base unit.

Parameters
valueInNativeUnitsthe value in terms of this unit to convert
Returns
the equivalent value in terms of the base unit

Definition at line 166 of file Unit.java.

◆ toString()

String org.wpilib.units.Unit.toString ( )

Definition at line 248 of file Unit.java.

◆ zero()

Measure<?> org.wpilib.units.Unit.zero ( )

Gets a measure of zero magnitude in terms of this unit. The returned object is guaranteed to be of the same type returned by of(double). Subclasses are encouraged to override this method to sharpen the return type.

Returns
a zero-magnitude measure of this unit

Reimplemented in org.wpilib.units.AngleUnit, org.wpilib.units.CurrentUnit, org.wpilib.units.DimensionlessUnit, org.wpilib.units.DistanceUnit, org.wpilib.units.EnergyUnit, org.wpilib.units.MassUnit, org.wpilib.units.MultUnit< A extends Unit, B extends Unit >, org.wpilib.units.PerUnit< N extends Unit, D extends Unit >, org.wpilib.units.TemperatureUnit, org.wpilib.units.TimeUnit, and org.wpilib.units.VoltageUnit.

Definition at line 95 of file Unit.java.


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