Exemplo n.º 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));
    }
  }
Exemplo n.º 2
0
 @Override
 public int getItemIndex(SpeedUnit item) {
   SpeedUnit floorItem = (SpeedUnit) item.valueOf(Math.round(item.getValue()));
   return unitsList.indexOf(floorItem);
 }