[wpiunits] Java units API rewrite (#6958)

Java generics are too limited to do what we need. This refactors generic code previously in Unit and Measure into unit-specific classes that can have unit-safe math operations (notably, times and divide) that can return values in known units instead of a wildcarded Measure<?>.

Unit-specific measure implementations are automatically generated by ./wpiunits/generate_units.py, which generates generic interfaces and mutable and immutable implementations of those interfaces. These make up the bulk of the diff of this PR (approximately 9300 LOC).

This also adds units for angular and linear velocities, accelerations, and momenta; moment of inertia; and torque.
This commit is contained in:
Sam Carlberg
2024-09-07 13:59:29 -04:00
committed by GitHub
parent 496e7c1bba
commit a9b885070e
178 changed files with 14750 additions and 2158 deletions

View File

@@ -14,365 +14,478 @@ public final class Units {
// Pseudo-classes describing the more common units of measure.
// Distance
// Unitless
/** A dimensionless unit that performs no scaling whatsoever. */
public static final DimensionlessUnit Value = BaseUnits.Value;
/**
* A dimensionless unit equal to to 1/100th of a {@link #Value}. A measurement of {@code
* Percent.of(42)} would be equivalent to {@code Value.of(0.42)}.
*/
public static final DimensionlessUnit Percent =
derive(Value).splitInto(100).named("Percent").symbol("%").make();
// DistanceUnit
/** The base unit of distance. */
public static final Distance Meters = BaseUnits.Distance;
public static final DistanceUnit Meters = BaseUnits.DistanceUnit;
/** The base unit of distance. */
public static final Distance Meter = Meters; // alias
public static final DistanceUnit Meter = Meters; // alias
/** 1/1000 of a {@link #Meter}. */
public static final Distance Millimeters = Milli(Meters, "Millimeter", "mm");
public static final DistanceUnit Millimeters = Milli(Meters, "Millimeter", "mm");
/** 1/1000 of a {@link #Meter}. */
public static final Distance Millimeter = Millimeters; // alias
public static final DistanceUnit Millimeter = Millimeters; // alias
/** 1/100 of a {@link #Meter}. */
public static final Distance Centimeters =
public static final DistanceUnit Centimeters =
derive(Meters).splitInto(100).named("Centimeter").symbol("cm").make();
/** 1/100 of a {@link #Meter}. */
public static final Distance Centimeter = Centimeters; // alias
public static final DistanceUnit Centimeter = Centimeters; // alias
/** 25.4/1000 of a {@link #Meter} and 1/12 of a {@link #Foot}. */
public static final Distance Inches =
public static final DistanceUnit Inches =
derive(Millimeters).aggregate(25.4).named("Inch").symbol("in").make();
/** 25.4/1000 of a {@link #Meter} and 1/12 of a {@link #Foot}. */
public static final Distance Inch = Inches; // alias
public static final DistanceUnit Inch = Inches; // alias
/** 304.8/1000 of a {@link #Meter}, or 12 {@link #Inches}. */
public static final Distance Feet =
public static final DistanceUnit Feet =
derive(Inches).aggregate(12).named("Foot").symbol("ft").make();
/** 304.8/1000 of a {@link #Meter}, or 12 {@link #Inches}. */
public static final Distance Foot = Feet; // alias
public static final DistanceUnit Foot = Feet; // alias
// Time
// TimeUnit
/** The base unit of time. */
public static final Time Seconds = BaseUnits.Time;
public static final TimeUnit Seconds = BaseUnits.TimeUnit;
/** Alias for {@link #Seconds} to make combined unit definitions read more smoothly. */
public static final Time Second = Seconds; // singularized alias
public static final TimeUnit Second = Seconds; // singularized alias
/** 1/1000 of a {@link #Seconds Second}. */
public static final Time Milliseconds = Milli(Seconds);
public static final TimeUnit Milliseconds = Milli(Seconds);
/** Alias for {@link #Milliseconds} to make combined unit definitions read more smoothly. */
public static final Time Millisecond = Milliseconds; // singularized alias
public static final TimeUnit Millisecond = Milliseconds; // singularized alias
/** 1/1,000,000 of a {@link #Seconds Second}. */
public static final Time Microseconds = Micro(Seconds);
public static final TimeUnit Microseconds = Micro(Seconds);
/** Alias for {@link #Microseconds} to make combined unit definitions read more smoothly. */
public static final Time Microsecond = Microseconds; // singularized alias
public static final TimeUnit Microsecond = Microseconds; // singularized alias
/** 60 {@link #Seconds}. */
public static final Time Minutes =
public static final TimeUnit Minutes =
derive(Seconds).aggregate(60).named("Minute").symbol("min").make();
/** Alias for {@link #Minutes} to make combined unit definitions read more smoothly. */
public static final Time Minute = Minutes; // singularized alias
public static final TimeUnit Minute = Minutes; // singularized alias
// Angle
// AngleUnit
/**
* The base SI unit of angle, represented by the distance that the radius of a unit circle can
* The standard SI unit of angle, represented by the distance that the radius of a unit circle can
* wrap around its circumference.
*/
public static final Angle Radians = BaseUnits.Angle;
public static final AngleUnit Radians = BaseUnits.AngleUnit;
/**
* The base SI unit of angle, represented by the distance that the radius of a unit circle can
* The standard SI unit of angle, represented by the distance that the radius of a unit circle can
* wrap around its circumference.
*/
public static final Angle Radian = Radians; // alias
public static final AngleUnit Radian = Radians; // alias
/**
* A single turn of an object around an external axis. Numerically equivalent to {@link
* #Rotations}, but may be semantically more expressive in certain scenarios.
*/
public static final Angle Revolutions =
public static final AngleUnit Revolutions =
derive(Radians).aggregate(2 * Math.PI).named("Revolution").symbol("R").make();
/**
* A single turn of an object around an external axis. Numerically equivalent to a {@link
* #Rotation}, but may be semantically more expressive in certain scenarios.
*/
public static final Angle Revolution = Revolutions; // alias
public static final AngleUnit Revolution = Revolutions; // alias
/**
* A single turn of an object around an internal axis. Numerically equivalent to {@link
* #Revolutions}, but may be semantically more expressive in certain scenarios.
*/
public static final Angle Rotations = derive(Revolutions).named("Rotation").symbol("R").make();
public static final AngleUnit Rotations =
derive(Revolutions).named("Rotation").symbol("R").make();
/**
* A single turn of an object around an internal axis. Numerically equivalent to a {@link
* #Revolution}, but may be semantically more expressive in certain scenarios.
*/
public static final Angle Rotation = Rotations; // alias
public static final AngleUnit Rotation = Rotations; // alias
/** 1/360 of a turn around a circle, or 1/57.3 {@link #Radians}. */
public static final Angle Degrees =
public static final AngleUnit Degrees =
derive(Revolutions).splitInto(360).named("Degree").symbol("°").make();
/** 1/360 of a turn around a circle, or 1/57.3 {@link #Radians}. */
public static final Angle Degree = Degrees; // alias
public static final AngleUnit Degree = Degrees; // alias
// Velocity
// VelocityUnit
/**
* The standard SI unit of linear velocity, equivalent to travelling at a rate of one {@link
* #Meters Meter} per {@link #Second}.
*/
public static final Velocity<Distance> MetersPerSecond = Meters.per(Second);
public static final LinearVelocityUnit MetersPerSecond = Meters.per(Second);
/**
* A unit of linear velocity equivalent to travelling at a rate one {@link #Feet Foot} per {@link
* #Second}.
*/
public static final Velocity<Distance> FeetPerSecond = Feet.per(Second);
public static final LinearVelocityUnit FeetPerSecond = Feet.per(Second);
/**
* A unit of linear velocity equivalent to travelling at a rate of one {@link #Inches Inch} per
* {@link #Second}.
*/
public static final Velocity<Distance> InchesPerSecond = Inches.per(Second);
public static final LinearVelocityUnit InchesPerSecond = Inches.per(Second);
/**
* A unit of angular velocity equivalent to spinning at a rate of one {@link #Revolutions
* Revolution} per {@link #Second}.
*/
public static final Velocity<Angle> RevolutionsPerSecond = Revolutions.per(Second);
public static final AngularVelocityUnit RevolutionsPerSecond = Revolutions.per(Second);
/**
* A unit of angular velocity equivalent to spinning at a rate of one {@link #Rotations Rotation}
* per {@link #Second}.
*/
public static final Velocity<Angle> RotationsPerSecond = Rotations.per(Second);
public static final AngularVelocityUnit RotationsPerSecond = Rotations.per(Second);
/**
* A unit of angular velocity equivalent to spinning at a rate of one {@link #Rotations Rotation}
* per {@link #Minute}. Motor spec sheets often list maximum speeds in terms of RPM.
*/
public static final Velocity<Angle> RPM = Rotations.per(Minute);
public static final AngularVelocityUnit RPM = Rotations.per(Minute);
/**
* The standard SI unit of angular velocity, equivalent to spinning at a rate of one {@link
* #Radians Radian} per {@link #Second}.
*/
public static final Velocity<Angle> RadiansPerSecond = Radians.per(Second);
public static final AngularVelocityUnit RadiansPerSecond = Radians.per(Second);
/**
* A unit of angular velocity equivalent to spinning at a rate of one {@link #Degrees Degree} per
* {@link #Second}.
*/
public static final Velocity<Angle> DegreesPerSecond = Degrees.per(Second);
public static final AngularVelocityUnit DegreesPerSecond = Degrees.per(Second);
/**
* The standard SI unit of frequency, equivalent to a periodic signal repeating once every {@link
* #Second}.
*/
public static final FrequencyUnit Hertz =
derive(Value.per(Second)).named("Hertz").symbol("hz").make();
/** 1/1000th of a {@link #Hertz}. */
public static final FrequencyUnit Millihertz = Milli(Hertz);
// Acceleration
/**
* The standard SI unit of linear acceleration, equivalent to accelerating at a rate of one {@link
* #Meters Meter} per {@link #Second} every second.
*/
public static final Velocity<Velocity<Distance>> MetersPerSecondPerSecond =
MetersPerSecond.per(Second);
public static final LinearAccelerationUnit MetersPerSecondPerSecond = MetersPerSecond.per(Second);
/**
* A unit of linear acceleration equivalent to accelerating at a rate of one {@link #Foot Foot}
* per {@link #Second} every second.
*/
public static final Velocity<Velocity<Distance>> FeetPerSecondPerSecond =
FeetPerSecond.per(Second);
public static final LinearAccelerationUnit FeetPerSecondPerSecond = FeetPerSecond.per(Second);
/**
* A unit of angular acceleration equivalent to accelerating at a rate of one {@link #Rotations
* Rotation} per {@link #Second} every second.
*/
public static final Velocity<Velocity<Angle>> RotationsPerSecondPerSecond =
public static final AngularAccelerationUnit RotationsPerSecondPerSecond =
RotationsPerSecond.per(Second);
/**
* The standard SI unit of angular acceleration, equivalent to accelerating at a rate of one
* {@link #Radians Radian} per {@link #Second} every second.
*/
public static final Velocity<Velocity<Angle>> RadiansPerSecondPerSecond =
public static final AngularAccelerationUnit RadiansPerSecondPerSecond =
RadiansPerSecond.per(Second);
/**
* A unit of angular acceleration equivalent to accelerating at a rate of one {@link #Degrees
* Degree} per {@link #Second} every second.
*/
public static final Velocity<Velocity<Angle>> DegreesPerSecondPerSecond =
public static final AngularAccelerationUnit DegreesPerSecondPerSecond =
DegreesPerSecond.per(Second);
/**
* A unit of acceleration equivalent to the pull of gravity on an object at sea level on Earth.
*/
public static final Velocity<Velocity<Distance>> Gs =
public static final LinearAccelerationUnit Gs =
derive(MetersPerSecondPerSecond).aggregate(9.80665).named("G").symbol("G").make();
// Mass
/** The base SI unit of mass. */
public static final Mass Kilograms = BaseUnits.Mass;
// MassUnit
/** The standard SI unit of mass. */
public static final MassUnit Kilograms = BaseUnits.MassUnit;
/** The base SI unit of mass. */
public static final Mass Kilogram = Kilograms; // alias
/** The standard SI unit of mass. */
public static final MassUnit Kilogram = Kilograms; // alias
/** 1/1000 of a {@link #Kilogram}. */
public static final Mass Grams = Milli(Kilograms, "Gram", "g");
public static final MassUnit Grams = Milli(Kilograms, "Gram", "g");
/** 1/1000 of a {@link #Kilogram}. */
public static final Mass Gram = Grams; // alias
public static final MassUnit Gram = Grams; // alias
/**
* A unit of mass equivalent to approximately 453 {@link #Grams}. This is <i>not</i> equivalent to
* pounds-force, which is the amount of force required to accelerate an object with one pound of
* mass at a rate of one {@link #Gs G}.
*
* @see #PoundsForce
*/
public static final Mass Pounds =
public static final MassUnit Pounds =
derive(Grams).aggregate(453.592).named("Pound").symbol("lb.").make();
/**
* A unit of mass equivalent to approximately 453 {@link #Grams}. This is <i>not</i> equivalent to
* pounds-force, which is the amount of force required to accelerate an object with one pound of
* mass at a rate of one {@link #Gs G}.
*
* @see #PoundForce
*/
public static final Mass Pound = Pounds; // alias
public static final MassUnit Pound = Pounds; // alias
/** 1/16 of a {@link #Pound}. */
public static final Mass Ounces =
public static final MassUnit Ounces =
derive(Pounds).splitInto(16).named("Ounce").symbol("oz.").make();
/** 1/16 of a {@link #Pound}. */
public static final Mass Ounce = Ounces; // alias
public static final MassUnit Ounce = Ounces; // alias
// Force
/**
* The standard unit of force, equivalent to accelerating a mass of one {@link #Kilogram} at a
* rate of one {@link #MetersPerSecondPerSecond meter per second per second}.
*/
public static final ForceUnit Newtons =
derive(Kilograms.mult(MetersPerSecondPerSecond)).named("Newton").symbol("N").make();
/**
* The standard unit of force, equivalent to the standard force of gravity applied to a one {@link
* #Kilogram} mass.
*/
public static final ForceUnit Newton = Newtons;
/**
* The standard Imperial unit of force, equivalent to the standard force of gravity applied to a
* one {@link #Pound} mass.
*/
public static final ForceUnit PoundsForce =
derive(Pounds.mult(Gs)).named("Pound-force").symbol("lbsf.").make();
/**
* The standard Imperial unit of force, equivalent to the standard force of gravity applied to a
* one {@link #Pound} mass.
*/
public static final ForceUnit PoundForce = PoundsForce;
/**
* 1/16th of {@link #PoundsForce}, equivalent to the standard force of gravity applied to a one
* {@link #Ounce} mass.
*/
public static final ForceUnit OuncesForce =
derive(Ounces.mult(Gs)).named("Ounce-force").symbol("ozf").make();
/**
* 1/16th of {@link #PoundsForce}, equivalent to the standard force of gravity applied to a one
* {@link #Ounce} mass.
*/
public static final ForceUnit OunceForce = OuncesForce;
// Torque
/** The standard SI unit for torque. */
public static final TorqueUnit NewtonMeters = Meters.multAsTorque(Newtons);
/** The standard SI unit for torque. */
public static final TorqueUnit NewtonMeter = NewtonMeters;
/**
* The equivalent of one {@link #PoundsForce pound of force} applied to an object one {@link
* #Foot} away from its center of rotation.
*/
public static final TorqueUnit PoundFeet = Feet.multAsTorque(PoundsForce);
/**
* The equivalent of one {@link #PoundsForce pound of force} applied to an object one {@link
* #Foot} away from its center of rotation.
*/
public static final TorqueUnit PoundFoot = PoundFeet;
/**
* The equivalent of one {@link #PoundsForce pound of force} applied to an object one {@link
* #Inch} away from its center of rotation.
*/
public static final TorqueUnit PoundInches = Inches.multAsTorque(PoundsForce);
/**
* The equivalent of one {@link #PoundsForce pound of force} applied to an object one {@link
* #Inch} away from its center of rotation.
*/
public static final TorqueUnit PoundInch = PoundInches;
/**
* The equivalent of one {@link #OunceForce ounce of force} applied to an object one {@link #Inch}
* away from its center of rotation.
*/
public static final TorqueUnit OunceInches = Inches.multAsTorque(OuncesForce);
/**
* The equivalent of one {@link #OunceForce ounce of force} applied to an object one {@link #Inch}
* away from its center of rotation.
*/
public static final TorqueUnit OunceInch = OunceInches;
// Linear momentum
/**
* The standard SI unit for linear momentum, equivalent to a one {@link #Kilogram} mass moving at
* one {@link #MetersPerSecond}.
*/
public static final LinearMomentumUnit KilogramMetersPerSecond = Kilograms.mult(MetersPerSecond);
// Angular momentum
/** The standard SI unit for angular momentum. */
public static final AngularMomentumUnit KilogramMetersSquaredPerSecond =
KilogramMetersPerSecond.mult(Meters);
// Moment of Inertia
/** The base SI unit for moment of inertia. */
public static final Mult<Mult<Mass, Distance>, Distance> KilogramSquareMeters =
Kilograms.mult(Meters).mult(Meters);
// Unitless
/** A dimensionless unit that performs no scaling whatsoever. */
public static final Dimensionless Value = BaseUnits.Value;
/** The standard SI unit for moment of inertia. */
public static final MomentOfInertiaUnit KilogramSquareMeters =
KilogramMetersSquaredPerSecond.mult(RadiansPerSecond);
/**
* A dimensionless unit equal to to 1/100th of a {@link #Value}. A measurement of {@code
* Percent.of(42)} would be equivalent to {@code Value.of(0.42)}.
*/
public static final Dimensionless Percent =
derive(Value).splitInto(100).named("Percent").symbol("%").make();
// Voltage
// VoltageUnit
/** The base unit of electric potential. */
public static final Voltage Volts = BaseUnits.Voltage;
public static final VoltageUnit Volts = BaseUnits.VoltageUnit;
/** The base unit of electric potential. */
public static final Voltage Volt = Volts; // alias
public static final VoltageUnit Volt = Volts; // alias
/**
* 1/1000 of a {@link #Volt}. Useful when dealing with low-voltage applications like LED drivers
* or low-power circuits.
*/
public static final Voltage Millivolts = Milli(Volts);
public static final VoltageUnit Millivolts = Milli(Volts);
/**
* 1/1000 of a {@link #Volt}. Useful when dealing with low-voltage applications like LED drivers
* or low-power circuits.
*/
public static final Voltage Millivolt = Millivolts; // alias
public static final VoltageUnit Millivolt = Millivolts; // alias
// Current
// CurrentUnit
/** The base unit of electrical current. */
public static final Current Amps = BaseUnits.Current;
public static final CurrentUnit Amps = BaseUnits.CurrentUnit;
/** The base unit of electrical current. */
public static final Current Amp = Amps; // alias
public static final CurrentUnit Amp = Amps; // alias
/**
* A unit equal to 1/1000 of an {@link #Amp}. Useful when dealing with low-current applications
* like LED drivers or low-power circuits.
*/
public static final Current Milliamps = Milli(Amps);
public static final CurrentUnit Milliamps = Milli(Amps);
/**
* A unit equal to 1/1000 of an {@link #Amp}. Useful when dealing with low-current applications
* like LED drivers or low-power circuits.
*/
public static final Current Milliamp = Milliamps; // alias
public static final CurrentUnit Milliamp = Milliamps; // alias
// Energy
// EnergyUnit
/** The base unit of energy. */
public static final Energy Joules = BaseUnits.Energy;
public static final EnergyUnit Joules = BaseUnits.EnergyUnit;
/** The base unit of energy. */
public static final Energy Joule = Joules; // alias
public static final EnergyUnit Joule = Joules; // alias
/**
* A unit equal to 1/1000 of a {@link #Joule}. Useful when dealing with lower-power applications.
*/
public static final Energy Millijoules = Milli(Joules);
public static final EnergyUnit Millijoules = Milli(Joules);
/**
* A unit equal to 1/1000 of a {@link #Joule}. Useful when dealing with lower-power applications.
*/
public static final Energy Millijoule = Millijoules; // alias
public static final EnergyUnit Millijoule = Millijoules; // alias
/**
* A unit equal to 1,000 {@link #Joules}. Useful when dealing with higher-level robot energy
* usage.
*/
public static final Energy Kilojoules = Kilo(Joules);
public static final EnergyUnit Kilojoules = Kilo(Joules);
/**
* A unit equal to 1,000 {@link #Joules}. Useful when dealing with higher-level robot energy
* usage.
*/
public static final Energy Kilojoule = Kilojoules; // alias
public static final EnergyUnit Kilojoule = Kilojoules; // alias
// Power
// PowerUnit
/** The base unit of power. Equivalent to one {@link #Joule} per {@link #Second}. */
public static final Power Watts = BaseUnits.Power;
public static final PowerUnit Watts = derive(Joules.per(Second)).named("Watt").symbol("W").make();
/** The base unit of power. Equivalent to one {@link #Joule} per {@link #Second}. */
public static final Power Watt = Watts; // alias
public static final PowerUnit Watt = Watts; // alias
/**
* A unit equal to 1/1000 of a {@link #Watt}. Useful when dealing with lower-power applications.
*/
public static final Power Milliwatts = Milli(Watts);
public static final PowerUnit Milliwatts = Milli(Watts);
/**
* A unit equal to 1/1000 of a {@link #Watt}. Useful when dealing with lower-power applications.
*/
public static final Power Milliwatt = Milliwatts; // alias
public static final PowerUnit Milliwatt = Milliwatts; // alias
/**
* A unit equal to 745.7 {@link #Watts}. May be useful when dealing with high-power gearboxes and
* motors.
*/
public static final Power Horsepower =
public static final PowerUnit Horsepower =
derive(Watts).aggregate(745.7).named("Horsepower").symbol("HP").make();
// Temperature
// TemperatureUnit
/**
* The base unit of temperature, where a value of 0 corresponds with absolutely zero energy in the
* measured system. Not particularly useful for robots unless you're cooling motors with liquid
* helium.
*/
public static final Temperature Kelvin = BaseUnits.Temperature;
public static final TemperatureUnit Kelvin = BaseUnits.TemperatureUnit;
/**
* The base SI unit of temperature, where a value of 0 roughly corresponds to the freezing point
* of water and a value of 100 corresponds to the boiling point. Electronics tend to exhibit
* The standard SI unit of temperature, where a value of 0 roughly corresponds to the freezing
* point of water and a value of 100 corresponds to the boiling point. Electronics tend to exhibit
* degraded performance or damage above 90 degrees Celsius.
*/
public static final Temperature Celsius =
public static final TemperatureUnit Celsius =
derive(Kelvin).offset(+273.15).named("Celsius").symbol("°C").make();
/**
* The base imperial (American) unit of temperature, where a value of 32 roughly corresponds to
* the freezing point of water and a value of 212 corresponds to the boiling point.
*/
public static final Temperature Fahrenheit =
public static final TemperatureUnit Fahrenheit =
derive(Celsius)
.mappingInputRange(0, 100)
.toOutputRange(32, 212)
@@ -386,28 +499,28 @@ public final class Units {
* A standard unit for measuring linear mechanisms' feedforward voltages based on a model of the
* system and a desired commanded linear velocity.
*/
public static final Per<Voltage, Velocity<Distance>> VoltsPerMeterPerSecond =
public static final PerUnit<VoltageUnit, LinearVelocityUnit> VoltsPerMeterPerSecond =
Volts.per(MetersPerSecond);
/**
* A standard unit for measuring linear mechanisms' feedforward voltages based on a model of the
* system and a desired commanded linear acceleration.
*/
public static final Per<Voltage, Velocity<Velocity<Distance>>> VoltsPerMeterPerSecondSquared =
public static final PerUnit<VoltageUnit, LinearAccelerationUnit> VoltsPerMeterPerSecondSquared =
Volts.per(MetersPerSecondPerSecond);
/**
* A standard unit for measuring angular mechanisms' feedforward voltages based on a model of the
* system and a desired commanded angular velocity.
*/
public static final Per<Voltage, Velocity<Angle>> VoltsPerRadianPerSecond =
public static final PerUnit<VoltageUnit, AngularVelocityUnit> VoltsPerRadianPerSecond =
Volts.per(RadiansPerSecond);
/**
* A standard unit for measuring angular mechanisms' feedforward voltages based on a model of the
* system and a desired commanded angular acceleration.
*/
public static final Per<Voltage, Velocity<Velocity<Angle>>> VoltsPerRadianPerSecondSquared =
public static final PerUnit<VoltageUnit, AngularAccelerationUnit> VoltsPerRadianPerSecondSquared =
Volts.per(RadiansPerSecond.per(Second));
/**
@@ -420,7 +533,7 @@ public final class Units {
* @return the milli-unit
*/
@SuppressWarnings("checkstyle:methodname")
public static <U extends Unit<U>> U Milli(Unit<U> baseUnit, String name, String symbol) {
public static <U extends Unit> U Milli(U baseUnit, String name, String symbol) {
return derive(baseUnit).splitInto(1000).named(name).symbol(symbol).make();
}
@@ -432,7 +545,7 @@ public final class Units {
* @return the milli-unit
*/
@SuppressWarnings("checkstyle:methodname")
public static <U extends Unit<U>> U Milli(Unit<U> baseUnit) {
public static <U extends Unit> U Milli(U baseUnit) {
return Milli(
baseUnit, "Milli" + baseUnit.name().toLowerCase(Locale.ROOT), "m" + baseUnit.symbol());
}
@@ -448,7 +561,7 @@ public final class Units {
* @return the micro-unit
*/
@SuppressWarnings("checkstyle:methodname")
public static <U extends Unit<U>> U Micro(Unit<U> baseUnit, String name, String symbol) {
public static <U extends Unit> U Micro(U baseUnit, String name, String symbol) {
return derive(baseUnit).splitInto(1_000_000).named(name).symbol(symbol).make();
}
@@ -460,7 +573,7 @@ public final class Units {
* @return the micro-unit
*/
@SuppressWarnings("checkstyle:methodname")
public static <U extends Unit<U>> U Micro(Unit<U> baseUnit) {
public static <U extends Unit> U Micro(U baseUnit) {
return Micro(
baseUnit, "Micro" + baseUnit.name().toLowerCase(Locale.ROOT), "u" + baseUnit.symbol());
}
@@ -475,7 +588,7 @@ public final class Units {
* @return the kilo-unit
*/
@SuppressWarnings("checkstyle:methodname")
public static <U extends Unit<U>> U Kilo(Unit<U> baseUnit, String name, String symbol) {
public static <U extends Unit> U Kilo(U baseUnit, String name, String symbol) {
return derive(baseUnit).aggregate(1000).named(name).symbol(symbol).make();
}
@@ -487,7 +600,7 @@ public final class Units {
* @return the kilo-unit
*/
@SuppressWarnings("checkstyle:methodname")
public static <U extends Unit<U>> U Kilo(Unit<U> baseUnit) {
public static <U extends Unit> U Kilo(U baseUnit) {
return Kilo(
baseUnit, "Kilo" + baseUnit.name().toLowerCase(Locale.ROOT), "K" + baseUnit.symbol());
}
@@ -500,8 +613,7 @@ public final class Units {
* @param <U> the dimension of the unit to derive
* @return a builder object
*/
@SuppressWarnings("unchecked")
public static <U extends Unit<U>> UnitBuilder<U> derive(Unit<U> unit) {
return new UnitBuilder<>((U) unit);
public static <U extends Unit> UnitBuilder<U> derive(U unit) {
return new UnitBuilder<>(unit);
}
}