// Copyright (c) FIRST and other WPILib contributors. // Open Source Software; you can modify and/or share it under the terms of // the WPILib BSD license file in the root directory of this project. package edu.wpi.first.units; import edu.wpi.first.units.measure.ImmutableTime; import edu.wpi.first.units.measure.MutTime; import edu.wpi.first.units.measure.Time; /** * Unit of time dimension. * *
This is the base type for units of time dimension. It is also used to specify the dimension
* for {@link Measure}: Measure<TimeUnit>.
*
*
Actual units (such as {@link Units#Seconds} and {@link Units#Milliseconds}) can be found in
* the {@link Units} class.
*/
public final class TimeUnit extends Unit {
TimeUnit(TimeUnit baseUnit, double baseUnitEquivalent, String name, String symbol) {
super(baseUnit, baseUnitEquivalent, name, symbol);
}
TimeUnit(
TimeUnit baseUnit,
UnaryFunction toBaseConverter,
UnaryFunction fromBaseConverter,
String name,
String symbol) {
super(baseUnit, toBaseConverter, fromBaseConverter, name, symbol);
}
@Override
public TimeUnit getBaseUnit() {
return (TimeUnit) super.getBaseUnit();
}
/**
* Creates a dimensionless unit corresponding to the scale factor between this and another unit of
* time.
*
* @param other the other unit of time
* @return the result
*/
@Override
public DimensionlessUnit per(TimeUnit other) {
return Units.derive(Units.Value)
.toBase(this.getConverterToBase().div(other.getConverterToBase()))
.fromBase(other.getConverterFromBase().div(this.getConverterFromBase()))
.named(this.name() + " per " + other.name())
.symbol(this.symbol() + "/" + other.symbol())
.make();
}
/**
* Creates a ratio unit between this unit and an arbitrary other unit.
*
* @param other the other unit
* @param the type of the other unit
* @return the ratio unit
*/
public PerUnit