Exemplo n.º 1
0
  @Override
  public void convertTo(final Measure _measure) {

    if (_measure == null) {
      throw new NullPointerException("Measure");
    }
    if (orginalValue.getMeasure() == _measure) {
      convert = orginalValue;
      return;
    }

    if (convert != null && convert.getMeasure() == _measure) {
      return;
    }

    if (!supportedMeasure.contains(_measure)) {
      throw new IllegalArgumentException(
          "cant convert "
              + orginalValue.getMeasure().getDescription()
              + " into "
              + _measure.getShortDisplayName());
    }
    // System.out.println("Converting into: "+_measure.getDescription());
    // TODO: Move calculation into switch block for better performance
    //
    final float v = orginalValue.getValue(); // always Knots!!!

    final float ms = v * 0.514444f; // m s-1

    final float kmh = v * 1.852f; // km/h

    final float knot = v; // knots

    final float mph = v * 1.150779f; // mi h-1

    final float fts = (v * 1.687810f); // ft s-1

    final float mmi = (ms * 60.f); // m min-1

    final float ftm = (fts * 60.f); // ft min-1

    final int beaufort = knotToBeaufort(knot);

    switch (_measure) {
      case MPS:
        convert = WindSpeed.create(ms, Measure.MPS);
        break;
      case KMH:
        convert = WindSpeed.create(kmh, Measure.KMH);
        break;
      case KNOTS:
        convert = WindSpeed.create(knot, Measure.KNOTS);
        break;
      case MPH:
        convert = WindSpeed.create(mph, Measure.MPH);
        break;
      case FPS:
        convert = WindSpeed.create(fts, Measure.FPS);
        break;
      case MMI:
        convert = WindSpeed.create(mmi, Measure.MMI);
        break;
      case FTM:
        convert = WindSpeed.create(ftm, Measure.FTM);
        break;
      case BEAUFORT:
        convert = WindSpeed.create(beaufort, Measure.BEAUFORT);
        break;
      default:
        throw new IllegalArgumentException("unknown Measure" + _measure.getDescription());
    }
  }
Exemplo n.º 2
0
 /*
  * (non-Javadoc)
  *
  * @see de.macsystems.windroid.identifyable.IMeasureValue#getMeasure()
  */
 @Override
 public Measure getMeasure() {
   convertTo(preferredMeasure);
   return convert.getMeasure();
 }