Android Open Source - android-appwidget-cirrus Wind Speed






From Project

Back to project page android-appwidget-cirrus.

License

The source code is released under:

MIT License

If you think the Android project android-appwidget-cirrus listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/* Copyright 2014 Wayne D Grant (www.waynedgrant.com)
   Licensed under the MIT License */
// w  w w.ja va 2s . c om
package com.waynedgrant.cirrus.measures;

import java.math.BigDecimal;
import java.math.RoundingMode;

import com.waynedgrant.cirrus.units.WindSpeedUnit;

public class WindSpeed
{
  private BigDecimal knots;
  private BigDecimal metresPerSecond;
  private BigDecimal kilometresPerHour;
  private BigDecimal milesPerHour;
  private BigDecimal beaufortScale;
  
  public WindSpeed(BigDecimal knots)
  {
    this.knots = knots;
    this.metresPerSecond = knots.multiply(new BigDecimal("0.514444"));
    this.kilometresPerHour = knots.multiply(new BigDecimal("1.852"));
    this.milesPerHour = knots.multiply(new BigDecimal("1.15078"));
    this.beaufortScale = convertKnotsToBeaufortScale(knots);
  }
  
  public BigDecimal getValue(WindSpeedUnit unit)
  {
        BigDecimal value = null;
        
        switch (unit)
        {
            case KNOTS: value = knots; break;
            case METRES_PER_SECOND: value = metresPerSecond; break;
            case KILOMETRES_PER_HOUR: value = kilometresPerHour; break;
            case MILES_PER_HOUR: value = milesPerHour; break;
            case BEAUFORT_SCALE: value = beaufortScale; break;
        }
        
        return value;
  }
  
  private BigDecimal convertKnotsToBeaufortScale(BigDecimal knots)
  {
      int roundedKnots = knots.setScale(0, RoundingMode.HALF_UP).intValue();
      
      int beaufortScale = 0;
      
      if (roundedKnots >= 1 && roundedKnots <= 3)
      {
          beaufortScale = 1;
      }
      else if (roundedKnots >= 4 && roundedKnots <= 6)
      {
          beaufortScale = 2;
      }
        else if (roundedKnots >= 7 && roundedKnots <= 10)
        {
            beaufortScale = 3;
        }
        else if (roundedKnots >= 11 && roundedKnots <= 16)
        {
            beaufortScale = 4;
        }
        else if (roundedKnots >= 17 && roundedKnots <= 21)
        {
            beaufortScale = 5;
        }
        else if (roundedKnots >= 22 && roundedKnots <= 27)
        {
            beaufortScale = 6;
        }
        else if (roundedKnots >= 28 && roundedKnots <= 33)
        {
            beaufortScale = 7;
        }
        else if (roundedKnots >= 34 && roundedKnots <= 40)
        {
            beaufortScale = 8;
        }
        else if (roundedKnots >= 41 && roundedKnots <= 47)
        {
            beaufortScale = 9;
        }
        else if (roundedKnots >= 48 && roundedKnots <= 55)
        {
            beaufortScale = 10;
        }
        else if (roundedKnots >= 56 && roundedKnots <= 63)
        {
            beaufortScale = 11;
        }
        else if (roundedKnots >= 64)
        {
            beaufortScale = 12;
        }
      
      return new BigDecimal(beaufortScale);
  }
}




Java Source Code List

com.waynedgrant.cirrus.UpdateWidgetService.java
com.waynedgrant.cirrus.WidgetConfigActivity.java
com.waynedgrant.cirrus.WidgetProvider.java
com.waynedgrant.cirrus.clientraw.ClientRawCache.java
com.waynedgrant.cirrus.clientraw.ClientRawRequest.java
com.waynedgrant.cirrus.clientraw.ClientRawResponse.java
com.waynedgrant.cirrus.clientraw.ClientRawUrl.java
com.waynedgrant.cirrus.clientraw.ClientRaw.java
com.waynedgrant.cirrus.clientraw.RetrieveClientRawTask.java
com.waynedgrant.cirrus.measures.Conditions.java
com.waynedgrant.cirrus.measures.Pressure.java
com.waynedgrant.cirrus.measures.Rainfall.java
com.waynedgrant.cirrus.measures.Temperature.java
com.waynedgrant.cirrus.measures.Trend.java
com.waynedgrant.cirrus.measures.WeatherItem.java
com.waynedgrant.cirrus.measures.WindDirection.java
com.waynedgrant.cirrus.measures.WindSpeed.java
com.waynedgrant.cirrus.preferences.Preferences.java
com.waynedgrant.cirrus.presentation.colorizers.TemperatureColorizer.java
com.waynedgrant.cirrus.presentation.colorizers.UvIndexColorizer.java
com.waynedgrant.cirrus.presentation.colorizers.WeatherItemColorizer.java
com.waynedgrant.cirrus.presentation.formatters.ConditionsFormatter.java
com.waynedgrant.cirrus.presentation.formatters.DateFormat.java
com.waynedgrant.cirrus.presentation.formatters.DateFormatter.java
com.waynedgrant.cirrus.presentation.formatters.FormattedWeatherItem.java
com.waynedgrant.cirrus.presentation.formatters.HumidityFormatter.java
com.waynedgrant.cirrus.presentation.formatters.PressureFormatter.java
com.waynedgrant.cirrus.presentation.formatters.RainfallFormatter.java
com.waynedgrant.cirrus.presentation.formatters.RainfallRateFormatter.java
com.waynedgrant.cirrus.presentation.formatters.SolarPercentageFormatter.java
com.waynedgrant.cirrus.presentation.formatters.SolarRadiationFormatter.java
com.waynedgrant.cirrus.presentation.formatters.StringFormatter.java
com.waynedgrant.cirrus.presentation.formatters.TemperatureFormatter.java
com.waynedgrant.cirrus.presentation.formatters.TimeFormat.java
com.waynedgrant.cirrus.presentation.formatters.TimeFormatter.java
com.waynedgrant.cirrus.presentation.formatters.TrendFormatter.java
com.waynedgrant.cirrus.presentation.formatters.UvIndexFormatter.java
com.waynedgrant.cirrus.presentation.formatters.WeatherItemFormatter.java
com.waynedgrant.cirrus.presentation.formatters.WindDirectionFormatter.java
com.waynedgrant.cirrus.presentation.formatters.WindSpeedFormatter.java
com.waynedgrant.cirrus.units.CardinalDirection.java
com.waynedgrant.cirrus.units.PressureUnit.java
com.waynedgrant.cirrus.units.RainfallUnit.java
com.waynedgrant.cirrus.units.TemperatureUnit.java
com.waynedgrant.cirrus.units.WindDirectionUnit.java
com.waynedgrant.cirrus.units.WindSpeedUnit.java
com.waynedgrant.cirrus.update.Timeout.java