Beispiel #1
0
  private void generateUnits(SpeedUnit startSpeed, SpeedUnit endSpeed) {
    if (!startSpeed.getClass().equals(endSpeed.getClass())) {
      endSpeed = (SpeedUnit) Operation.convert(endSpeed, startSpeed.getIdentifier());
    }

    final int startValue = (int) Math.round(startSpeed.getValue());
    final int endValue = (int) Math.round(endSpeed.getValue());

    if (startValue > endValue)
      throw new IllegalArgumentException(
          "Starting value must be less or equal to the ending value.");

    unitsList.clear();
    for (int i = startValue; i <= endValue; i++) {
      unitsList.add((SpeedUnit) startSpeed.valueOf(i));
    }
  }
  public MeterPerSecond fromTargetToBase(SpeedUnit target) {
    if (target instanceof MeterPerSecond) return (MeterPerSecond) target;

    return Operation.convert(target, UnitIdentifier.METER_PER_SECOND);
  }