Class WeatherDistributor

java.lang.Object
java.util.AbstractMap<Enum,Object>
org.ka2ddo.yaac.weather.WeatherDistributor
All Implemented Interfaces:
Map<Enum,Object>

public class WeatherDistributor extends AbstractMap<Enum,Object>
This class collects weather data from the local weather station and makes it available to other listening classes.
Author:
Andrew Pavlin, KA2DDO
  • Field Details

    • WEATHER_STATION_TYPES

      public static final String[] WEATHER_STATION_TYPES
      Types of weather stations (abbreviations) to be appended to generic weather station data strings. The key "WeatherStationType."+the abbreviation is the key to look up the localized name string for each supported abbreviation.
  • Method Details

    • getInstance

      public static WeatherDistributor getInstance()
      Get the WeatherDistributor singleton.
      Returns:
      WeatherDistributor singleton object
    • parseWeatherData

      public Map<Enum,Object> parseWeatherData(String line, Map<Enum,Object> currentWeather)
      Decode weather data in Peet Bros format into the distributor's cache.
      Parameters:
      line - String to parse
      currentWeather - Map for storing the extracted weather data
      Returns:
      Map containing the weather data
    • loadCurrentWeather

      public void loadCurrentWeather(Map<? extends Enum,?> extensions)
      Copy weather data from some other map into the currentWeather map in this WeatherDistributor.
      Parameters:
      extensions - Map of WeatherEnums to values
    • get

      public Number get(WeatherEnum e)
      Fetch a numeric value from the weather data.
      Parameters:
      e - WeatherEnum for the data item wanted
      Returns:
      Number of the value of the requested weather data item, or null if the item isn't known
    • put

      public Object put(WeatherEnum e, Object value)
      Store a new value into the weather map.
      Parameters:
      e - WeatherEnum identifying the field to be updated
      value - Object value to be stored; note that most WeatherEnums require a Number subclass as their value
      Returns:
      the previous value stored for the WeatherEnum key
      Throws:
      ClassCastException - if trying to store a non-numeric value for a WeatherEnum that expects a Number
    • addWeatherListener

      public void addWeatherListener(WeatherListener l)
      Register a WeatherListener to be notified of updates in the weather data.
      Parameters:
      l - WeatherListener to register
    • removeWeatherListener

      public void removeWeatherListener(WeatherListener l)
      Deregister a WeatherListener so it will no longer be informed of changes in the local weather data.
      Parameters:
      l - WeatherListener to deregister
    • makeWeatherMsg

      public PositionlessWeatherReport makeWeatherMsg()
      Build a PositionlessWeatherReport from the current state of the collected local weather data.
      Returns:
      PositionlessWeatherReport containing the current local weather, or null if there is no weather data to report
    • getWeatherModelNameStrings

      public static String[] getWeatherModelNameStrings()
      Returns an array of localized weather station model names, in the same order as the standard abbreviations.
      Returns:
      String array of model names
    • entrySet

      public Set<Map.Entry<Enum,Object>> entrySet()
      Returns a Set view of the mappings contained in this map. The set is backed by the map, so changes to the map are reflected in the set, and vice-versa. If the map is modified while an iteration over the set is in progress (except through the iterator's own remove operation, or through the setValue operation on a map entry returned by the iterator) the results of the iteration are undefined. The set supports element removal, which removes the corresponding mapping from the map, via the Iterator.remove, Set.remove, removeAll, retainAll and clear operations. It does not support the add or addAll operations.
      Specified by:
      entrySet in interface Map<Enum,Object>
      Specified by:
      entrySet in class AbstractMap<Enum,Object>
      Returns:
      a set view of the mappings contained in this map
    • size

      public int size()
      Returns the number of key-value mappings in this map. If the map contains more than Integer.MAX_VALUE elements, returns Integer.MAX_VALUE.
      Specified by:
      size in interface Map<Enum,Object>
      Overrides:
      size in class AbstractMap<Enum,Object>
      Returns:
      the number of key-value mappings in this map
    • isEmpty

      public boolean isEmpty()
      Returns true if this map contains no key-value mappings.
      Specified by:
      isEmpty in interface Map<Enum,Object>
      Overrides:
      isEmpty in class AbstractMap<Enum,Object>
      Returns:
      true if this map contains no key-value mappings
    • get

      public Object get(Object key)
      Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.

      More formally, if this map contains a mapping from a key k to a value v such that (key==null ? k==null : key.equals(k)), then this method returns v; otherwise it returns null. (There can be at most one such mapping.)

      If this map permits null values, then a return value of null does not necessarily indicate that the map contains no mapping for the key; it's also possible that the map explicitly maps the key to null. The containsKey operation may be used to distinguish these two cases.

      Specified by:
      get in interface Map<Enum,Object>
      Overrides:
      get in class AbstractMap<Enum,Object>
      Parameters:
      key - the key whose associated value is to be returned
      Returns:
      the value to which the specified key is mapped, or null if this map contains no mapping for the key
      Throws:
      ClassCastException - if the key is of an inappropriate type for this map (optional)
      NullPointerException - if the specified key is null and this map does not permit null keys (optional)
    • keySet

      public Set<Enum> keySet()
      Returns a Set view of the keys contained in this map. The set is backed by the map, so changes to the map are reflected in the set, and vice-versa. If the map is modified while an iteration over the set is in progress (except through the iterator's own remove operation), the results of the iteration are undefined. The set supports element removal, which removes the corresponding mapping from the map, via the Iterator.remove, Set.remove, removeAll, retainAll, and clear operations. It does not support the add or addAll operations.
      Specified by:
      keySet in interface Map<Enum,Object>
      Overrides:
      keySet in class AbstractMap<Enum,Object>
      Returns:
      a set view of the keys contained in this map
    • values

      public Collection<Object> values()
      Returns a Collection view of the values contained in this map. The collection is backed by the map, so changes to the map are reflected in the collection, and vice-versa. If the map is modified while an iteration over the collection is in progress (except through the iterator's own remove operation), the results of the iteration are undefined. The collection supports element removal, which removes the corresponding mapping from the map, via the Iterator.remove, Collection.remove, removeAll, retainAll and clear operations. It does not support the add or addAll operations.
      Specified by:
      values in interface Map<Enum,Object>
      Overrides:
      values in class AbstractMap<Enum,Object>
      Returns:
      a collection view of the values contained in this map