// 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.Acceleration; /** * A generic unit of acceleration. * *

NOTE: This type is not compatible with unit-specific accelerations like * {@link edu.wpi.first.units.measure.LinearAcceleration}. Authors of APIs that need to interact * with all types should consider using a generic {@code Measure], TimeUnit>, TimeUnit>}. Bounded wildcards are necessary in order to * interoperate with any subclass of the {@link edu.wpi.first.units.measure.Per} measurement * type. * * @param the unit of the accelerating quantity */ public final class AccelerationUnit extends PerUnit, TimeUnit> { @SuppressWarnings({"rawtypes", "unchecked"}) private static final CombinatoryUnitCache cache = new CombinatoryUnitCache<>(AccelerationUnit::new); AccelerationUnit(VelocityUnit velocity, TimeUnit period) { super( velocity.isBaseUnit() && period.isBaseUnit() ? null : combine(velocity.getBaseUnit(), period.getBaseUnit()), velocity, period); } AccelerationUnit( AccelerationUnit baseUnit, UnaryFunction toBaseConverter, UnaryFunction fromBaseConverter, String name, String symbol) { super(baseUnit, toBaseConverter, fromBaseConverter, name, symbol); } @Override public Acceleration of(double magnitude) { return new Acceleration<>(magnitude, toBaseUnits(magnitude), this); } @Override public Acceleration ofBaseUnits(double baseUnitMagnitude) { return new Acceleration<>(fromBaseUnits(baseUnitMagnitude), baseUnitMagnitude, this); } @Override @SuppressWarnings({"unchecked", "rawtypes"}) public Acceleration zero() { return (Acceleration) (Acceleration) super.zero(); } @Override @SuppressWarnings({"unchecked", "rawtypes"}) public Acceleration one() { return (Acceleration) (Acceleration) super.one(); } @Override public VelocityUnit> per(TimeUnit time) { return VelocityUnit.combine(this, time); } /** * 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, U> per(U other) { return PerUnit.combine(this, other); } /** * Converts a measurement value in terms of another time unit to this unit. * * @param magnitude the magnitude of the measurement in terms of the other time unit * @param otherUnit the other time unit * @return the value of the measurement in terms of this unit */ public double convertFrom(double magnitude, AccelerationUnit otherUnit) { return fromBaseUnits(otherUnit.toBaseUnits(magnitude)); } /** * Combines a generic velocity and time period into a unit of acceleration. * * @param velocity the unit of velocity * @param period the unit of the time period of acceleration * @param the unit of the accelerating quantity * @return the combined acceleration unit */ @SuppressWarnings("unchecked") public static AccelerationUnit combine( VelocityUnit velocity, TimeUnit period) { return cache.combine(velocity, period); } }